Added technician check to frontend #393
This commit is contained in:
parent
73848c3141
commit
eb3eb24e81
@ -51,4 +51,4 @@
|
|||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "~4.9.5"
|
"typescript": "~4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,10 +50,14 @@ export class AuthGuard implements CanActivate {
|
|||||||
if (memberRole !== undefined) {
|
if (memberRole !== undefined) {
|
||||||
let userHasAccess = false;
|
let userHasAccess = false;
|
||||||
let authUser = await this.authService.getLoggedInUser();
|
let authUser = await this.authService.getLoggedInUser();
|
||||||
|
let isTechnician = (authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? []).length > 0;
|
||||||
|
if (isTechnician) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
let server = route.params["serverId"];
|
let server = route.params["serverId"];
|
||||||
|
|
||||||
if (!authUser || !authUser.users) {
|
if (!authUser || !authUser.users) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
authUser?.users?.forEach(u => {
|
authUser?.users?.forEach(u => {
|
||||||
if (u.server === +(server ?? 0)) {
|
if (u.server === +(server ?? 0)) {
|
||||||
|
@ -86,7 +86,7 @@ export class ShortRoleNamesComponent extends ComponentWithTable implements OnIni
|
|||||||
|
|
||||||
this.spinner.showSpinner();
|
this.spinner.showSpinner();
|
||||||
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
|
this.data.query<SingleDiscordQuery>(Queries.guildsQuery, {
|
||||||
id: server?.discordId
|
id: server?.discordId ?? 0
|
||||||
}
|
}
|
||||||
).subscribe(data => {
|
).subscribe(data => {
|
||||||
if (data.discord.guilds) {
|
if (data.discord.guilds) {
|
||||||
|
@ -15,216 +15,218 @@ import { DataService } from "../data/data.service";
|
|||||||
import { FeatureFlag } from "../../models/config/feature-flags.model";
|
import { FeatureFlag } from "../../models/config/feature-flags.model";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root"
|
providedIn: "root"
|
||||||
})
|
})
|
||||||
export class SidebarService {
|
export class SidebarService {
|
||||||
|
|
||||||
isSidebarOpen: boolean = true;
|
isSidebarOpen: boolean = true;
|
||||||
menuItems$ = new BehaviorSubject<MenuItem[]>(new Array<MenuItem>());
|
menuItems$ = new BehaviorSubject<MenuItem[]>(new Array<MenuItem>());
|
||||||
server!: Server | undefined;
|
server!: Server | undefined;
|
||||||
|
|
||||||
dashboard: MenuItem = {};
|
dashboard: MenuItem = {};
|
||||||
serverDashboard: MenuItem = {};
|
serverDashboard: MenuItem = {};
|
||||||
serverProfile: MenuItem = {};
|
serverProfile: MenuItem = {};
|
||||||
serverMembers: MenuItem = {};
|
serverMembers: MenuItem = {};
|
||||||
serverAutoRoles: MenuItem = {};
|
serverAutoRoles: MenuItem = {};
|
||||||
serverLevels: MenuItem = {};
|
serverLevels: MenuItem = {};
|
||||||
serverAchievements: MenuItem = {};
|
serverAchievements: MenuItem = {};
|
||||||
serverShortRoleNames: MenuItem = {};
|
serverShortRoleNames: MenuItem = {};
|
||||||
serverConfig: MenuItem = {};
|
serverConfig: MenuItem = {};
|
||||||
serverMenu: MenuItem = {};
|
serverMenu: MenuItem = {};
|
||||||
adminConfig: MenuItem = {};
|
adminConfig: MenuItem = {};
|
||||||
adminUsers: MenuItem = {};
|
adminUsers: MenuItem = {};
|
||||||
adminMenu: MenuItem = {};
|
adminMenu: MenuItem = {};
|
||||||
|
|
||||||
featureFlags: FeatureFlag[] = [];
|
featureFlags: FeatureFlag[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private themeService: ThemeService,
|
private themeService: ThemeService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private translateService: TranslateService,
|
private translateService: TranslateService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private serverService: ServerService,
|
private serverService: ServerService,
|
||||||
private data: DataService
|
private data: DataService
|
||||||
) {
|
) {
|
||||||
this.themeService.isSidebarOpen$.subscribe(value => {
|
this.themeService.isSidebarOpen$.subscribe(value => {
|
||||||
this.isSidebarOpen = value;
|
this.isSidebarOpen = value;
|
||||||
this.setMenu(true);
|
this.setMenu(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.translateService.onLangChange.subscribe(_ => {
|
||||||
|
this.setMenu(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.serverService.server$.subscribe(server => {
|
||||||
|
this.server = server;
|
||||||
|
if (server) {
|
||||||
|
this.setMenu(true);
|
||||||
|
} else {
|
||||||
|
this.setMenu(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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",
|
||||||
|
routerLink: "dashboard"
|
||||||
|
};
|
||||||
|
this.serverDashboard = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.dashboard") : "",
|
||||||
|
icon: "pi pi-th-large",
|
||||||
|
routerLink: `server/${this.server?.id}`
|
||||||
|
};
|
||||||
|
this.serverProfile = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.profile") : "",
|
||||||
|
icon: "pi pi-id-card",
|
||||||
|
routerLink: `server/${this.server?.id}/members/${user?.id}`
|
||||||
|
};
|
||||||
|
this.serverMembers = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.members") : "",
|
||||||
|
icon: "pi pi-users",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/members`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverAutoRoles = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.auto_roles") : "",
|
||||||
|
icon: "pi pi-sitemap",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/auto-roles`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverLevels = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.levels") : "",
|
||||||
|
icon: "pi pi-book",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/levels`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverAchievements = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.achievements") : "",
|
||||||
|
icon: "pi pi-angle-double-up",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/achievements`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverShortRoleNames = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.short_role_names") : "",
|
||||||
|
icon: "pi pi-list",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/short-role-names`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverConfig = {
|
||||||
|
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.configuration") : "",
|
||||||
|
icon: "pi pi-cog",
|
||||||
|
visible: true,
|
||||||
|
routerLink: `server/${this.server?.id}/config`
|
||||||
|
};
|
||||||
|
|
||||||
|
this.serverMenu = {
|
||||||
|
label: this.isSidebarOpen ? this.server?.name : "",
|
||||||
|
icon: "pi pi-server",
|
||||||
|
visible: false,
|
||||||
|
expanded: true,
|
||||||
|
items: [this.serverDashboard, this.serverProfile, this.serverMembers, this.serverAutoRoles, this.serverLevels, this.serverAchievements, this.serverShortRoleNames, this.serverConfig]
|
||||||
|
};
|
||||||
|
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 || isTechnician,
|
||||||
|
expanded: true,
|
||||||
|
items: [this.adminConfig, this.adminUsers]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
setMenu(build: boolean = false) {
|
||||||
|
const server = this.server;
|
||||||
|
|
||||||
|
if (server) {
|
||||||
|
this.featureFlags = [];
|
||||||
|
this.data.query<PossibleFeatureFlagsQuery>("{possibleFeatureFlags}"
|
||||||
|
).subscribe(data => {
|
||||||
|
let observables: Observable<HasServerFeatureFlagQuery>[] = [];
|
||||||
|
data.possibleFeatureFlags.forEach(flag => {
|
||||||
|
observables.push(
|
||||||
|
this.data.query<HasServerFeatureFlagQuery>(Queries.hasServerFeatureFlag, {
|
||||||
|
filter: { id: server.id },
|
||||||
|
flag: flag
|
||||||
|
},
|
||||||
|
function(data: Query) {
|
||||||
|
return data.servers[0];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.translateService.onLangChange.subscribe(_ => {
|
forkJoin(observables).subscribe(data => {
|
||||||
this.setMenu(true);
|
data.forEach(flag => {
|
||||||
});
|
if (!flag.hasFeatureFlag.value) {
|
||||||
|
return;
|
||||||
this.serverService.server$.subscribe(server => {
|
|
||||||
this.server = server;
|
|
||||||
if (server) {
|
|
||||||
this.setMenu(true);
|
|
||||||
} else {
|
|
||||||
this.setMenu(false);
|
|
||||||
}
|
}
|
||||||
|
this.featureFlags.push(flag.hasFeatureFlag);
|
||||||
|
});
|
||||||
|
this._setMenu(build);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this._setMenu(build);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async buildMenu(user: UserDTO | null, hasPermission: boolean, isTechnician: boolean = false) {
|
private _setMenu(build: boolean = false) {
|
||||||
this.dashboard = {
|
this.authService.hasUserPermission(AuthRoles.Admin).then(async hasPermission => {
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.dashboard") : "",
|
let authUser = await this.authService.getLoggedInUser();
|
||||||
icon: "pi pi-th-large",
|
let user: UserDTO | null = authUser?.users?.find(u => u.server == this.server?.id) ?? null;
|
||||||
routerLink: "dashboard"
|
let isTechnician = (authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? []).length > 0;
|
||||||
};
|
|
||||||
this.serverDashboard = {
|
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.dashboard") : "",
|
|
||||||
icon: "pi pi-th-large",
|
|
||||||
routerLink: `server/${this.server?.id}`
|
|
||||||
};
|
|
||||||
this.serverProfile = {
|
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.profile") : "",
|
|
||||||
icon: "pi pi-id-card",
|
|
||||||
routerLink: `server/${this.server?.id}/members/${user?.id}`
|
|
||||||
};
|
|
||||||
this.serverMembers = {
|
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.members") : "",
|
|
||||||
icon: "pi pi-users",
|
|
||||||
visible: true,
|
|
||||||
routerLink: `server/${this.server?.id}/members`
|
|
||||||
};
|
|
||||||
|
|
||||||
this.serverAutoRoles = {
|
if (build || this.menuItems$.value.length == 0) {
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.auto_roles") : "",
|
await this.buildMenu(user, hasPermission, isTechnician);
|
||||||
icon: "pi pi-sitemap",
|
}
|
||||||
visible: true,
|
|
||||||
routerLink: `server/${this.server?.id}/auto-roles`
|
|
||||||
};
|
|
||||||
|
|
||||||
this.serverLevels = {
|
if (this.server) {
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.levels") : "",
|
this.serverMenu.visible = true;
|
||||||
icon: "pi pi-book",
|
this.serverMembers.visible = isTechnician || !!user?.isModerator;
|
||||||
visible: true,
|
console.log(isTechnician, this.hasFeature("AutoRoleModule") && !!user?.isModerator)
|
||||||
routerLink: `server/${this.server?.id}/levels`
|
this.serverAutoRoles.visible = isTechnician || this.hasFeature("AutoRoleModule") && !!user?.isModerator;
|
||||||
};
|
this.serverLevels.visible = isTechnician || this.hasFeature("LevelModule") && !!user?.isModerator;
|
||||||
|
this.serverAchievements.visible = isTechnician || this.hasFeature("AchievementsModule") && !!user?.isModerator;
|
||||||
|
this.serverShortRoleNames.visible = isTechnician || this.hasFeature("ShortRoleName") && !!user?.isAdmin;
|
||||||
|
|
||||||
this.serverAchievements = {
|
console.log(isTechnician, this.serverAutoRoles.visible)
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.achievements") : "",
|
this.serverConfig.visible = isTechnician || !!user?.isAdmin;
|
||||||
icon: "pi pi-angle-double-up",
|
} else {
|
||||||
visible: true,
|
this.serverMenu.visible = false;
|
||||||
routerLink: `server/${this.server?.id}/achievements`
|
}
|
||||||
};
|
|
||||||
|
|
||||||
this.serverShortRoleNames = {
|
let menuItems: MenuItem[] = [
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.short_role_names") : "",
|
this.dashboard,
|
||||||
icon: "pi pi-list",
|
this.serverMenu,
|
||||||
visible: true,
|
this.adminMenu
|
||||||
routerLink: `server/${this.server?.id}/short-role-names`
|
];
|
||||||
};
|
this.menuItems$.next(menuItems);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.serverConfig = {
|
private hasFeature(key: string): boolean {
|
||||||
label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.configuration") : "",
|
const flag = this.featureFlags.filter(flag => flag.key == key);
|
||||||
icon: "pi pi-cog",
|
if (flag.length == 0) {
|
||||||
visible: true,
|
return false;
|
||||||
routerLink: `server/${this.server?.id}/config`
|
|
||||||
};
|
|
||||||
|
|
||||||
this.serverMenu = {
|
|
||||||
label: this.isSidebarOpen ? this.server?.name : "",
|
|
||||||
icon: "pi pi-server",
|
|
||||||
visible: false,
|
|
||||||
expanded: true,
|
|
||||||
items: [this.serverDashboard, this.serverProfile, this.serverMembers, this.serverAutoRoles, this.serverLevels, this.serverAchievements, this.serverShortRoleNames, this.serverConfig]
|
|
||||||
};
|
|
||||||
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 || isTechnician,
|
|
||||||
expanded: true,
|
|
||||||
items: [this.adminConfig, this.adminUsers]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
setMenu(build: boolean = false) {
|
|
||||||
const server = this.server;
|
|
||||||
|
|
||||||
if (server) {
|
|
||||||
this.featureFlags = [];
|
|
||||||
this.data.query<PossibleFeatureFlagsQuery>("{possibleFeatureFlags}"
|
|
||||||
).subscribe(data => {
|
|
||||||
let observables: Observable<HasServerFeatureFlagQuery>[] = [];
|
|
||||||
data.possibleFeatureFlags.forEach(flag => {
|
|
||||||
observables.push(
|
|
||||||
this.data.query<HasServerFeatureFlagQuery>(Queries.hasServerFeatureFlag, {
|
|
||||||
filter: { id: server.id },
|
|
||||||
flag: flag
|
|
||||||
},
|
|
||||||
function(data: Query) {
|
|
||||||
return data.servers[0];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
forkJoin(observables).subscribe(data => {
|
|
||||||
data.forEach(flag => {
|
|
||||||
if (!flag.hasFeatureFlag.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.featureFlags.push(flag.hasFeatureFlag);
|
|
||||||
});
|
|
||||||
this._setMenu(build);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this._setMenu(build);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _setMenu(build: boolean = false) {
|
|
||||||
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?.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, isTechnician.length > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.server) {
|
|
||||||
this.serverMenu.visible = true;
|
|
||||||
this.serverMembers.visible = !!user?.isModerator;
|
|
||||||
this.serverAutoRoles.visible = this.hasFeature("AutoRoleModule") ? !!user?.isModerator : false;
|
|
||||||
this.serverLevels.visible = this.hasFeature("LevelModule") ? !!user?.isModerator : false;
|
|
||||||
this.serverAchievements.visible = this.hasFeature("AchievementsModule") ? !!user?.isModerator : false;
|
|
||||||
this.serverShortRoleNames.visible = this.hasFeature("ShortRoleName") ? !!user?.isAdmin : false;
|
|
||||||
|
|
||||||
this.serverConfig.visible = !!user?.isAdmin || isTechnician.length > 0;
|
|
||||||
} else {
|
|
||||||
this.serverMenu.visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let menuItems: MenuItem[] = [
|
|
||||||
this.dashboard,
|
|
||||||
this.serverMenu,
|
|
||||||
this.adminMenu
|
|
||||||
];
|
|
||||||
this.menuItems$.next(menuItems);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private hasFeature(key: string): boolean {
|
|
||||||
const flag = this.featureFlags.filter(flag => flag.key == key);
|
|
||||||
if (flag.length == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return flag[0].value;
|
|
||||||
}
|
}
|
||||||
|
return flag[0].value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"WebVersion": {
|
"WebVersion": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "1",
|
"Minor": "1",
|
||||||
"Micro": "9"
|
"Micro": "9"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user