-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
} | ||
return true; | ||
} | ||
// If the user is not an admin, check if the route is allowed for non admin user. |
There was a problem hiding this comment.
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: [ |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Define error handling on router error. | ||
router.onError((error: unknown) => { | ||
console.error(error); | ||
throw error; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
sources/packages/web/src/composables/institution/useInstitutionAuth.ts
Outdated
Show resolved
Hide resolved
sources/packages/web/src/composables/institution/useInstitutionState.ts
Outdated
Show resolved
Hide resolved
const institutionUserDetails = store.getters[ | ||
"institution/myDetails" | ||
] as UserStateForStore; | ||
const authorizations = |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the isAuthenticatedInstitutionUser
👍
There was a problem hiding this 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.
There was a problem hiding this 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
Kudos, SonarCloud Quality Gate passed!
|
setInstitutionSetupUser( | ||
context: ActionContext<InstitutionLocationState, RootState>, | ||
): void { | ||
context.commit("setInstitutionSetupUser", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this 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 👍
There was a problem hiding this 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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
Improvement in Guards
The following improvements have been implemented to the Guards.
Defining the interface to route meta to have it typed.

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 withallowOnlyLegalSigningAuthority
set to true.useInstitutionAuth
refactored to use the store getters and added additional properties.isAuthenticatedInstitutionUser
created inuseInstitutionAuth
to include the verification of isActive status of the user. And due to which the following nav buttons does not appear during create institutions.As per the Vue documentation, Global before guards are replaced with Global Resolve guards.
UserStateForStore
as the interface properties were not in sync with data stored in state.