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

#2370 - Institution Read-Only User Type - PR 2 #4214

Merged
merged 30 commits into from
Jan 13, 2025

Conversation

andrepestana-aot
Copy link
Collaborator

@andrepestana-aot andrepestana-aot commented Jan 8, 2025

  • Added College E to DB Seeding and configured user as a read-only user;
  • Changed endpoints using @HasLocationAccess() to require the user to have InstitutionUserTypes.user for that location;
  • Added logic to Education Program endpoints to check if user has at least InstitutionUserTypes.user or InstitutionUserTypes.admin for any location and deny access to "read-only" users as education programs are at institution level;
  • Adapted authorizeUserTokenForLocation to optionally receive the InstitutionUserTypes for the user;
  • Added some tests to check read-only user access to some specific endpoints;
  • Added generic test to auth.e2e-spec.ts;

@andrepestana-aot andrepestana-aot self-assigned this Jan 8, 2025
@andrepestana-aot andrepestana-aot added Institution Institution Features SIMS-Api SIMS-Api labels Jan 8, 2025
@andrepestana-aot andrepestana-aot marked this pull request as ready for review January 9, 2025 18:17
@andrepestana-aot andrepestana-aot changed the title #2370 - Institution Read-Only User Type - Part 2 #2370 - Institution Read-Only User Type - PR 2 Jan 9, 2025
@lewischen-aot lewischen-aot self-requested a review January 9, 2025 23:01
Comment on lines 163 to 186
/**
* Create a location with read only user access.
* This is useful for tests that need to assert that the API endpoints
* are properly restricted for read only users.
* @param db E2E testing data sources.
* @returns location the user will have read only access.
*/
export async function getReadOnlyAuthorizedLocation(
db: E2EDataSources,
institutionTokenType: InstitutionTokenTypes,
) {
const { institution } = await getAuthRelatedEntities(
db.dataSource,
institutionTokenType,
);
const location = createFakeInstitutionLocation({ institution });
await authorizeUserTokenForLocation(
db.dataSource,
institutionTokenType,
location,
{ institutionUserType: InstitutionUserTypes.readOnlyUser },
);
return location;
}
Copy link
Collaborator

@lewischen-aot lewischen-aot Jan 10, 2025

Choose a reason for hiding this comment

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

❤️ This method reduces the amount of duplicated codes for creating a location with read only user access in this PR, and I think it can be expanded further to create locations for other user types as well. A cleanup ticket is probably needed in the future considering there are quite a few duplicated codes like this in the E2E tests. This comment is not a blocker. Great method by the way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would agree with @lewischen-aot. The method can be converted to a generic version that would return an authorized location with the InstitutionUserTypes provided. Not a blocker but it would be a nice improvement 😉

Copy link
Collaborator

@lewischen-aot lewischen-aot 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 to me. Awesome work ❤️

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes, only minor comments left.

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.22% ( 3787 / 17042 )
Methods: 10.17% ( 219 / 2154 )
Lines: 25.67% ( 3282 / 12785 )
Branches: 13.6% ( 286 / 2103 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.59% ( 589 / 898 )
Methods: 59.63% ( 65 / 109 )
Lines: 68.72% ( 468 / 681 )
Branches: 51.85% ( 56 / 108 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 86.14% ( 1249 / 1450 )
Methods: 82.42% ( 136 / 165 )
Lines: 88.51% ( 1032 / 1166 )
Branches: 68.07% ( 81 / 119 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 67.58% ( 5960 / 8819 )
Methods: 65.3% ( 734 / 1124 )
Lines: 71.48% ( 4674 / 6539 )
Branches: 47.75% ( 552 / 1156 )

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Great work, looks good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Institution Institution Features SIMS-Api SIMS-Api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants