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

chore(ids-auth-api): Change handling of alsoForDelegatedUser in createScope helper #16046

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

jonarnarbriem
Copy link
Member

@jonarnarbriem jonarnarbriem commented Sep 18, 2024

alsoForDelegatedUser is now set to false by default
added option to set to true if wanted
seeder script to set value to false for one existing scope

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

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 property to manage API scope accessibility for delegated users.
    • Updated logic for determining scope inclusion in access tokens.
  • Bug Fixes

    • Adjusted database migration to restrict access for delegated users on specific API scopes.

@jonarnarbriem jonarnarbriem requested review from a team as code owners September 18, 2024 08:58
Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

This pull request introduces a database migration script that modifies the api_scope table to set the also_for_delegated_user field to false for a specific API scope. It also updates the ScopeOptions interface to include a new optional property, alsoForDelegatedUser, which enhances the configurability of scope options related to delegated users. The changes ensure that the API scope will no longer be available for delegated users while maintaining the ability to revert to the previous state.

Changes

File Change Summary
libs/auth-api-lib/seeders/.../20240917153226-set-also-for-delegated-user-false.js Added migration script to set also_for_delegated_user to false for a specific entry and provided a rollback mechanism.
libs/auth-api-lib/seeders/data/helpers/createScope.ts Introduced alsoForDelegatedUser optional property in ScopeOptions interface and updated getScopeFields logic to utilize this new property.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • GunnlaugurG

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.

@jonarnarbriem jonarnarbriem added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Sep 18, 2024
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

Outside diff range and nitpick comments (1)
libs/auth-api-lib/seeders/20240917153226-set-also-for-delegated-user-false.js (1)

5-7: Avoid Hardcoding Scope Names for Maintainability

Hardcoding the scope name '@island.is/signature-collection' reduces flexibility and can lead to maintenance issues if the scope name changes.

Consider defining the scope name as a constant at the top of the module:

+const scopeName = '@island.is/signature-collection';

 module.exports = {
   up(queryInterface) {
     return queryInterface.sequelize.transaction(async (transaction) => {
       await queryInterface.sequelize.query(
         `
           UPDATE api_scope
           SET also_for_delegated_user = false
-          WHERE name = '@island.is/signature-collection'
+          WHERE name = '${scopeName}'
         `,
         { transaction },
       )
     })
   },
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 43a8006 and 42d9dd6.

Files selected for processing (2)
  • libs/auth-api-lib/seeders/20240917153226-set-also-for-delegated-user-false.js (1 hunks)
  • libs/auth-api-lib/seeders/data/helpers/createScope.ts (2 hunks)
Additional context used
Path-based instructions (2)
libs/auth-api-lib/seeders/20240917153226-set-also-for-delegated-user-false.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/seeders/data/helpers/createScope.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."
Additional comments not posted (3)
libs/auth-api-lib/seeders/data/helpers/createScope.ts (3)

51-54: Well-Documented Addition of alsoForDelegatedUser Property

The introduction of the alsoForDelegatedUser optional property in the ScopeOptions interface is clear and follows TypeScript best practices. The JSDoc comment accurately describes its purpose and default behavior.


63-63: Consistent Default Value Logic

The use of the nullish coalescing operator (??) for also_for_delegated_user ensures that false is the default value when alsoForDelegatedUser is undefined. This maintains consistency with the documented default behavior.


51-54: Ensure Consistency in Optional Delegation Properties

Now that alsoForDelegatedUser is optional and defaults to false, verify that this property is intentionally true only where necessary. This helps prevent unintended exposure of scopes to delegated users.

To check where alsoForDelegatedUser is set to true, you can run:

Verification successful

Verified: alsoForDelegatedUser Usage is Intentional and Necessary

The alsoForDelegatedUser: true property is used appropriately in the findActorApiScopes method of resources.service.ts. This method filters API scopes to include only those explicitly marked for delegated users, aligning with the property's intended purpose. No other instances of setting this property to true were found, indicating it's not being overused elsewhere in the codebase.

  • Location: libs/auth-api-lib/src/lib/resources/resources.service.ts
  • Context: Used in findActorApiScopes method to filter API scopes for delegated users
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all instances where alsoForDelegatedUser is explicitly set to true.

# Search through seeders for alsoForDelegatedUser: true
rg --type ts 'alsoForDelegatedUser:\s*true'

Length of output: 138


Script:

#!/bin/bash
# Description: View the context of alsoForDelegatedUser: true usage in resources.service.ts

# Display the relevant part of the file with context
rg --type ts -C 10 'alsoForDelegatedUser:\s*true' libs/auth-api-lib/src/lib/resources/resources.service.ts

# Look for any comments mentioning alsoForDelegatedUser in the same file
rg --type ts '(\/\/|\/\*|\*).*alsoForDelegatedUser' libs/auth-api-lib/src/lib/resources/resources.service.ts

Length of output: 910

@datadog-island-is
Copy link

Datadog Report

All test runs 6aa34a7 🔗

13 Total Test Services: 0 Failed, 13 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.26%), 1 increased (+0.02%), 22 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.04s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.1s 1 no change Link
application-system-api 0 0 0 111 2 3m 11.41s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 49.7s 1 no change Link
auth-api-lib 0 0 0 20 0 33.47s 1 no change Link
services-auth-admin-api 0 0 0 107 0 2m 34.13s 1 no change Link
services-auth-delegation-api 0 0 0 256 0 2m 42.17s 1 decreased (-0.26%) Link
services-auth-ids-api 0 0 0 145 0 52.49s 1 no change Link
services-auth-personal-representative 0 0 0 59 0 1m 15.68s 1 no change Link
services-auth-personal-representative-public 0 0 0 10 0 24.92s 1 increased (+0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

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

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.74%. Comparing base (2dd6e46) to head (dbd5ef6).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #16046    +/-   ##
========================================
  Coverage   36.73%   36.74%            
========================================
  Files        6735     6733     -2     
  Lines      138280   138179   -101     
  Branches    39319    39284    -35     
========================================
- Hits        50797    50772    -25     
+ Misses      87483    87407    -76     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 49.89% <ø> (ø)
application-system-api 41.64% <ø> (ø)
application-template-api-modules 23.46% <ø> (+0.01%) ⬆️
portals-admin-regulations-admin 1.95% <ø> (ø)
services-auth-admin-api 52.87% <ø> (ø)
services-auth-delegation-api 61.30% <ø> (-0.08%) ⬇️
services-auth-ids-api 54.01% <ø> (-0.02%) ⬇️
services-auth-personal-representative 47.91% <ø> (-0.05%) ⬇️
services-auth-personal-representative-public 43.86% <ø> (ø)
services-auth-public-api 51.81% <ø> (+0.01%) ⬆️
services-user-notification 47.62% <ø> (ø)
services-user-profile 62.28% <ø> (ø)
web 1.85% <ø> (ø)

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

Files with missing lines Coverage Δ
...s/auth-api-lib/seeders/data/helpers/createScope.ts 0.00% <ø> (ø)

... and 20 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 2dd6e46...dbd5ef6. Read the comment docs.

@kodiakhq kodiakhq bot merged commit ab53cdc into main Sep 18, 2024
55 checks passed
@kodiakhq kodiakhq bot deleted the feat/update-create-scope-helper branch September 18, 2024 14:08
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.

2 participants