Secured config endpoints #334

This commit is contained in:
2023-08-15 21:50:37 +02:00
parent 8a0d939147
commit e549341196
10 changed files with 67 additions and 19 deletions

View File

@@ -28,8 +28,11 @@ export class AuthGuard implements CanActivate {
const role = route.data['role'];
if (role) {
this.authService.hasUserPermission(role).then(hasPermission => {
if (!hasPermission) {
this.authService.hasUserPermission(role).then(async hasPermission => {
let authUser = await this.authService.getLoggedInUser();
let isTechnician = authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? [];
if (!hasPermission && !isTechnician) {
this.router.navigate(['/dashboard']);
return false;
}

View File

@@ -67,7 +67,7 @@ export class SidebarService {
}
}
async buildMenu(user: UserDTO | null, hasPermission: boolean) {
async buildMenu(user: UserDTO | null, hasPermission: boolean, isTechnician: boolean = false) {
this.dashboard = {
label: this.isSidebarOpen ? this.translateService.instant("sidebar.dashboard") : "",
icon: "pi pi-th-large",
@@ -127,18 +127,20 @@ export class SidebarService {
};
this.adminConfig = {
label: this.isSidebarOpen ? this.translateService.instant("sidebar.config") : "",
visible: hasPermission || isTechnician,
icon: "pi pi-cog",
routerLink: "/admin/settings"
};
this.adminUsers = {
label: this.isSidebarOpen ? this.translateService.instant("sidebar.auth_user_list") : "",
visible: hasPermission,
icon: "pi pi-user-edit",
routerLink: "/admin/users"
};
this.adminMenu = {
label: this.isSidebarOpen ? this.translateService.instant("sidebar.administration") : "",
icon: "pi pi-cog",
visible: hasPermission,
visible: hasPermission || isTechnician,
expanded: true,
items: [this.adminConfig, this.adminUsers]
};
@@ -148,9 +150,10 @@ export class SidebarService {
this.authService.hasUserPermission(AuthRoles.Admin).then(async hasPermission => {
let authUser = await this.authService.getLoggedInUser();
let user: UserDTO | null = authUser?.users?.find(u => u.server == this.server$.value?.id) ?? null;
let isTechnician = authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? [];
if (build || this.menuItems$.value.length == 0) {
await this.buildMenu(user, hasPermission);
await this.buildMenu(user, hasPermission, isTechnician.length > 0);
}
if (this.server$.value) {
@@ -159,7 +162,7 @@ export class SidebarService {
this.serverAutoRoles.visible = !!user?.isModerator;
this.serverLevels.visible = !!user?.isModerator;
this.serverAchievements.visible = !!user?.isModerator;
this.serverConfig.visible = !!user?.isAdmin;
this.serverConfig.visible = !!user?.isAdmin || isTechnician.length > 0;
} else {
this.serverMenu.visible = false;
}