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 - Restrict non BC Public Institutions from accessing Routes for BC Public institutions #1898

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {
InstitutionUserAuthRolesAndLocation,
InstitutionUserRoles,
UserStateForStore,
} from "@/types";
import { InstitutionLocationState, InstitutionUserRoles } from "@/types";
import { computed } from "vue";
import { Store, useStore } from "vuex";
import { useAuth } from "..";

export function useInstitutionAuth(rootStore?: Store<any>) {
const store = rootStore ?? useStore();

// From store get user details and authorizations.
const institutionUserDetails = store.state.institution
.userState as UserStateForStore;
// From store get institution details.
const institutionDetails = store.state
.institution as InstitutionLocationState;

// From institution details in store, get institution user details and authorizations.
const institutionUserDetails = institutionDetails.userState;
const authorizations =
(store.state.institution.authorizationsState
.authorizations as InstitutionUserAuthRolesAndLocation[]) ?? [];
institutionDetails.authorizationsState.authorizations ?? [];

const { isAuthenticated } = useAuth();
const isAuthenticatedInstitutionUser = computed(
Expand Down Expand Up @@ -44,6 +42,10 @@ export function useInstitutionAuth(rootStore?: Store<any>) {
// User type Admin | User.
const userType = computed(() => userAuthorization?.userType);

const isBCPublic = computed(
() => institutionDetails.institutionState?.isBCPublic,
);

return {
isAdmin,
isAuthenticated,
Expand All @@ -55,5 +57,6 @@ export function useInstitutionAuth(rootStore?: Store<any>) {
isInstitutionSetupUser,
hasLocationAccess,
userType,
isBCPublic,
};
}
7 changes: 6 additions & 1 deletion sources/packages/web/src/router/InstitutionRouteHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function isInstitutionUserAllowed(to: RouteLocationNormalized): boolean {
isAdmin,
isLegalSigningAuthority,
userType,
isBCPublic,
hasLocationAccess,
} = useInstitutionAuth(store);

Expand All @@ -81,7 +82,11 @@ function isInstitutionUserAllowed(to: RouteLocationNormalized): boolean {
return false;
}

// TODO: Validate the route for BCPublic institutions must be done here.
// If the route is suppose to be accessible only for BC Public institutions
// reject the access for other institution types.
if (to.meta.allowOnlyBCPublic && !isBCPublic.value) {
return false;
}

// If the user is institution admin, then they have access to all routes
// except the routes which are accessible only for legal signing authority.
Expand Down
6 changes: 6 additions & 0 deletions sources/packages/web/src/router/InstitutionRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
},
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand Down Expand Up @@ -468,6 +469,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
component: InstitutionStudentProfile,
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
Copy link
Contributor

@ann-aot ann-aot Apr 20, 2023

Choose a reason for hiding this comment

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

just wanted to check if, adding allowOnlyBCPublic to the parent (line 457) will it protect all its children. As discussed, you can just try and check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tested by using allowOnlyBCPublic in parent onluy and it works perfectly. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for trying it. As discussed, we can test and remove the other meta from the children in another ticket

institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand All @@ -481,6 +483,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
component: InstitutionStudentApplications,
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand All @@ -494,6 +497,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
component: InstitutionStudentRestrictions,
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand All @@ -507,6 +511,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
component: InstitutionStudentFileUploads,
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand All @@ -520,6 +525,7 @@ export const institutionRoutes: Array<RouteRecordRaw> = [
component: InstitutionStudentNotes,
meta: {
clientType: ClientIdType.Institution,
allowOnlyBCPublic: true,
institutionUserTypes: [
InstitutionUserTypes.admin,
InstitutionUserTypes.user,
Expand Down