From 3ab53b59fa9b51b8c8e87b7b154d4df98320a6ad Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 2 Dec 2020 13:29:55 +0200 Subject: [PATCH] IsAdmin is temporary is admin or is manager --- .../app/auth/project-member-guard.service.ts | 53 ------------------- apps/red-ui/src/app/auth/red-role.guard.ts | 12 ++--- .../app/common/service/permissions.service.ts | 10 +++- .../dictionary-overview-screen.component.html | 1 + .../base-screen/base-screen.component.html | 4 +- apps/red-ui/src/app/state/app-state.guard.ts | 12 +++-- 6 files changed, 25 insertions(+), 67 deletions(-) delete mode 100644 apps/red-ui/src/app/auth/project-member-guard.service.ts diff --git a/apps/red-ui/src/app/auth/project-member-guard.service.ts b/apps/red-ui/src/app/auth/project-member-guard.service.ts deleted file mode 100644 index 0202a0791..000000000 --- a/apps/red-ui/src/app/auth/project-member-guard.service.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; -import { UserService } from '../user/user.service'; -import { AppLoadStateService } from '../utils/app-load-state.service'; -import { Observable } from 'rxjs'; -import { AppStateService } from '../state/app-state.service'; -import { NotificationService, NotificationType } from '../notification/notification.service'; -import { TranslateService } from '@ngx-translate/core'; - -@Injectable({ - providedIn: 'root' -}) -export class ProjectMemberGuard implements CanActivate { - constructor( - private readonly _router: Router, - private readonly _appLoadStateService: AppLoadStateService, - private readonly _appStateService: AppStateService, - private readonly _userService: UserService, - private readonly _notificationService: NotificationService, - private readonly _translateService: TranslateService - ) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return new Observable((obs) => { - if (this._userService.isManager(this._userService.user)) { - obs.next(true); - obs.complete(); - return; - } - - const projectId = route.params.projectId; - this._appStateService.loadAllProjects().then(() => { - const isProjectMember = this._appStateService.allProjects - .find((pw) => pw.project.projectId === projectId) - ?.project.memberIds.includes(this._userService.user.id); - if (!isProjectMember) { - this._router.navigate(['ui', 'projects']); - this._appLoadStateService.pushLoadingEvent(false); - this._notificationService.showToastNotification( - this._translateService.instant('project-member-guard.access-denied'), - null, - NotificationType.ERROR - ); - obs.next(false); - obs.complete(); - } else { - obs.next(true); - obs.complete(); - } - }); - }); - } -} diff --git a/apps/red-ui/src/app/auth/red-role.guard.ts b/apps/red-ui/src/app/auth/red-role.guard.ts index bbd9fdcd8..bea3612cb 100644 --- a/apps/red-ui/src/app/auth/red-role.guard.ts +++ b/apps/red-ui/src/app/auth/red-role.guard.ts @@ -11,12 +11,7 @@ class UrlTree {} providedIn: 'root' }) export class RedRoleGuard implements CanActivate { - constructor( - protected readonly _router: Router, - protected readonly _keycloak: KeycloakService, - private readonly _appLoadStateService: AppLoadStateService, - private readonly _userService: UserService - ) {} + constructor(protected readonly _router: Router, private readonly _appLoadStateService: AppLoadStateService, private readonly _userService: UserService) {} canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { return new Observable((obs) => { @@ -26,6 +21,11 @@ export class RedRoleGuard implements CanActivate { obs.next(false); obs.complete(); } else { + if (!this._userService.isUser() && state.url.startsWith('/ui/projects')) { + this._router.navigate(['/ui/admin-dictionaries']); + obs.next(false); + obs.complete(); + } obs.next(true); obs.complete(); } diff --git a/apps/red-ui/src/app/common/service/permissions.service.ts b/apps/red-ui/src/app/common/service/permissions.service.ts index fcc3bb95b..a97de4365 100644 --- a/apps/red-ui/src/app/common/service/permissions.service.ts +++ b/apps/red-ui/src/app/common/service/permissions.service.ts @@ -208,6 +208,14 @@ export class PermissionsService { if (!user) { user = this._userService.user; } - return user.isAdmin; + // TODO temporary + return user.isAdmin || user.isManager; + } + + isUser(user?: UserWrapper) { + if (!user) { + user = this._userService.user; + } + return user.isUser; } } diff --git a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html index c64e16b23..cad56b291 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html +++ b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html @@ -62,6 +62,7 @@ [mode]="'text'" [theme]="'tomorrow'" [options]="aceOptions" + [readOnly]="!permissionsService.isAdmin()" (textChanged)="textChanged($event)" [autoUpdateContent]="true" [text]="dictionaryEntriesAsText" diff --git a/apps/red-ui/src/app/screens/base-screen/base-screen.component.html b/apps/red-ui/src/app/screens/base-screen/base-screen.component.html index 6fbda8535..b36c50c08 100644 --- a/apps/red-ui/src/app/screens/base-screen/base-screen.component.html +++ b/apps/red-ui/src/app/screens/base-screen/base-screen.component.html @@ -1,6 +1,6 @@