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

#582 - Improvement in guards #1891

Merged
merged 15 commits into from
Apr 20, 2023
Merged

Conversation

dheepak-aot
Copy link
Collaborator

@dheepak-aot dheepak-aot commented Apr 18, 2023

Improvement in Guards

The following improvements have been implemented to the Guards.

  • Defining the interface to route meta to have it typed.
    image

  • Refactoring the logic of validating institution user access to the institution routes. According the updated logic, the institution user types must be specified in the route and missing to do so will reject the access for all user types.

  • Route meta property allowOnlyBCPublic created for routes to be allowed only for BCPublic institutions. (Implementation of this logic is not part of the ticket.)

  • Route meta property allowOnlyLegalSigningAuthority is added and is used to authorize only user with role legal signing authority to access the routes with allowOnlyLegalSigningAuthority set to true.

  • useInstitutionAuth refactored to use the store getters and added additional properties.

  • isAuthenticatedInstitutionUser created in useInstitutionAuth to include the verification of isActive status of the user. And due to which the following nav buttons does not appear during create institutions.
    image

  • As per the Vue documentation, Global before guards are replaced with Global Resolve guards.

image

  • Refactored the interface UserStateForStore as the interface properties were not in sync with data stored in state.

@dheepak-aot dheepak-aot self-assigned this Apr 18, 2023
@dheepak-aot dheepak-aot changed the title Improvements/institution guards #582 - Improvement in guards Apr 19, 2023
@dheepak-aot dheepak-aot marked this pull request as ready for review April 19, 2023 03:46
}
return true;
}
// If the user is not an admin, check if the route is allowed for non admin user.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know that we only have 2 types of institution user for now but if we add a new one, we'll need to come here and change the comment. Maybe a more generic comment here would suit it better.

@@ -93,7 +93,10 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
},
meta: {
clientType: ClientIdType.Institution,
userTypes: [InstitutionUserTypes.admin, InstitutionUserTypes.user],
institutionUserTypes: [
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could have a constant for the institutionUserTypes as it repeats many times.

Copy link
Collaborator

@andrepestana-aot andrepestana-aot left a comment

Choose a reason for hiding this comment

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

Good job. I left some minor comments.

/**
* Route meta properties.
*/
interface RouteMeta {
Copy link
Contributor

@ann-aot ann-aot Apr 19, 2023

Choose a reason for hiding this comment

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

it will be like a common meta interface, right? just wondering can have derived interface from a base interface for each client type when required, because last 3 are only for institution

Copy link
Collaborator Author

@dheepak-aot dheepak-aot Apr 19, 2023

Choose a reason for hiding this comment

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

I also would like to have separate interfaces for different client types. But unfortunately RouteMeta is the interface that the router's meta is typed to and we are suppose to use only one single interface.

Are you are saying that for the sake of readability if we should create like this? if so do not see a benefit of creating it as it(RouteMetaInstitution) could never be used anywhere.

interface RouteMetaInstitution {
    institutionUserTypes?: InstitutionUserTypes[];
    allowOnlyLegalSigningAuthority?: boolean;
    allowOnlyBCPublic?: boolean;
  }

interface RouteMeta extends  RouteMetaInstitution {
    clientType: ClientIdType;
    requiresAuth?: boolean;
  }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it accepts only an interface or can it be a type like interface1 | interface2 | interface3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only interface AFAIK.

image

// Define error handling on router error.
router.onError((error: unknown) => {
console.error(error);
throw error;
Copy link
Contributor

@ann-aot ann-aot Apr 19, 2023

Choose a reason for hiding this comment

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

In our discussion we were saying that we don't want the router to stuck in case of an error right, instead return something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed, I wrongly assumed that the catch block in the previous code had the re-direction, but it was not.

So just kept the code inside catch as is and added to on error. @andrewsignori-aot @andrepestana-aot @guru-aot @sh16011993 fyi.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, do we need it at all? I am assuming that an error will be logged either way, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then I can remove the this for now and added it when required if that is ok.

}

/**
* Validate the access of user to the given route.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

const institutionUserDetails = store.getters[
"institution/myDetails"
] as UserStateForStore;
const authorizations =
Copy link
Contributor

Choose a reason for hiding this comment

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

just for my info why store.state.institution.authorizationsState are replaced

@@ -8,7 +8,7 @@
class="navigation-btn float-left"
>
<v-btn
v-if="isAuthenticated"
v-if="isAuthenticatedInstitutionUser"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the isAuthenticatedInstitutionUser 👍

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.

Nice work and great refactor, please take a look at the comments.

Copy link
Contributor

@ann-aot ann-aot left a comment

Choose a reason for hiding this comment

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

Nice work @dheepak-aot added some comments

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 17.95% ( 1961 / 10926 )
Methods: 8.1% ( 115 / 1419 )
Lines: 20.64% ( 1717 / 8317 )
Branches: 10.84% ( 129 / 1190 )

@github-actions
Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 32.41% ( 176 / 543 )
Methods: 21.25% ( 17 / 80 )
Lines: 39.25% ( 157 / 400 )
Branches: 3.17% ( 2 / 63 )

@github-actions
Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 65.01% ( 353 / 543 )
Methods: 53.62% ( 37 / 69 )
Lines: 67.24% ( 312 / 464 )
Branches: 40% ( 4 / 10 )

@github-actions
Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 38.9% ( 2638 / 6782 )
Methods: 30.84% ( 272 / 882 )
Lines: 44.36% ( 2244 / 5059 )
Branches: 14.51% ( 122 / 841 )

setInstitutionSetupUser(
context: ActionContext<InstitutionLocationState, RootState>,
): void {
context.commit("setInstitutionSetupUser", true);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ann-aot ann-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 Refactor @dheepak-aot 👍

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 doing the changes and the great refactor, looks good 👍

Copy link
Collaborator

@andrepestana-aot andrepestana-aot left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@guru-aot guru-aot left a comment

Choose a reason for hiding this comment

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

LGTM, nice work @dheepak-aot

@dheepak-aot dheepak-aot merged commit 2cfff52 into main Apr 20, 2023
@dheepak-aot dheepak-aot temporarily deployed to DEV April 20, 2023 19:32 — with GitHub Actions Inactive
@dheepak-aot dheepak-aot temporarily deployed to DEV April 20, 2023 19:33 — with GitHub Actions Inactive
@dheepak-aot dheepak-aot temporarily deployed to DEV April 20, 2023 19:46 — with GitHub Actions Inactive
@dheepak-aot dheepak-aot deleted the improvements/institution-guards branch April 24, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants