Skip to content

feat: adjust identity repositories - #2903

Merged
tada5hi merged 2 commits into
masterfrom
2883-idp-repos
Mar 13, 2026
Merged

tada5hi merged 2 commits into
masterfrom
2883-idp-repos

Conversation

@tada5hi

@tada5hi tada5hi commented Mar 13, 2026 •

Copy link
Copy Markdown
Collaborator

resolves #2883

Summary by CodeRabbit

  • Refactor

    • Improved dependency injection and wiring in identity modules, consolidating repository-backed domain services and a single data source instance; removed the LDAP identity provider adapter.
  • New Features

    • Added lookup methods for clients, robots, and users: findOneByName() and findOneByIdOrName().
  • Breaking Changes

    • Public constructors/types for identity repositories changed — update integrations to the new constructor/context signatures.

@coderabbitai

coderabbitai Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Refactors 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

Cohort / File(s) Summary
Identity Repository Implementations
apps/server-core/src/app/modules/identity/repositories/client.ts, apps/server-core/src/app/modules/identity/repositories/robot.ts, apps/server-core/src/app/modules/identity/repositories/user.ts
Replaced runtime useDataSource() usage with constructor-injected domain repositories. Added private repository fields and new lookup helpers findOneByName() and findOneByIdOrName(). User repository now accepts a UserIdentityRepositoryContext (user repo, userPermission repo, userRole repo) and uses injected repos for permission/role operations.
DI Module Wiring
apps/server-core/src/app/modules/identity/module.ts
Updated to resolve DataSource from container once and construct/wire ClientRepository, RobotRepository, UserRepository (plus permission/role repositories) into the identity repository instances. Adjusted imports and types to support new constructor signatures.
Identity Provider Adapter Removal
apps/server-core/src/app/modules/identity/repositories/identity-provider.ts
Removed the LDAP identity provider adapter (IdentityProviderLdapAdapter) and its findByProtocol method (file content deleted).
Tests / Public exports
apps/server-core/test/unit/core/identity/provider/account.spec.ts
Tests updated to construct UserIdentityRepository with the new context object; public exports updated to include UserRepository where needed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 I hopped through code, with twitching nose,
I swapped the locators for tidy rows,
Repos arrive by gentle hand,
No runtime hunts across the land,
Constructor carrots — tidy, grand! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The removal of IdentityProviderLdapAdapter in identity-provider.ts is out of scope—issue #2883 lists specific files to change but does not mention this repository file or the LDAP adapter removal. Either verify that the IdentityProviderLdapAdapter removal is a required part of issue #2883 or move it to a separate pull request focused on LDAP adapter deprecation.
Title check ❓ Inconclusive The title 'feat: adjust identity repositories' is vague and generic, using the non-descriptive term 'adjust' without conveying the core change of replacing service-locator usage with dependency injection. Consider using a more specific title like 'feat: replace useDataSource() with constructor-injected repositories in identity modules' to better communicate the primary architectural change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully implements all coding requirements from issue #2883: replaces useDataSource() calls with constructor-injected repositories in ClientIdentityRepository, RobotIdentityRepository, and UserIdentityRepository, wires dependencies in module.ts via the DI container, and removes the IdentityProviderLdapAdapter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2883-idp-repos
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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), so container.resolve(UserPermissionEntity) returns Repository<UserPermissionEntity>, not Repository<UserPermission>. The explicit type annotation acts as a cast. This works at runtime since UserPermissionEntity 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 UserIdentityRepositoryContext to use Repository<UserPermissionEntity> and Repository<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 to ClientIdentityRepository.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

📥 Commits

Reviewing files that changed from the base of the PR and between e43aff4 and 4633dc9.

📒 Files selected for processing (5)
  • apps/server-core/src/app/modules/identity/module.ts
  • apps/server-core/src/app/modules/identity/repositories/client.ts
  • apps/server-core/src/app/modules/identity/repositories/robot.ts
  • apps/server-core/src/app/modules/identity/repositories/user.ts
  • apps/server-core/test/unit/core/identity/provider/account.spec.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Refactor identity repositories to use DIP instead of useDataSource()

1 participant