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-admin): General mandate delegation type #16005

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

GunnlaugurG
Copy link
Member

@GunnlaugurG GunnlaugurG commented Sep 13, 2024

What

Added General mandate delegation type with 1 to 1 connection to custom delegations.

Why

So we can use this for 'Allsherjarumboð' instead of the Custom delegation type

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

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

    • Introduced a new delegation type, "GeneralMandate," enhancing authorization delegation capabilities.
    • Improved handling of delegation types to ensure consistency between custom and general mandate types during creation and removal.
  • Bug Fixes

    • Updated logic to exclude "General Mandate" from user-facing results, ensuring a cleaner UI experience.
  • Documentation

    • Expanded the AuthDelegationType enum to include the new "GeneralMandate" type for better categorization.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

This pull request introduces a new delegation type, "GeneralMandate," into the database and updates various services to manage this type. A migration script adds the delegation type to the database schema, while the ClientsService, DelegationProviderService, and AdminScopeService classes are modified to handle the creation, upsertion, and deletion of delegation types. The AuthDelegationType enum is also updated to include "GeneralMandate," and relevant test cases are adjusted to reflect these changes.

Changes

File Change Summary
libs/auth-api-lib/migrations/20240913092844-GeneralMandate-delegation-type.js Added a migration script to introduce "GeneralMandate" delegation type with up and down functions.
libs/auth-api-lib/src/lib/clients/clients.service.ts Modified upsert and destroy methods to handle "GeneralMandate" alongside "Custom" delegation types.
libs/auth-api-lib/src/lib/delegations/delegation-provider.service.ts Added filtering to exclude "GeneralMandate" from results in delegation type retrieval.
libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts Updated creation and removal logic for delegation types to include handling of "GeneralMandate".
libs/shared/types/src/lib/delegation.ts Added GeneralMandate to the AuthDelegationType enum.
libs/api/domains/auth/src/lib/models/delegation.model.ts Added handling for AuthDelegationType.GeneralMandate in delegation processing logic.
apps/services/auth/admin-api/src/app/v2/clients/test/me-clients.spec.ts Updated test cases to include AuthDelegationType.GeneralMandate in supported delegation types.
apps/services/auth/admin-api/src/app/v2/scopes/test/me-scopes.spec.ts Added AuthDelegationType.GeneralMandate to supportedDelegationTypes in multiple test cases.

Possibly related PRs

Suggested reviewers

  • GunnlaugurG
  • saevarma

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0f09a68 and f457c14.

Files selected for processing (1)
  • libs/auth-api-lib/src/lib/clients/clients.service.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/auth-api-lib/src/lib/clients/clients.service.ts

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>, please review it.
    -- 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 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.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for code reviews. This model has advanced reasoning capabilities and can provide more nuanced feedback on your code.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

@GunnlaugurG GunnlaugurG marked this pull request as ready for review September 13, 2024 14:38
@GunnlaugurG GunnlaugurG requested review from a team as code owners September 13, 2024 14:38
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 8b22584 and 41fe7aa.

