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): Filter delegation indexing by provider #16141

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

saevarma
Copy link
Member

@saevarma saevarma commented Sep 24, 2024

What

Filter the delegation indexing by providers, as new providers are now using the webhook and providing hard check method, so their delegations are deleted if not protected by providers filter.

Tests will be added in a follow up PR due to pressure of starting to test this.

Why

So not all delegations are removed on reindexing.

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 constant for indexed delegation providers to enhance delegation record retrieval.
  • Bug Fixes

    • Improved filtering logic for delegation records based on specific providers.

@saevarma saevarma requested review from a team as code owners September 24, 2024 16:14
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes introduce a new constant, INDEXED_DELEGATION_PROVIDERS, which lists specific delegation providers for indexed retrieval. The findAll method in the DelegationsIndexService class is modified to filter records based on this constant, ensuring only relevant delegation records are retrieved for a given nationalId. This update refines the indexing and retrieval logic for delegation records.

Changes

Files Change Summary
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts Added a new constant INDEXED_DELEGATION_PROVIDERS and modified the findAll method to filter records based on this constant.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • Herdismaria

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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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.

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

Outside diff range and nitpick comments (1)
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (1)

45-54: LGTM! Consider enhancing the comment for future maintainers.

The addition of INDEXED_DELEGATION_PROVIDERS aligns well with the PR objective of filtering delegation indexing by provider. The comment provides good context for the change.

Consider adding a brief explanation of what "indexed" means in this context to make the comment even more informative for future maintainers. For example:

 // When delegation providers have been refactored to use the webhook method
 // with hard check on action we need to exclude them from the standard indexing.
 // We register our current providers as indexed, as all new providers are expected
-// to use the webhook method.
+// to use the webhook method. "Indexed" providers are those that still rely on
+// the standard indexing process rather than the webhook method.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e8e70b8 and afb6c4e.

Files selected for processing (1)
  • libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (2 hunks)
Additional context used
Path-based instructions (1)
libs/auth-api-lib/src/lib/delegations/delegations-index.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."
Additional comments not posted (2)
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (2)

Line range hint 1-724: Summary: Changes align well with PR objectives and maintain code quality.

The modifications in this file successfully implement the filtering mechanism for delegation indexing based on providers, as outlined in the PR objectives. The changes are well-documented and maintain good code quality and readability. They address the concern of potential data loss during reindexing for new providers using the webhook method.

Key points:

  1. The new INDEXED_DELEGATION_PROVIDERS constant clearly defines which providers should be included in the standard indexing process.
  2. The saveToIndex method has been updated to use this constant, ensuring only relevant delegations are processed.

These changes appear to meet the requirements without introducing any obvious issues. The code adheres to the coding guidelines for the libs/**/* pattern, maintaining reusability and effective TypeScript usage.


357-357: LGTM! Verify the impact on existing functionality.

The modification to filter delegations based on INDEXED_DELEGATION_PROVIDERS aligns perfectly with the PR objective. This change ensures that only delegations from indexed providers are processed during reindexing, preventing unintended data loss for new providers using the webhook method.

To ensure this change doesn't unintentionally affect existing functionality, let's verify the usage of saveToIndex method:

This script will help us identify any potential areas that might need adjustment due to the new filtering mechanism.

Verification successful

Please execute the following updated shell scripts to continue the verification process:


Please execute the following shell script to identify the actual INDEXED_DELEGATION_PROVIDERS:


Please execute the following shell script to extract the actual values of INDEXED_DELEGATION_PROVIDERS:


Verified the impact on existing functionality.

All direct calls to saveToIndex are correctly filtered based on INDEXED_DELEGATION_PROVIDERS (CompanyRegistry, Custom, NationalRegistry, PersonalRepresentativeRegistry). This ensures that only delegations from these indexed providers are processed, aligning with the PR objectives and preventing unintended data loss for new providers using the webhook method.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any direct calls to saveToIndex that might be affected by this change

# Search for direct calls to saveToIndex
echo "Direct calls to saveToIndex:"
rg --type typescript "saveToIndex\(" libs/auth-api-lib

# Search for any references to non-indexed providers that might be affected
echo "\nReferences to non-indexed providers:"
rg --type typescript "AuthDelegationProvider\." libs/auth-api-lib | grep -vE "$(echo $INDEXED_DELEGATION_PROVIDERS | tr ',' '|')"

Length of output: 382


Script:

#!/bin/bash
# Description: Check for any direct calls to saveToIndex that might be affected by this change

# Define INDEXED_DELEGATION_PROVIDERS if not already set
INDEXED_DELEGATION_PROVIDERS="${INDEXED_DELEGATION_PROVIDERS:-provider1,provider2}" # Replace with actual providers as needed

