Added technician check to frontend #393

This commit is contained in:
Sven Heidemann 2023-10-02 15:11:34 +02:00
parent 73848c3141
commit eb3eb24e81
5 changed files with 209 additions and 203 deletions

View File

@ -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)) {

View File

@ -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) {

View File

@ -192,21 +192,23 @@ export class SidebarService {
this.authService.hasUserPermission(AuthRoles.Admin).then(async hasPermission => { this.authService.hasUserPermission(AuthRoles.Admin).then(async hasPermission => {
let authUser = await this.authService.getLoggedInUser(); let authUser = await this.authService.getLoggedInUser();
let user: UserDTO | null = authUser?.users?.find(u => u.server == this.server?.id) ?? null; 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) ?? []; let isTechnician = (authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? []).length > 0;
if (build || this.menuItems$.value.length == 0) { if (build || this.menuItems$.value.length == 0) {
await this.buildMenu(user, hasPermission, isTechnician.length > 0); await this.buildMenu(user, hasPermission, isTechnician);
} }
if (this.server) { if (this.server) {
this.serverMenu.visible = true; this.serverMenu.visible = true;
this.serverMembers.visible = !!user?.isModerator; this.serverMembers.visible = isTechnician || !!user?.isModerator;
this.serverAutoRoles.visible = this.hasFeature("AutoRoleModule") ? !!user?.isModerator : false; console.log(isTechnician, this.hasFeature("AutoRoleModule") && !!user?.isModerator)
this.serverLevels.visible = this.hasFeature("LevelModule") ? !!user?.isModerator : false; this.serverAutoRoles.visible = isTechnician || this.hasFeature("AutoRoleModule") && !!user?.isModerator;
this.serverAchievements.visible = this.hasFeature("AchievementsModule") ? !!user?.isModerator : false; this.serverLevels.visible = isTechnician || this.hasFeature("LevelModule") && !!user?.isModerator;
this.serverShortRoleNames.visible = this.hasFeature("ShortRoleName") ? !!user?.isAdmin : false; this.serverAchievements.visible = isTechnician || this.hasFeature("AchievementsModule") && !!user?.isModerator;
this.serverShortRoleNames.visible = isTechnician || this.hasFeature("ShortRoleName") && !!user?.isAdmin;
this.serverConfig.visible = !!user?.isAdmin || isTechnician.length > 0; console.log(isTechnician, this.serverAutoRoles.visible)
this.serverConfig.visible = isTechnician || !!user?.isAdmin;
} else { } else {
this.serverMenu.visible = false; this.serverMenu.visible = false;
} }