Skip to content

SIMSBIOHUB 878: Team Middleware for Authorization#339

Merged
J-pilon merged 49 commits intodevfrom
SIMSBIOHUB-878
Mar 2, 2026
Merged

SIMSBIOHUB 878: Team Middleware for Authorization#339
J-pilon merged 49 commits intodevfrom
SIMSBIOHUB-878

Conversation

@J-pilon
Copy link
Collaborator

@J-pilon J-pilon commented Feb 25, 2026

Links to Jira Tickets

https://apps.nrs.gov.bc.ca/int/jira/browse/SIMSBIOHUB-878

Description of Changes

  • Introduces team-scoped authorization: models and a dedicated repository and service (with tests) for resolving team-based access.
  • Adds Zod types TeamMemberRecord, TeamPolicyRecord, and DataRequestRecord for query results.
  • TeamAuthorizationRepository provides Knex query-builder methods to find active team membership by team ID, by policy ID, and by data request ID, and a SQL (CTE) method to find a team policy for a submission feature via URN matching on policy_statement.
  • TeamAuthorizationService exposes isUserAuthorizedForTeamEntity, which handles team, policy, data request, and submission_feature entity types; for submission features it respects the secured flag, optional submission ID, and uses the new repository method to resolve access by submission feature ID.
  • AuthorizationService is refactored so team rules are evaluated by delegating to TeamAuthorizationService instead of inlining logic.
  • The GET submission feature route (/submission/{submissionId}/features/{submissionFeatureId}) is updated to authorize via the Team rule with entity type submission_feature (submissionFeatureId and submissionId).
  • Includes unit tests for TeamAuthorizationRepository, TeamAuthorizationService, and updated AuthorizationService tests that stub TeamAuthorizationService.
  • Data requests scoped by user’s teams: GET /data-requests is filtered by the requesting user’s teams.
  • TeamRepository gains a method to get teams by system_user_id (joining team_member and team); TeamService exposes getTeamIdsBySystemUserId; DataRequestRepository adds a team_ids filter; DataRequestService’s findDataRequests uses system_user_id to resolve team IDs and fetch only data requests for those teams.
  • Discriminator handling is updated: adds system_user to confirm the user is in the system and removes the unimplemented ticket type. Adds tests for DataRequestService and for DataRequestRepository’s team_ids filter.

Testing Instructions

Regular System User:
Create data_request where your part of the team:

curl --location 'http://localhost:6100/api/data-request' \
--header 'Authorization: Bearer <TOKEN> \
--header 'Content-Type: application/json' \
--data '{
    "reason": "Part of this team"
}'

Create data_request where you are not part of the team:
After creating the data_request, remove yourself from the team.

curl --location 'http://localhost:6100/api/data-request' \
--header 'Authorization: Bearer <TOKEN> \
--header 'Content-Type: application/json' \
--data '{
    "reason": "Not part of this team",
    "team_id": "abc123"
}'

Request all data_request records

curl --location 'http://localhost:6100/api/data-request/' \
--header 'Authorization: Bearer <TOKEN>'

You should see only one data_request record that you are part of the team.

Change system user role to ADMIN
You should see both data_request records.

@J-pilon J-pilon marked this pull request as ready for review February 25, 2026 20:41
@J-pilon J-pilon marked this pull request as ready for review February 27, 2026 18:35
@J-pilon J-pilon added Ready For Review PR is ready for review and removed Not Ready For Review Addressing feedback and/or refactoring labels Feb 27, 2026
@J-pilon J-pilon requested a review from mauberti-bc February 27, 2026 18:36
Copy link
Collaborator

@mauberti-bc mauberti-bc left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple comments to address

@J-pilon J-pilon added Not Ready For Review Addressing feedback and/or refactoring and removed Ready For Review PR is ready for review labels Feb 27, 2026
@J-pilon J-pilon marked this pull request as draft February 27, 2026 22:35
@J-pilon J-pilon marked this pull request as ready for review February 28, 2026 00:15
@J-pilon
Copy link
Collaborator Author

J-pilon commented Feb 28, 2026

@mauberti-bc

  • Refactored TeamAuthorizationService's 'isUserAuthorizedForTeamEntity' method to conform to its contract of only returning booleans
  • Removed duplication for 'findDataRequests' and 'findDataRequestsByTeamMembership' in DataRequestRepository by creating a private method for applying filters following the pattern in TeamRepository

@J-pilon J-pilon requested a review from mauberti-bc February 28, 2026 00:19
@J-pilon J-pilon added Ready For Review PR is ready for review and removed Not Ready For Review Addressing feedback and/or refactoring labels Feb 28, 2026
Copy link
Collaborator

@mauberti-bc mauberti-bc left a comment

Choose a reason for hiding this comment

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

👍

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2026

@J-pilon J-pilon merged commit b09d70e into dev Mar 2, 2026
18 checks passed
@J-pilon J-pilon deleted the SIMSBIOHUB-878 branch March 2, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready For Review PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants