Fixes side bar admin pages showing to all users. (Issue #85)
This commit is contained in:
parent
c09685c501
commit
e6bc04b3f5
|
@ -61,7 +61,7 @@ const appRoutes: Routes = [
|
|||
}
|
||||
},
|
||||
{
|
||||
path: 'dmp-templates',
|
||||
path: 'dmp-profiles',
|
||||
loadChildren: './ui/admin/dmp-profile/dmp-profile.module#DmpProfileModule',
|
||||
data: {
|
||||
breadcrumb: true
|
||||
|
@ -75,7 +75,7 @@ const appRoutes: Routes = [
|
|||
}
|
||||
},
|
||||
{
|
||||
path: 'dataset-templates',
|
||||
path: 'dataset-profiles',
|
||||
loadChildren: './ui/admin/dataset-profile/dataset-profile.module#DatasetProfileModule',
|
||||
data: {
|
||||
breadcrumb: true
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
<!-- Sidebar Menu -->
|
||||
<ul class="nav" *ngFor="let groupMenuItem of groupMenuItems; last as isLast; first as isFirst" [class.nav-list-item]="(isAuthenticated() || !groupMenuItem.requiresAuthentication)">
|
||||
<div *ngIf="isAuthenticated() || !groupMenuItem.requiresAuthentication">
|
||||
<div *ngIf="showItem(groupMenuItem);">
|
||||
<div class="sidebarSubtitle">
|
||||
<p>{{groupMenuItem.title | translate}}</p>
|
||||
</div>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue