Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth-api-lib): add support for delegation types to api-scopes #14887

Merged
merged 4 commits into from
May 23, 2024

Conversation

Herdismaria
Copy link
Contributor

@Herdismaria Herdismaria commented May 22, 2024

Update admin api client patch endpoint to be able to accept delegation type

What
Start using the new delegation types db table in auth admin api.

When creating or updating supported delegation types for a api scope we now both update the old boolean fields in the api_scope table and create/remove rows from the new api_scope_delegation_types table.

Why
We want to move to using a new supportedDelegationType array field when retrieving supported delegation types for an api_scope.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced delegation type management within API scopes.
    • Added functionality to include and exclude delegation types in API scope operations.
  • Bug Fixes

    • Improved validation and processing of delegation types for API scopes.
  • Documentation

    • Updated API documentation to cover new delegation type features.
  • Refactor

    • Renamed properties in delegation type models for consistency.
    • Optimized methods for handling delegation types and their relationships.

@Herdismaria Herdismaria requested review from a team as code owners May 22, 2024 13:42
Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

The updates primarily enhance the handling of delegation types across various modules, focusing on the MeScopesController and related components. These changes introduce new delegation types, update DTOs, models, and services to support these types, and include new test cases. The modifications aim to improve the association and management of delegation types within API scopes, enhancing the flexibility and robustness of the authorization system.

Changes

