+
diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts
index 7f85300d9..669db42f6 100644
--- a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts
+++ b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts
@@ -3,6 +3,8 @@ import { MatDialog } from '@angular/material';
import { TranslateService } from '@ngx-translate/core';
import { AuthService } from '../../core/services/auth/auth.service';
import { UserDialogComponent } from '../misc/navigation/user-dialog/user-dialog.component';
+import { Principal } from '../../core/model/auth/Principal';
+import { AppRole } from '../../core/common/enum/app-role';
declare interface RouteInfo {
path: string;
@@ -13,6 +15,7 @@ declare interface GroupMenuItem {
title: string;
routes: RouteInfo[];
requiresAuthentication: boolean;
+ requiresAdmin: boolean;
}
export const GENERAL_ROUTES: RouteInfo[] = [
@@ -24,8 +27,8 @@ export const DMP_ROUTES: RouteInfo[] = [
{ path: '/projects', title: 'SIDE-BAR.MY-PROJECTS', icon: 'work_outline' }
];
export const ADMIN_ROUTES: RouteInfo[] = [
- { path: '/dmp-templates', title: 'SIDE-BAR.DMP-TEMPLATES', icon: 'library_books' },
- { path: '/dataset-templates', title: 'SIDE-BAR.DATASET-TEMPLATES', icon: 'library_books' },
+ { path: '/dmp-profiles', title: 'SIDE-BAR.DMP-TEMPLATES', icon: 'library_books' },
+ { path: '/dataset-profiles', title: 'SIDE-BAR.DATASET-TEMPLATES', icon: 'library_books' },
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' }
];
// export const HISTORY_ROUTES: RouteInfo[] = [
@@ -56,21 +59,24 @@ export class SidebarComponent implements OnInit {
this.generalItems = {
title: 'SIDE-BAR.GENERAL',
routes: GENERAL_ROUTES,
- requiresAuthentication: false
+ requiresAuthentication: false,
+ requiresAdmin: false,
}
this.groupMenuItems.push(this.generalItems);
this.dmpItems = {
title: 'SIDE-BAR.DMP',
routes: DMP_ROUTES,
- requiresAuthentication: true
+ requiresAuthentication: true,
+ requiresAdmin: false
}
this.groupMenuItems.push(this.dmpItems);
this.adminItems = {
title: 'SIDE-BAR.ADMIN',
routes: ADMIN_ROUTES,
- requiresAuthentication: true
+ requiresAuthentication: true,
+ requiresAdmin: true
}
this.groupMenuItems.push(this.adminItems);
@@ -83,7 +89,8 @@ export class SidebarComponent implements OnInit {
this.publicItems = {
title: 'SIDE-BAR.PUBLIC',
routes: PUBLIC_ROUTES,
- requiresAuthentication: false
+ requiresAuthentication: false,
+ requiresAdmin: false
}
this.groupMenuItems.push(this.publicItems);
}
@@ -97,9 +104,33 @@ export class SidebarComponent implements OnInit {
}
public isAuthenticated(): boolean {
+ const myBollean = this.isAdmin();
return !(!this.authentication.current());
}
+ public isAdmin(): boolean {
+ const principal: Principal = this.authentication.current();
+ if (principal) {
+ if (principal.authorities.find(role => role === AppRole.Admin)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ showItem(value: GroupMenuItem) {
+ if (value.requiresAdmin) {
+ return this.isAdmin();
+ }
+ else {
+ return this.isAuthenticated() || !value.requiresAuthentication;
+ }
+ }
+
openProfile() {
const dialogRef = this.dialog.open(UserDialogComponent, {
hasBackdrop: true,