Skip to content

Commit

Permalink
Fix permission checks on tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
hengkysanjaya123 committed Jan 22, 2024
1 parent 0ff698f commit d93ec7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const routes: Routes = [
breadcrumb: 'Person',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN, ACR_ROLES.EDIT, ACR_ROLES.PRINT])
},
canActivate: [GuardService],
component: PersonComponent
},
{
Expand All @@ -74,6 +75,7 @@ const routes: Routes = [
breadcrumb: 'Scan',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN])
},
canActivate: [GuardService],
component: ScansComponent
},
{
Expand All @@ -82,6 +84,7 @@ const routes: Routes = [
breadcrumb: 'Delegate Types',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN, ACR_ROLES.EDIT_DELEGATE_TYPES])
},
canActivate: [GuardService],
component: DelegateTypesComponent
},
{
Expand All @@ -90,6 +93,7 @@ const routes: Routes = [
breadcrumb: 'Positions',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN, ACR_ROLES.EDIT_POSITIONS])
},
canActivate: [GuardService],
component: PositionsComponent
},
{
Expand All @@ -98,6 +102,7 @@ const routes: Routes = [
breadcrumb: 'Package Options',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN, ACR_ROLES.EDIT_PACKAGE_OPTIONS])
},
canActivate: [GuardService],
component: PackageOptionsComponent
},
{
Expand All @@ -106,6 +111,7 @@ const routes: Routes = [
breadcrumb: 'Zones',
roles: forAppCode(environment.worldskillsAppId, [ACR_ROLES.ADMIN, ACR_ROLES.EDIT_ZONES])
},
canActivate: [GuardService],
component: ZonesComponent
}
]
Expand Down
4 changes: 1 addition & 3 deletions src/app/event/event.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ <h2 class="mb-0">
[(selectedIndex)]="selectedTabIndex"
(selectedTabChange)="navigate($event)">
<ng-container *ngFor="let tab of tabs">
<mat-tab
*wsUserRole="tab.requiredRoles; appId: appId"
[label]="tab.label"></mat-tab>
<mat-tab [label]="tab.label"></mat-tab>
</ng-container>

</mat-tab-group>
Expand Down
5 changes: 5 additions & 0 deletions src/app/event/event.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export class EventComponent extends WsComponent implements OnInit {
this.authService.currentUser.subscribe(currentUser => {
this.hasAdHocPrintPermission = UserRoleUtil.userHasRoles(currentUser, environment.worldskillsAppId, environment.appRoles.ADMIN, environment.appRoles.AD_HOC_PRINT);
this.hasSetUpScanAppPermission = UserRoleUtil.userHasRoles(currentUser, environment.worldskillsAppId, environment.appRoles.ADMIN, environment.appRoles.SET_UP_SCAN_APP);

// hide tabs that user does not have permission to access
this.tabs = this.tabs.filter(tab => {
return tab.requiredRoles.some(role => UserRoleUtil.userHasRoles(currentUser, environment.worldskillsAppId, role));
});
})
)
}
Expand Down

0 comments on commit d93ec7a

Please sign in to comment.