Files Change Summary
me-scopes.spec.ts, index.ts, clients.module.ts Modifications related to handling delegation types, including imports, exports, and associations.
delegation-type.model.ts, admin-scope.service.ts Updates to support linking ApiScope entities through ApiScopeDelegationType and handling delegation types in services.
admin-create-scope.dto.ts, admin-patch-scope.dto.ts Addition of properties and decorators for delegation types in DTO classes.
api-scope-base.dto.ts Validation updates for supportedDelegationTypes in the base DTO class.
api-scope-delegation-type.model.ts, api-scope.model.ts Changes in model classes for consistency and introducing new associations for delegation types.
fixture-factory.ts Addition of a new property apiScopes within a method in the FixtureFactory class.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between d97292b and 68abd55.
Files selected for processing (10)
  • apps/services/auth/admin-api/src/app/v2/scopes/test/me-scopes.spec.ts (13 hunks)
  • libs/auth-api-lib/src/index.ts (1 hunks)
  • libs/auth-api-lib/src/lib/clients/clients.module.ts (2 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (2 hunks)
  • libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts (10 hunks)
  • libs/auth-api-lib/src/lib/resources/admin/dto/admin-create-scope.dto.ts (1 hunks)
  • libs/auth-api-lib/src/lib/resources/admin/dto/admin-patch-scope.dto.ts (1 hunks)
  • libs/auth-api-lib/src/lib/resources/dto/base/api-scope-base.dto.ts (2 hunks)
  • libs/auth-api-lib/src/lib/resources/models/api-scope-delegation-type.model.ts (2 hunks)
  • libs/auth-api-lib/src/lib/resources/models/api-scope.model.ts (4 hunks)
Files skipped from review due to trivial changes (2)
  • libs/auth-api-lib/src/index.ts
  • libs/auth-api-lib/src/lib/resources/models/api-scope-delegation-type.model.ts
Additional Context Used
Path-based Instructions (8)
libs/auth-api-lib/src/lib/resources/admin/dto/admin-create-scope.dto.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/resources/dto/base/api-scope-base.dto.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/resources/admin/dto/admin-patch-scope.dto.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/clients/clients.module.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/resources/models/api-scope.model.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/services/auth/admin-api/src/app/v2/scopes/test/me-scopes.spec.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Additional comments not posted (18)
libs/auth-api-lib/src/lib/resources/admin/dto/admin-create-scope.dto.ts (2)

6-8: The inheritance and property omission are correctly implemented for the creation DTO.


15-21: The supportedDelegationTypes property is well-defined with appropriate validation and documentation.

libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (1)

67-69: The association between DelegationTypeModel and ApiScope is correctly implemented for a many-to-many relationship.

libs/auth-api-lib/src/lib/resources/dto/base/api-scope-base.dto.ts (1)

111-117: The supportedDelegationTypes property is correctly implemented with appropriate validation and documentation.

libs/auth-api-lib/src/lib/resources/admin/dto/admin-patch-scope.dto.ts (1)

88-102: The properties addedDelegationTypes and removedDelegationTypes are correctly implemented with appropriate validation and documentation.

libs/auth-api-lib/src/lib/clients/clients.module.ts (1)

Line range hint 25-45: The import and inclusion of ApiScopeDelegationType in the module's imports are correctly implemented.

libs/auth-api-lib/src/lib/resources/models/api-scope.model.ts (1)

260-271: The associations for ApiScopeDelegationType and DelegationTypeModel are correctly implemented, facilitating the intended many-to-many relationships.

libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts (7)

8-8: Ensure proper usage of Sequelize Op and Transaction imports.

These imports are correctly used for database operations within transactions, which is a best practice for ensuring data integrity.


42-45: Check for correct dependency injection of new models.

The models ApiScopeDelegationType and DelegationTypeModel are correctly injected, which allows for their methods to be used within the service.


57-59: Ensure that the new supportedDelegationTypes association is correctly configured.

The inclusion of supportedDelegationTypes in the include option of Sequelize queries is correct and ensures that delegation types are fetched along with API scopes.

Also applies to: 94-96


Line range hint 162-195: Review transaction handling and delegation type management in createScope.

The transaction ensures atomicity of operations, which is crucial when creating a scope and its associated delegation types. The method addScopeDelegationTypes is correctly called within the transaction.


Line range hint 336-485: Examine updates in updateScope method for handling delegation types.

The updates to handle delegation types within the updateScope method are correctly implemented. The method addScopeDelegationTypes and removeScopeDelegationTypes are used to manage the delegation types, ensuring that changes are made atomically within a transaction.


395-487: Check logic in addScopeDelegationTypes and removeScopeDelegationTypes methods.

The logic to add and remove delegation types based on boolean flags and explicit types is correctly implemented. This allows for flexible management of delegation types based on different conditions.


28-30: Verify correct integration of new models for delegation types.

Verification successful

The new models ApiScopeDelegationType and DelegationTypeModel are correctly integrated and used throughout the system. The search results show multiple instances where these models are imported and utilized in various files, confirming their integration.

  • libs/auth-api-lib/src/lib/resources/models/api-scope-delegation-type.model.ts
  • libs/auth-api-lib/src/lib/resources/models/api-scope.model.ts
  • libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts
  • libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts
  • libs/auth-api-lib/src/lib/clients/clients.module.ts
  • libs/auth-api-lib/src/lib/clients/models/client.model.ts
  • apps/services/auth/admin-api/src/app/v2/scopes/test/me-scopes.spec.ts
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new models are correctly integrated and used throughout the system.

# Test: Search for usage of `ApiScopeDelegationType` and `DelegationTypeModel`.
rg --type typescript $'ApiScopeDelegationType|DelegationTypeModel'

Length of output: 102



Script:

#!/bin/bash
# Description: Verify that the new models are correctly integrated and used throughout the system.

# Test: Search for usage of `ApiScopeDelegationType` and `DelegationTypeModel`.
rg --type ts $'ApiScopeDelegationType|DelegationTypeModel'

Length of output: 7687

apps/services/auth/admin-api/src/app/v2/scopes/test/me-scopes.spec.ts (4)

12-19: Confirm correct imports for new delegation types in test cases.

The imports for ApiScopeDelegationType, AdminPatchScopeDto, AuthDelegationProvider, and AuthDelegationType are correctly added to support the new test cases involving delegation types.


113-134: Review the setup of delegation types in test data creation.

The setup for creating delegation types in the test data is correctly implemented, ensuring that various delegation types are available for the test cases.


Line range hint 271-308: Examine the handling of supportedDelegationTypes in test cases for creating scopes.

The test cases correctly handle the supportedDelegationTypes field when creating scopes, ensuring that the field is tested for both presence and absence of delegation types.


Line range hint 430-487: Ensure correct handling of supportedDelegationTypes in patch test cases.

The patch test cases correctly manipulate the supportedDelegationTypes field, testing both the addition and removal of delegation types, which aligns with the new functionality introduced in the API.

@Herdismaria Herdismaria changed the title feature(auth-api-lib): add support for delegation types to api-scopes feat(auth-api-lib): add support for delegation types to api-scopes May 22, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented May 22, 2024

Datadog Report

All test runs 24ad8eb 🔗

13 Total Test Services: 0 Failed, 13 Passed
🔻 Test Sessions change in coverage: 6 decreased, 2 increased, 15 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 4.42s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 16.02s 1 no change Link
application-system-api 0 0 0 111 2 4m 5.73s 1 increased (+0.01%) Link
application-template-api-modules 0 0 0 109 0 1m 54.62s 1 no change Link
auth-api-lib 0 0 0 13 0 51.24s 1 decreased (-0.09%) Link
services-auth-admin-api 0 0 0 106 0 3m 33.94s 1 increased (+0.33%) Link
services-auth-delegation-api 0 0 0 254 0 3m 36.84s 1 decreased (-0.09%) Link
services-auth-ids-api 0 0 0 193 0 1m 25.89s 1 decreased (-0.02%) Link
services-auth-personal-representative 0 0 0 59 0 1m 25.28s 1 decreased (-0.03%) Link
services-auth-personal-representative-public 0 0 0 10 0 36.62s 1 decreased (-0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (6)

This report shows up to 5 code coverage decreases.

  • auth-api-lib - jest 10.88% (-0.09%) - Details
  • services-auth-delegation-api - jest 61.1% (-0.09%) - Details
  • services-auth-personal-representative - jest 51.3% (-0.03%) - Details
  • services-auth-public-api - jest 51.31% (-0.03%) - Details
  • services-auth-ids-api - jest 51.15% (-0.02%) - Details

Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.02%. Comparing base (9bf6804) to head (1a934f5).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #14887      +/-   ##
==========================================
- Coverage   37.03%   37.02%   -0.01%     
==========================================
  Files        6331     6331              
  Lines      129165   129155      -10     
  Branches    36869    36869              
==========================================
- Hits        47831    47823       -8     
+ Misses      81334    81332       -2     
Flag Coverage Δ
air-discount-scheme-backend 53.97% <ø> (ø)
api-domains-health-insurance 27.34% <ø> (ø)
api-domains-payment-schedule 40.64% <ø> (ø)
clients-driving-license 40.43% <ø> (ø)
clients-driving-license-book 43.92% <ø> (ø)
clients-license-client 1.84% <ø> (ø)
clients-rsk-company-registry 29.46% <ø> (ø)
clients-syslumenn 49.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
libs/auth-api-lib/src/index.ts 100.00% <ø> (ø)
...ibs/auth-api-lib/src/lib/clients/clients.module.ts 100.00% <ø> (ø)
...rc/lib/delegations/models/delegation-type.model.ts 100.00% <ø> (ø)
...lib/src/lib/resources/admin/admin-scope.service.ts 96.87% <ø> (-0.10%) ⬇️
.../lib/resources/admin/dto/admin-create-scope.dto.ts 100.00% <ø> (ø)
...c/lib/resources/admin/dto/admin-patch-scope.dto.ts 100.00% <ø> (ø)
...b/src/lib/resources/dto/base/api-scope-base.dto.ts 100.00% <ø> (ø)
...esources/models/api-scope-delegation-type.model.ts 0.00% <ø> (ø)
...pi-lib/src/lib/resources/models/api-scope.model.ts 95.91% <ø> (ø)
...vices/auth/testing/src/fixtures/fixture-factory.ts 89.52% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9bf6804...1a934f5. Read the comment docs.

@Herdismaria Herdismaria requested a review from a team as a code owner May 22, 2024 15:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 68abd55 and 9a4b043.
Files selected for processing (1)
  • libs/services/auth/testing/src/fixtures/fixture-factory.ts (1 hunks)
Additional Context Used
Path-based Instructions (1)
libs/services/auth/testing/src/fixtures/fixture-factory.ts (2)

Pattern libs/services/**/*: "Confirm that the code adheres to the following:

  • Shared services and modules that can be utilized across NestJS apps.
  • Proper implementation of NestJS providers, including custom providers.
  • Adherence to NestJS module encapsulation and isolation principles."

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."

libs/services/auth/testing/src/fixtures/fixture-factory.ts Outdated Show resolved Hide resolved
Copy link
Member

@GunnlaugurG GunnlaugurG left a comment

Choose a reason for hiding this comment

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

Two minor comments, otherwise LGTM!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9a4b043 and b698983.
Files selected for processing (2)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts (2 hunks)
  • libs/services/auth/testing/src/fixtures/fixture-factory.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts
  • libs/services/auth/testing/src/fixtures/fixture-factory.ts

Copy link
Member

@saevarma saevarma left a comment

Choose a reason for hiding this comment

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

🚀

@Herdismaria Herdismaria added the automerge Merge this PR as soon as all checks pass label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants