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): Delegation domain name changes #16013

Merged
merged 25 commits into from
Sep 18, 2024
Merged

Conversation

GunnlaugurG
Copy link
Member

@GunnlaugurG GunnlaugurG commented Sep 16, 2024

What

Make domain_name in delegation table optional and remove default value

Why

So we can offer general mandate (Allsherjarumboð) delegation that is not domain specific

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

    • Enhanced handling of domainName to allow for null values, improving flexibility in delegation scenarios.
    • Introduced a new referenceId property for tracking Zendesk tickets related to delegations.
  • Bug Fixes

    • Improved robustness by ensuring consistent handling of undefined domainName values across various services.
  • Documentation

    • Updated method documentation to clarify the purpose of the direction parameter in the delete method.

Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

This pull request introduces changes to the delegation table in the database, allowing the domain_name column to accept NULL values and modifying the unique constraints associated with it. Additionally, it updates various services and models to handle the new flexibility in the domain_name field, ensuring consistent handling of potentially undefined values across the codebase.

Changes

File Change Summary
libs/auth-api-lib/migrations/20240915135625-delegation-allow-null-domain_name.js Migration script modifies the delegation table by dropping a unique constraint, allowing domain_name to be NULL, and creating a new unique index that treats NULL as distinct. The down function reverses these changes.
libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts Introduced a new unique index on domain_name, changed domainName to be optional, and added a new optional referenceId property for Zendesk ticket tracking.
libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts Adjusted findScopes method to handle delegation.domainName with nullish coalescing, ensuring consistent value handling.
libs/auth-api-lib/src/lib/delegations/delegations-outgoing.service.ts Replaced direct references to domainName with nullish coalescing to ensure defined values; removed an import statement indicating a refactor.
libs/auth-api-lib/src/lib/delegations/delegations.service.ts Modified findScopeNames to use nullish coalescing for domainName; added documentation for a new direction parameter in the delete method; minor formatting change.
libs/auth-api-lib/src/lib/resources/delegation-resources.service.ts Changed domainName parameter type from string to `string

Possibly related PRs

Suggested labels

automerge


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.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 36.68%. Comparing base (ab53cdc) to head (6f4e6b7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...legations/admin/delegation-admin-custom.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16013      +/-   ##
==========================================
- Coverage   36.73%   36.68%   -0.05%     
==========================================
  Files        6735     6722      -13     
  Lines      138279   138257      -22     
  Branches    39318    39384      +66     
==========================================
- Hits        50797    50721      -76     
- Misses      87482    87536      +54     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 49.89% <ø> (ø)
application-system-api 41.64% <ø> (ø)
application-template-api-modules 23.45% <ø> (-0.01%) ⬇️
services-auth-admin-api 52.84% <28.57%> (-0.04%) ⬇️
services-auth-delegation-api 61.31% <85.71%> (+<0.01%) ⬆️
services-auth-ids-api 54.01% <28.57%> (-0.02%) ⬇️
services-auth-personal-representative 47.91% <28.57%> (-0.08%) ⬇️
services-auth-personal-representative-public 43.88% <28.57%> (-0.04%) ⬇️
services-auth-public-api 51.78% <28.57%> (-0.04%) ⬇️
services-user-notification 47.62% <ø> (ø)
services-user-profile 62.28% <ø> (ø)

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

Files with missing lines Coverage Δ
...rc/lib/delegations/delegations-outgoing.service.ts 95.74% <100.00%> (+0.09%) ⬆️
...api-lib/src/lib/delegations/delegations.service.ts 26.10% <100.00%> (-0.46%) ⬇️
...lib/src/lib/delegations/models/delegation.model.ts 88.57% <100.00%> (-0.32%) ⬇️
.../src/lib/resources/delegation-resources.service.ts 98.33% <ø> (ø)
...legations/admin/delegation-admin-custom.service.ts 48.64% <0.00%> (-1.36%) ⬇️

... and 139 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 ab53cdc...6f4e6b7. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 16, 2024

Datadog Report

All test runs 0354a6f 🔗

13 Total Test Services: 0 Failed, 13 Passed
🔻 Test Sessions change in coverage: 2 decreased, 1 increased (+0.02%), 21 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 3.08s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.86s 1 no change Link
application-system-api 0 0 0 111 2 3m 31.67s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 53.8s 1 no change Link
auth-api-lib 0 0 0 20 0 30.38s 1 no change Link
services-auth-admin-api 0 0 0 107 0 3m 2.7s 1 no change Link
services-auth-delegation-api 0 0 0 256 0 2m 30.55s 1 decreased (-0.26%) Link
services-auth-ids-api 0 0 0 145 0 59.21s 1 decreased (-0.02%) Link
services-auth-personal-representative 0 0 0 59 0 1m 17.56s 1 no change Link
services-auth-personal-representative-public 0 0 0 10 0 27.21s 1 increased (+0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • services-auth-delegation-api - jest 60.05% (-0.26%) - Details
  • services-auth-ids-api - jest 49.87% (-0.02%) - Details

@GunnlaugurG GunnlaugurG marked this pull request as ready for review September 16, 2024 21:09
@GunnlaugurG GunnlaugurG requested review from a team as code owners September 16, 2024 21:09
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

Outside diff range and nitpick comments (2)
libs/auth-api-lib/migrations/20240915135625-delegation-allow-null-domain_name.js (1)

1-1: Remove the redundant 'use strict' directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it. The 'use strict' directive is redundant and can be safely removed.

Apply this diff to remove the redundant directive:

-'use strict'
Tools
Biome

[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)

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

Line range hint 97-103: Remove the duplicate referenceId property definition.

The referenceId property is defined twice in the code (lines 87-95 and 97-103). Having duplicate property definitions can lead to confusion and potential errors.

Please remove the duplicate definition:

-  /**
-   * ReferenceId is a field for storing a reference to the zendesk ticket id
-   */
-  @Column({
-    type: DataType.STRING,
-    allowNull: true,
-    unique: true,
-  })
-  referenceId?: string
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7572adf and 9aaba64.

Files selected for processing (6)
  • libs/auth-api-lib/migrations/20240915135625-delegation-allow-null-domain_name.js (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts (1 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations-outgoing.service.ts (4 hunks)
  • libs/auth-api-lib/src/lib/delegations/delegations.service.ts (3 hunks)
  • libs/auth-api-lib/src/lib/delegations/models/delegation.model.ts (2 hunks)
  • libs/auth-api-lib/src/lib/resources/delegation-resources.service.ts (5 hunks)
Additional context used
Path-based instructions (6)
libs/auth-api-lib/migrations/20240915135625-delegation-allow-null-domain_name.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/models/delegation.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/delegations/admin/delegation-admin-custom.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/delegation-resources.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/delegations/delegations-outgoing.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/delegations/delegations.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/20240915135625-delegation-allow-null-domain_name.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 (15)
libs/auth-api-lib/migrations/20240915135625-delegation-allow-null-domain_name.js (2)

4-23: LGTM!

The up function correctly modifies the delegation table to allow NULL values in the domain_name column and creates a new unique index to maintain data integrity. The use of a transaction ensures that the changes are applied atomically.


25-44: LGTM!

The down function correctly reverts the changes made by the up function, restoring the original state of the delegation table. The use of a transaction ensures that the changes are applied atomically.

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

31-36: LGTM!

The unique index is correctly defined and will enhance data integrity by preventing duplicate entries for the same delegation scenario. It will also improve query performance for queries that rely on the uniqueness of the indexed columns.


82-85: Verify the impact of making the domainName field optional.

The changes to make the domainName field optional are implemented correctly. This will allow for more flexibility in cases where a domain name is not applicable.

However, please ensure that:

  1. Existing code that relies on the presence of the domainName field is updated to handle the optional nature of the field.
  2. Existing data in the delegation table is migrated properly to handle null values for the domainName field.

87-95: LGTM!

The new referenceId property is correctly defined as an optional and unique field. This will facilitate better tracking and management of support tickets related to delegations.

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

109-109: LGTM!

The use of the nullish coalescing operator (??) to conditionally set delegation.domainName to null when it is undefined is a good practice. It ensures that the findScopes method receives a consistent value, preventing potential issues from passing undefined. This change enhances the robustness of the code without altering the overall logic flow.

libs/auth-api-lib/src/lib/resources/delegation-resources.service.ts (5)

139-139: Ensure proper handling of the null case and update method callers.

The change to allow null for domainName aligns with the PR objective. Please ensure that:

  • The findScopesInternal method called within findScopes handles the case when domainName is null.
  • All callers of the findScopes method are updated to handle the new string | null type for domainName.

170-170: Ensure proper handling of the null case and update method callers.

The change to allow null for domainName aligns with the PR objective. Please ensure that:

  • The findScopesInternal method called within findScopeNames handles the case when domainName is null.
  • All callers of the findScopeNames method are updated to handle the new string | null type for domainName.

184-184: Ensure proper handling of the null case and update method callers.

The change to allow null for domainName aligns with the PR objective. Please ensure that:

  • The findScopeNames method called within validateScopeAccess handles the case when domainName is null.
  • All callers of the validateScopeAccess method are updated to handle the new string | null type for domainName.

240-240: Handle the null case in the where clause.

The change to allow null for domainName aligns with the PR objective. Please ensure that the where clause in the findAll call within the findScopesInternal method handles the case when domainName is null.


Line range hint 1-400: Adherence to additional instructions:

  • Reusability of components and hooks across different NextJS apps: Not applicable, as this is a NestJS service.
  • TypeScript usage for defining props and exporting types: The code adheres to this by using TypeScript for defining types and method signatures.
  • Effective tree-shaking and bundling practices: Not directly observable in this code.
libs/auth-api-lib/src/lib/delegations/delegations-outgoing.service.ts (2)

345-345: LGTM!

The use of the nullish coalescing operator (??) to default currentDelegation.domainName to null when it's undefined is a good practice. It ensures a consistent value is passed to the validateScopeAccess function, improving the reliability of the delegation logic.


406-406: Looks good!

Using the nullish coalescing operator (??) to default delegation.domainName to null when it's undefined is a good practice. It ensures a consistent value is passed to the findScopes function, improving the reliability of the delegation logic.

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

139-139: Approved: Explicit handling of undefined or null domainName.

The change from delegation.domainName to delegation.domainName ?? null is a good practice. It ensures that the findScopeNames method receives an explicit null value instead of potentially receiving undefined when domainName is not defined.

Using the nullish coalescing operator ?? provides a fallback value and enhances the robustness of the code by clarifying the intent.


159-159: Approved: Enhanced documentation clarity.

Adding the direction parameter to the delete method's documentation is a good improvement. It clarifies that the method can handle both incoming and outgoing delegations.

Specifying the possible values of direction (incoming or outgoing) helps developers understand the purpose and usage of the method more easily.

Enhancing the documentation in this way improves the overall clarity and maintainability of the codebase.

@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