Repository navigation
feat: adjust identity repositories - #2903
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughRefactors identity repositories to constructor-based dependency injection: ClientIdentityRepository, RobotIdentityRepository, and UserIdentityRepository now accept domain repositories (ClientRepository, RobotRepository, UserRepository + permission/role repos). The identity module wires these via the DI container; LDAP identity-provider adapter was removed. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
apps/server-core/src/app/modules/identity/module.ts (1)
55-56: Type annotation masks actual return type.The container registers repositories keyed by entity class (
UserPermissionEntity), socontainer.resolve(UserPermissionEntity)returnsRepository<UserPermissionEntity>, notRepository<UserPermission>. The explicit type annotation acts as a cast. This works at runtime sinceUserPermissionEntity implements UserPermission, but reduces type safety if the interface and entity diverge.Consider using the entity types consistently:
- userPermissionRepository: container.resolve<Repository<UserPermission>>(UserPermissionEntity), - userRoleRepository: container.resolve<Repository<UserRole>>(UserRoleEntity), + userPermissionRepository: container.resolve(UserPermissionEntity), + userRoleRepository: container.resolve(UserRoleEntity),This would require updating
UserIdentityRepositoryContextto useRepository<UserPermissionEntity>andRepository<UserRoleEntity>.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/server-core/src/app/modules/identity/module.ts` around lines 55 - 56, The current type annotations on the container.resolve calls are casting Repository<UserPermissionEntity> and Repository<UserRoleEntity> to Repository<UserPermission>/Repository<UserRole>, which hides the real return type; change the annotations so the resolved types are Repository<UserPermissionEntity> and Repository<UserRoleEntity> (i.e., remove the incorrect cast to the interface types) and then update the UserIdentityRepositoryContext type declarations to expect Repository<UserPermissionEntity> and Repository<UserRoleEntity> so entity types are used consistently (adjust any usages of UserPermission/UserRole within UserIdentityRepositoryContext to the entity types where needed).apps/server-core/src/app/modules/identity/repositories/robot.ts (1)
38-80: Consider extracting shared query logic.The
find()method is nearly identical toClientIdentityRepository.find(). Both implement the same pattern for:
- UUID detection and conditional where clauses
- Realm key handling (UUID vs name)
- Non-select column inclusion
- ID-based caching
A shared base class or utility function could reduce duplication, though keeping explicit implementations may be preferred for the hexagonal architecture.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/server-core/src/app/modules/identity/repositories/robot.ts` around lines 38 - 80, The find() method duplicates logic from ClientIdentityRepository.find: UUID detection, realmKey handling, adding non-select columns, and ID-based caching; extract the common behavior into a shared helper (e.g., a utility function buildEntityFindQuery(repository, alias, key, realmKey) or a protected base method in a new IdentityRepositoryBase) and have RobotRepository.find() call that helper then apply the entity-specific cache key (use buildRedisKeyPath with CachePrefix.ROBOT) before getOne(); ensure the helper exposes hooks for alias, realm relationship name and cache prefix so both RobotRepository.find and ClientIdentityRepository.find can reuse the UUID check, realm branch, addSelect loop (using repository.metadata.columns), and optional caching.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/server-core/src/app/modules/identity/module.ts`:
- Around line 55-56: The current type annotations on the container.resolve calls
are casting Repository<UserPermissionEntity> and Repository<UserRoleEntity> to
Repository<UserPermission>/Repository<UserRole>, which hides the real return
type; change the annotations so the resolved types are
Repository<UserPermissionEntity> and Repository<UserRoleEntity> (i.e., remove
the incorrect cast to the interface types) and then update the
UserIdentityRepositoryContext type declarations to expect
Repository<UserPermissionEntity> and Repository<UserRoleEntity> so entity types
are used consistently (adjust any usages of UserPermission/UserRole within
UserIdentityRepositoryContext to the entity types where needed).
In `@apps/server-core/src/app/modules/identity/repositories/robot.ts`:
- Around line 38-80: The find() method duplicates logic from
ClientIdentityRepository.find: UUID detection, realmKey handling, adding
non-select columns, and ID-based caching; extract the common behavior into a
shared helper (e.g., a utility function buildEntityFindQuery(repository, alias,
key, realmKey) or a protected base method in a new IdentityRepositoryBase) and
have RobotRepository.find() call that helper then apply the entity-specific
cache key (use buildRedisKeyPath with CachePrefix.ROBOT) before getOne(); ensure
the helper exposes hooks for alias, realm relationship name and cache prefix so
both RobotRepository.find and ClientIdentityRepository.find can reuse the UUID
check, realm branch, addSelect loop (using repository.metadata.columns), and
optional caching.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ef7595d7-b2bf-4f77-88ac-17cf0255e940
📒 Files selected for processing (5)
apps/server-core/src/app/modules/identity/module.tsapps/server-core/src/app/modules/identity/repositories/client.tsapps/server-core/src/app/modules/identity/repositories/robot.tsapps/server-core/src/app/modules/identity/repositories/user.tsapps/server-core/test/unit/core/identity/provider/account.spec.ts
resolves #2883
Summary by CodeRabbit
Refactor
New Features
Breaking Changes