Files selected for processing (5)
  • libs/auth-api-lib/migrations/20240913092844-GeneralMandate-delegation-type.js (1 hunks)
  • libs/auth-api-lib/src/lib/clients/clients.service.ts (2 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegation-provider.service.ts (2 hunks)
  • libs/auth-api-lib/src/lib/resources/admin/admin-scope.service.ts (2 hunks)
  • libs/shared/types/src/lib/delegation.ts (1 hunks)
Additional context used
Path-based instructions (5)
libs/shared/types/src/lib/delegation.ts (2)

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

  • Cross-application utility functions, types, and constants.
  • TypeScript best practices to ensure type safety and reusability.
  • Documentation and examples for library consumers."

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/migrations/20240913092844-GeneralMandate-delegation-type.js (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/delegation-provider.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."
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."
libs/auth-api-lib/src/lib/clients/clients.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."
Biome
libs/auth-api-lib/migrations/20240913092844-GeneralMandate-delegation-type.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

Additional comments not posted (7)
libs/shared/types/src/lib/delegation.ts (1)

7-7: LGTM!

The addition of the GeneralMandate enum value aligns with the PR objective of introducing a new delegation type. The enum value name is clear and descriptive.

As this enum is part of the shared types library, it adheres to the guidelines for:

  • Cross-application reusability
  • Type safety
  • Documentation (although an explanatory comment could be beneficial for future maintainers)

Overall, this is a good addition to the AuthDelegationType enum.

libs/auth-api-lib/migrations/20240913092844-GeneralMandate-delegation-type.js (1)

4-16: LGTM!

The migration script aligns with the PR objective and follows best practices:

  • It introduces the new "GeneralMandate" delegation type and associates it with clients and API scopes that currently use the "Custom" type.
  • It uses SQL transactions to ensure data consistency.
  • It provides a rollback script to undo the changes.

The script is also reusable across different NextJS apps, adhering to the additional instructions for libs/** files.

Also applies to: 18-30

libs/auth-api-lib/src/lib/delegations/delegation-provider.service.ts (1)

25-29: LGTM! The filtering condition is correctly implemented.

The added where clause in the association with the delegationTypeModel effectively filters out entries where the id matches AuthDelegationType.GeneralMandate. This ensures that the "General Mandate" delegation type is excluded from the results returned by the findAll method.

The use of the Op.ne operator is appropriate for achieving the desired exclusion. The comment also provides clarity on the purpose behind this change, which is to prevent the "General Mandate" delegation type from being displayed in the UI.

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

462-488: LGTM!

The code correctly upserts each delegationType into the ApiScopeDelegationType model and establishes the one-to-one relationship between 'Custom' and 'GeneralMandate' types as per the PR objectives. It also adheres to the reusability and TypeScript usage guidelines for the libs directory.


551-577: LGTM!

The code correctly destroys each delegationType from the ApiScopeDelegationType model and maintains the one-to-one relationship between 'Custom' and 'GeneralMandate' types as per the PR objectives. It also adheres to the reusability and TypeScript usage guidelines for the libs directory.

libs/auth-api-lib/src/lib/clients/clients.service.ts (2)

621-646: LGTM!

The changes to addClientDelegationTypes enhance the functionality by ensuring that both the specified delegation type and an additional instance of AuthDelegationType.GeneralMandate are managed simultaneously when the delegation type is AuthDelegationType.Custom. This improves the integrity of the delegation type handling.

The code adheres to the reusability and modularity guidelines by utilizing the AuthDelegationType enum and ClientDelegationType model. The changes are logically correct and the code is readable.


703-728: LGTM!

The changes to removeClientDelegationTypes ensure that when a custom delegation type is removed, its associated general mandate is also appropriately handled by deleting an instance of AuthDelegationType.GeneralMandate. This maintains consistency in the data model.

The code adheres to the reusability and modularity guidelines by utilizing the AuthDelegationType enum and ClientDelegationType model. The changes are logically correct and the code is readable.

Copy link

codecov bot commented Sep 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.75%. Comparing base (e660f32) to head (f457c14).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16005      +/-   ##
==========================================
+ Coverage   36.73%   36.75%   +0.01%     
==========================================
  Files        6735     6736       +1     
  Lines      138283   138316      +33     
  Branches    39323    39344      +21     
==========================================
+ Hits        50799    50833      +34     
+ Misses      87484    87483       -1     
Flag Coverage Δ
air-discount-scheme-backend 54.10% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.39% <ø> (ø)
api-domains-air-discount-scheme 36.85% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 49.89% <ø> (ø)
api-domains-communications 40.45% <100.00%> (+<0.01%) ⬆️
api-domains-criminal-record 47.77% <ø> (ø)
api-domains-driving-license 44.32% <ø> (ø)
api-domains-education 31.32% <ø> (ø)
api-domains-health-insurance 34.58% <ø> (ø)
api-domains-mortgage-certificate 35.73% <ø> (ø)
api-domains-payment-schedule 41.14% <ø> (ø)
application-api-files 57.59% <ø> (ø)
application-core 71.29% <ø> (-0.33%) ⬇️
application-system-api 41.64% <100.00%> (+<0.01%) ⬆️
application-template-api-modules 23.47% <100.00%> (+0.02%) ⬆️
application-templates-accident-notification 22.14% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.63% <ø> (ø)
application-templates-driving-license 18.63% <ø> (ø)
application-templates-estate 12.34% <ø> (ø)
application-templates-example-payment 25.41% <ø> (ø)
application-templates-financial-aid 14.34% <ø> (ø)
application-templates-general-petition 23.68% <ø> (ø)
application-templates-health-insurance 26.62% <ø> (ø)
application-templates-inheritance-report 6.45% <ø> (ø)
application-templates-marriage-conditions 15.23% <ø> (ø)
application-templates-mortgage-certificate 43.96% <100.00%> (+0.03%) ⬆️
application-templates-parental-leave 30.15% <ø> (ø)
application-types 6.71% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.29% <ø> (ø)
auth-nest-tools 31.02% <100.00%> (+0.19%) ⬆️
auth-react 22.84% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.56% <ø> (ø)
clients-driving-license-book 43.85% <ø> (ø)
clients-financial-statements-inao 49.10% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 72.58% <100.00%> (-0.24%) ⬇️
clients-regulations 42.54% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-syslumenn 49.75% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.60% <100.00%> (+<0.01%) ⬆️
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.50% <ø> (ø)
contentful-apps 5.76% <ø> (ø)
download-service 44.60% <ø> (ø)
financial-aid-backend 56.52% <ø> (ø)
financial-aid-shared 19.03% <ø> (ø)
icelandic-names-registry-backend 54.64% <ø> (ø)
island-ui-core 28.60% <ø> (ø)
judicial-system-api 19.40% <ø> (ø)
judicial-system-backend 55.21% <100.00%> (+<0.01%) ⬆️
judicial-system-web 28.71% <ø> (ø)
license-api 42.42% <ø> (-0.16%) ⬇️
localization 10.15% <ø> (ø)
nest-audit 68.20% <ø> (ø)
nest-feature-flags 51.91% <ø> (ø)
nest-problem 46.48% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
portals-admin-regulations-admin 1.95% <ø> (ø)
portals-core 16.16% <ø> (ø)
reference-backend 50.57% <ø> (ø)
services-auth-admin-api 52.89% <100.00%> (+0.05%) ⬆️
services-auth-delegation-api 61.27% <27.27%> (-0.05%) ⬇️
services-auth-ids-api 53.95% <27.27%> (-0.01%) ⬇️
services-auth-personal-representative 47.93% <27.27%> (+<0.01%) ⬆️
services-auth-personal-representative-public 43.86% <27.27%> (-0.03%) ⬇️
services-auth-public-api 51.75% <27.27%> (-0.03%) ⬇️
services-documents 61.26% <ø> (ø)
services-endorsements-api 55.10% <ø> (ø)
services-sessions 65.80% <100.00%> (+0.06%) ⬆️
services-university-gateway 48.48% <ø> (+0.05%) ⬆️
services-user-notification 47.63% <100.00%> (+0.03%) ⬆️
services-user-profile 62.28% <ø> (+0.07%) ⬆️
shared-components 27.67% <ø> (ø)
shared-form-fields 31.60% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 28.91% <ø> (ø)
skilavottord-ws 24.34% <ø> (ø)
web 1.85% <ø> (ø)

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

Files with missing lines Coverage Δ
...bs/auth-api-lib/src/lib/clients/clients.service.ts 31.46% <100.00%> (+1.20%) ⬆️
...src/lib/delegations/delegation-provider.service.ts 100.00% <100.00%> (ø)
...lib/src/lib/resources/admin/admin-scope.service.ts 90.50% <100.00%> (+0.21%) ⬆️
libs/shared/types/src/lib/delegation.ts 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes


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 e660f32...f457c14. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 14, 2024

Datadog Report

All test runs ff7cd89 🔗

81 Total Test Services: 0 Failed, 79 Passed
❄️ 1 with New Flaky
🔻 Test Sessions change in coverage: 7 decreased, 7 increased, 186 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
services-auth-personal-representative 0 0 1 59 0 1m 9.81s 1 decreased (-0.02%) Link
air-discount-scheme-backend 0 0 0 81 0 42.63s 1 no change Link
air-discount-scheme-web 0 0 0 2 0 11.56s 1 no change Link
api 0 0 0 4 0 3.2s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 20.33s N/A Link
api-domains-assets 0 0 0 3 0 13.58s N/A Link
api-domains-auth-admin 0 0 0 18 0 14.49s 1 no change Link
api-domains-communications 0 0 0 5 0 34.48s 1 no change Link
api-domains-criminal-record 0 0 0 5 0 9.42s N/A Link
api-domains-driving-license 0 0 0 23 0 29.41s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (7)

This report shows up to 5 code coverage decreases.

  • services-auth-delegation-api - jest 60.01% (-0.3%) - Details
  • application-core - jest 79.46% (-0.21%) - Details
  • services-auth-ids-api - jest 49.86% (-0.03%) - Details
  • services-auth-public-api - jest 52.59% (-0.03%) - Details
  • services-auth-personal-representative - jest 50.07% (-0.02%) - Details

@GunnlaugurG GunnlaugurG added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants