Skip to content

Commit 1ea3f2f

Browse files
committed
feat(auth): hide My Tasks for project managers and block direct route access
1 parent 2963584 commit 1ea3f2f

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/app/app.routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ProjectMembersComponent } from './features/projects/components/project-
2424
import { ActivityLogComponent } from './features/activity/components/activity-log/activity-log.component';
2525
import { managerOrAdminGuard } from './core/auth/guards/manager-or-admin.guard';
2626
import { AppSettingsComponent } from './features/settings/components/app-settings/app-settings.component';
27+
import { nonProjectManagerGuard } from './core/auth/guards/non-project-manager.guard';
2728

2829
export const routes: Routes = [
2930
{ path: '', component: LandingPageComponent },
@@ -43,7 +44,7 @@ export const routes: Routes = [
4344
{ path: 'profile', component: UserProfileSecurityComponent, canActivate: [authGuard] },
4445
{ path: 'admin', component: AdminDashboardComponent, canActivate: [authGuard, adminRoleGuard] },
4546
{ path: 'tasks/create', component: TaskItemCreateComponent, canActivate: [authGuard] },
46-
{ path: 'tasks/my-tasks', component: UserTaskItemsComponent, canActivate: [authGuard] },
47+
{ path: 'tasks/my-tasks', component: UserTaskItemsComponent, canActivate: [authGuard, nonProjectManagerGuard] },
4748
{ path: 'login', component: HomeLoginComponent },
4849
{ path: 'callback', component: AuthCallbackComponent },
4950
{ path: 'notfound', redirectTo: 'not-found' },
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inject } from '@angular/core';
2+
import { CanActivateFn, Router } from '@angular/router';
3+
import { AppRole } from '../models/app-role.model';
4+
import { AuthService } from '../services/auth.service';
5+
6+
export const nonProjectManagerGuard: CanActivateFn = () => {
7+
const authService = inject(AuthService);
8+
const router = inject(Router);
9+
10+
if (!authService.hasRole(AppRole.ProjectManager)) {
11+
return true;
12+
}
13+
14+
return router.createUrlTree(['/unauthorized']);
15+
};

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ export class AppMenuComponent {
4646
label: 'Delivery',
4747
items: [
4848
{ label: 'All Tasks', icon: 'pi pi-fw pi-list', routerLink: ['/tasks'] },
49-
{ label: 'My Tasks', icon: 'pi pi-fw pi-user', routerLink: ['/tasks/my-tasks'] },
49+
{
50+
label: 'My Tasks',
51+
icon: 'pi pi-fw pi-user',
52+
routerLink: ['/tasks/my-tasks'],
53+
visible: !this.authService.hasRole(AppRole.ProjectManager)
54+
},
5055
{
5156
label: 'Create Task',
5257
icon: 'pi pi-fw pi-plus',

0 commit comments

Comments
 (0)