Skip to content

Commit 3c2f55d

Browse files
committed
feat(authz): align role-based route/menu/page access with backend policies
1 parent 4319f3e commit 3c2f55d

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/app/app.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export const routes: Routes = [
3030
{ path: 'dashboard', component: DashboardComponent, canActivate: [authGuard] },
3131
{ path: 'projects', component: ProjectListComponent, canActivate: [authGuard] },
3232
{ path: 'projects/kanban', component: ProjectKanbanComponent, canActivate: [authGuard] },
33-
{ path: 'projects/create', component: ProjectCreateComponent, canActivate: [authGuard] },
33+
{ path: 'projects/create', component: ProjectCreateComponent, canActivate: [authGuard, managerOrAdminGuard] },
3434
{ path: 'projects/members', component: ProjectMembersComponent, canActivate: [authGuard] },
35-
{ path: 'projects/details', component: ProjectDetailsComponent, canActivate: [authGuard] },
35+
{ path: 'projects/details', component: ProjectDetailsComponent, canActivate: [authGuard, managerOrAdminGuard] },
3636
{ path: 'tasks', component: TaskItemListComponent, canActivate: [authGuard] },
3737
{ path: 'search', component: SearchFiltersComponent, canActivate: [authGuard] },
3838
{ path: 'docs', component: ProjectDocsComponent, canActivate: [authGuard] },

src/app/core/layout/component/app-menu/app-menu.component.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ export class AppMenuComponent {
2525
label: 'Workspaces',
2626
items: [
2727
{ label: 'All Projects', icon: 'pi pi-fw pi-list', routerLink: ['/projects'] },
28-
{ label: 'Project Details', icon: 'pi pi-fw pi-folder-open', routerLink: ['/projects/details'] },
28+
{
29+
label: 'Project Details',
30+
icon: 'pi pi-fw pi-folder-open',
31+
routerLink: ['/projects/details'],
32+
visible: this.authService.hasAnyRole(['Administrator', 'ProjectManager'])
33+
},
2934
{ label: 'Project Members', icon: 'pi pi-fw pi-users', routerLink: ['/projects/members'] },
30-
{ label: 'Create Project', icon: 'pi pi-fw pi-plus', routerLink: ['/projects/create'] },
35+
{
36+
label: 'Create Project',
37+
icon: 'pi pi-fw pi-plus',
38+
routerLink: ['/projects/create'],
39+
visible: this.authService.hasAnyRole(['Administrator', 'ProjectManager'])
40+
},
3141
{ label: 'Kanban Board', icon: 'pi pi-fw pi-th-large', routerLink: ['/projects/kanban'] }
3242
]
3343
},
@@ -36,7 +46,12 @@ export class AppMenuComponent {
3646
items: [
3747
{ label: 'All Tasks', icon: 'pi pi-fw pi-list', routerLink: ['/tasks'] },
3848
{ label: 'My Tasks', icon: 'pi pi-fw pi-user', routerLink: ['/tasks/my-tasks'] },
39-
{ label: 'Create Task', icon: 'pi pi-fw pi-plus', routerLink: ['/tasks/create'] }
49+
{
50+
label: 'Create Task',
51+
icon: 'pi pi-fw pi-plus',
52+
routerLink: ['/tasks/create'],
53+
visible: this.authService.hasAnyRole(['Administrator', 'ProjectManager', 'User'])
54+
}
4055
]
4156
},
4257
{

src/app/features/projects/components/project-list/project-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2>All Projects</h2>
1515

1616
<div class="projects-header__actions">
1717
<button pButton type="button" label="Refresh" icon="pi pi-refresh" class="p-button-outlined" (click)="refreshProjects()" [loading]="loading"></button>
18-
<button pButton type="button" label="Create Project" icon="pi pi-plus" (click)="createProject()"></button>
18+
<button *ngIf="canManageProjects" pButton type="button" label="Create Project" icon="pi pi-plus" (click)="createProject()"></button>
1919
</div>
2020
</div>
2121
</p-card>

src/app/features/projects/components/project-list/project-list.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class ProjectListComponent implements OnInit, OnDestroy {
6262
return this.preferencesService.preferences().defaultTablePageSize;
6363
}
6464

65+
get canManageProjects(): boolean {
66+
return this.authService.hasAnyRole(['Administrator', 'ProjectManager']);
67+
}
68+
6569
trackByProjectId(_: number, project: ProjectDto): string {
6670
return project.id;
6771
}
@@ -84,6 +88,10 @@ export class ProjectListComponent implements OnInit, OnDestroy {
8488
}
8589

8690
createProject(): void {
91+
if (!this.canManageProjects) {
92+
return;
93+
}
94+
8795
void this.router.navigate(['/projects/create']);
8896
}
8997

0 commit comments

Comments
 (0)