# Search for direct calls to saveToIndex in .ts and .tsx files
echo "Direct calls to saveToIndex:"
rg "saveToIndex\(" --glob "*.ts" --glob "*.tsx" libs/auth-api-lib

# Search for any references to non-indexed providers that might be affected
echo "\nReferences to non-indexed providers:"
rg "AuthDelegationProvider\." --glob "*.ts" --glob "*.tsx" libs/auth-api-lib | grep -vE "$(echo $INDEXED_DELEGATION_PROVIDERS | tr ',' '|')"

Length of output: 6701


Script:

#!/bin/bash
# Description: Locate the definition of INDEXED_DELEGATION_PROVIDERS in the codebase

echo "Searching for the definition of INDEXED_DELEGATION_PROVIDERS..."
rg "INDEXED_DELEGATION_PROVIDERS" --glob "*.ts" --glob "*.tsx" libs/auth-api-lib

Length of output: 438


Script:

#!/bin/bash
# Description: Extract the elements of the INDEXED_DELEGATION_PROVIDERS array

echo "Extracting INDEXED_DELEGATION_PROVIDERS values..."

rg -A 10 "const INDEXED_DELEGATION_PROVIDERS\s*=" --glob "*.ts" --glob "*.tsx" libs/auth-api-lib | \
grep -E "AuthDelegationProvider\." | \
sed -E 's/.*AuthDelegationProvider\.([A-Za-z0-9_]+).*/\1/' | \
awk '{print $1}' | sort | uniq

Length of output: 409

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.70%. Comparing base (e8e70b8) to head (13d0ff9).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16141      +/-   ##
==========================================
- Coverage   36.71%   36.70%   -0.01%     
==========================================
  Files        6761     6761              
  Lines      139076   139077       +1     
  Branches    39501    39501              
==========================================
- Hits        51055    51054       -1     
- Misses      88021    88023       +2     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 48.86% <ø> (ø)
application-system-api 41.56% <ø> (ø)
application-template-api-modules 23.62% <ø> (ø)
judicial-system-api 18.61% <ø> (ø)
judicial-system-backend 54.78% <ø> (ø)
judicial-system-formatters 79.76% <ø> (ø)
judicial-system-message 66.86% <ø> (ø)
judicial-system-message-handler 47.71% <ø> (ø)
judicial-system-scheduler 69.06% <ø> (ø)
judicial-system-types 48.35% <ø> (ø)
judicial-system-web 28.56% <ø> (ø)
services-auth-admin-api 50.46% <100.00%> (+<0.01%) ⬆️
services-auth-delegation-api 58.13% <100.00%> (+<0.01%) ⬆️
services-auth-ids-api 51.98% <100.00%> (-0.02%) ⬇️
services-auth-personal-representative 45.65% <100.00%> (+0.03%) ⬆️
services-auth-personal-representative-public 41.70% <100.00%> (-0.04%) ⬇️
services-auth-public-api 49.35% <100.00%> (+<0.01%) ⬆️
services-user-notification 47.16% <ø> (+0.02%) ⬆️
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 Δ
...b/src/lib/delegations/delegations-index.service.ts 90.32% <100.00%> (+0.04%) ⬆️

... and 1 file 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 e8e70b8...13d0ff9. Read the comment docs.

@kodiakhq kodiakhq bot merged commit c7efccb into main Sep 24, 2024
58 checks passed
@kodiakhq kodiakhq bot deleted the auth-api/index-filter-providers branch September 24, 2024 16:55
saevarma added a commit that referenced this pull request Sep 26, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Sep 26, 2024
* feat(ids-api): Use syslumenn api to verify delegation. (#16029)

* Use syslumenn api to verify delegation.

* Fix api error case.

* Fix config.

* chore: nx format:write update dirty files

* Handle error in api.

* Fix typo in name.

* Refactor mock.

* Update infra.

* Update host in infra.

* Add syslumenn infra to other auth apis.

* Also return empty array if error.

* Use post.

* Fix tests.

* Single delegation type.

* Remove infra config from pr public.

* Fix type.

* Refactor error handling in check for scopes.

* Openapi fix.

* Refactor verification error handling.

* Fix status code.

* Decrease syslumenn api timeout to 3s.

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: Valur Einarsson <valure@live.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* feat(auth-api): Filter delegation indexing by provider (#16141)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* feat(portals-admin-ids-admin): Add LegalRepresentative delegation type (#16069)

* Add missing translation for legal representation delegation type in IDS Admin

* Refactor delegation type filtering from client and scope creation to account for LegalRepresentative as superuser only.

* Update patch super user delegation type check.
Add tests.

* Handle legal representative in scope patch.
Add tests.

* Hide it from the UI.

* Fix duplicated message id

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: Valur Einarsson <valure@live.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
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