From 75adc2285e9d83cbe0c8bea88b9bae5a75c58340 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 3 Oct 2023 10:51:40 +0200 Subject: [PATCH] Fixed feature flag handling #393 --- kdb-bot/src/bot/bot.json | 2 +- kdb-bot/src/bot_api/bot-api.json | 2 +- kdb-bot/src/bot_core/bot-core.json | 2 +- .../configuration/feature_flags_settings.py | 2 +- .../src/bot_core/service/config_service.py | 8 +- kdb-bot/src/bot_data/bot-data.json | 2 +- kdb-bot/src/bot_graphql/bot-graphql.json | 2 +- .../mutations/technician_config_mutation.py | 14 +- .../modules/achievements/achievements.json | 2 +- kdb-bot/src/modules/auto_role/auto-role.json | 2 +- kdb-bot/src/modules/base/base.json | 2 +- kdb-bot/src/modules/boot_log/boot-log.json | 2 +- kdb-bot/src/modules/config/config.json | 2 +- .../src/modules/config/config_extension.py | 2 +- kdb-bot/src/modules/database/database.json | 2 +- kdb-bot/src/modules/level/level.json | 2 +- .../src/modules/permission/permission.json | 2 +- .../permission/service/permission_service.py | 6 +- .../src/modules/technician/technician.json | 2 +- kdb-bot/tools/checks/checks.json | 2 +- kdb-bot/tools/get_version/get-version.json | 2 +- kdb-bot/tools/post_build/post-build.json | 2 +- kdb-bot/tools/set_version/set-version.json | 2 +- kdb-web/package.json | 2 +- .../modules/shared/guards/auth/auth.guard.ts | 13 +- .../app/services/sidebar/sidebar.service.ts | 390 +++++++++--------- kdb-web/src/assets/version.json | 2 +- 27 files changed, 243 insertions(+), 232 deletions(-) diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index 4a5a808b..6cfefe9a 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_api/bot-api.json b/kdb-bot/src/bot_api/bot-api.json index 50a61597..cc6404cc 100644 --- a/kdb-bot/src/bot_api/bot-api.json +++ b/kdb-bot/src/bot_api/bot-api.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/bot_core/bot-core.json b/kdb-bot/src/bot_core/bot-core.json index f82bbff3..c8a158d2 100644 --- a/kdb-bot/src/bot_core/bot-core.json +++ b/kdb-bot/src/bot_core/bot-core.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py b/kdb-bot/src/bot_core/configuration/feature_flags_settings.py index 9178637c..37c17483 100644 --- a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py +++ b/kdb-bot/src/bot_core/configuration/feature_flags_settings.py @@ -26,7 +26,7 @@ class FeatureFlagsSettings(ConfigurationModelABC): FeatureFlagsEnum.game_server.value: False, # 25.09.2023 #366 FeatureFlagsEnum.sync_xp.value: False, # 25.09.2023 #366 FeatureFlagsEnum.short_role_name.value: False, # 28.09.2023 #378 - FeatureFlagsEnum.technician_full_access.value: False, # 28.09.2023 #393 + FeatureFlagsEnum.technician_full_access.value: False, # 03.10.2023 #393 } def __init__(self, **kwargs: dict): diff --git a/kdb-bot/src/bot_core/service/config_service.py b/kdb-bot/src/bot_core/service/config_service.py index c9022056..6aa29b83 100644 --- a/kdb-bot/src/bot_core/service/config_service.py +++ b/kdb-bot/src/bot_core/service/config_service.py @@ -7,7 +7,6 @@ from bot_data.abc.technician_config_repository_abc import TechnicianConfigReposi from bot_data.model.server import Server from bot_data.model.technician_config import TechnicianConfig from bot_data.service.server_config_seeder import ServerConfigSeeder -from bot_data.service.technician_config_seeder import TechnicianConfigSeeder class ConfigService: @@ -17,7 +16,6 @@ class ConfigService: services: ServiceProviderABC, technician_config_repo: TechnicianConfigRepositoryABC, server_config_repo: ServerConfigRepositoryABC, - tech_seeder: TechnicianConfigSeeder, server_seeder: ServerConfigSeeder, ): self._config = config @@ -25,13 +23,9 @@ class ConfigService: self._technician_config_repo = technician_config_repo self._server_config_repo = server_config_repo - self._tech_seeder = tech_seeder self._server_seeder = server_seeder - async def reload_technician_config(self): - if not self._technician_config_repo.does_technician_config_exists(): - await self._tech_seeder.seed() - + def reload_technician_config(self): technician_config = self._technician_config_repo.get_technician_config() self._config.add_configuration(TechnicianConfig, technician_config) self._config.add_configuration(FeatureFlagsSettings, FeatureFlagsSettings(**technician_config.feature_flags)) diff --git a/kdb-bot/src/bot_data/bot-data.json b/kdb-bot/src/bot_data/bot-data.json index 64b57aa8..3e0dac07 100644 --- a/kdb-bot/src/bot_data/bot-data.json +++ b/kdb-bot/src/bot_data/bot-data.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_graphql/bot-graphql.json b/kdb-bot/src/bot_graphql/bot-graphql.json index 700d338e..4a9505a7 100644 --- a/kdb-bot/src/bot_graphql/bot-graphql.json +++ b/kdb-bot/src/bot_graphql/bot-graphql.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py b/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py index 0fa5318a..434856ee 100644 --- a/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py @@ -11,6 +11,7 @@ from bot_data.model.technician_config import TechnicianConfig from bot_data.model.technician_id_config import TechnicianIdConfig from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig from bot_data.model.user_role_enum import UserRoleEnum +from bot_data.service.technician_config_seeder import TechnicianConfigSeeder from bot_graphql.abc.query_abc import QueryABC @@ -23,6 +24,7 @@ class TechnicianConfigMutation(QueryABC): technician_configs: TechnicianConfigRepositoryABC, db: DatabaseContextABC, config_service: ConfigService, + tech_seeder: TechnicianConfigSeeder, ): QueryABC.__init__(self, "TechnicianConfigMutation") @@ -32,10 +34,14 @@ class TechnicianConfigMutation(QueryABC): self._technician_configs = technician_configs self._db = db self._config_service = config_service + self._tech_seeder = tech_seeder self.set_field("updateTechnicianConfig", self.resolve_update_technician_config) def resolve_update_technician_config(self, *_, input: dict): + if not self._technician_configs.does_technician_config_exists(): + self._bot.loop.create_task(self._tech_seeder.seed()) + technician_config = self._technician_configs.get_technician_config() self._can_user_mutate_data(Route.get_user().users[0].server, UserRoleEnum.technician) @@ -53,11 +59,16 @@ class TechnicianConfigMutation(QueryABC): technician_config.cache_max_messages = ( input["cacheMaxMessages"] if "cacheMaxMessages" in input else technician_config.cache_max_messages ) + old_feature_flags = technician_config.feature_flags technician_config.feature_flags = ( dict(zip([x["key"] for x in input["featureFlags"]], [x["value"] for x in input["featureFlags"]])) if "featureFlags" in input else technician_config.feature_flags ) + for old_flag in old_feature_flags: + if old_flag not in technician_config.feature_flags: + technician_config.feature_flags[old_flag] = False + technician_config.ping_urls = ( List(str, input["pingURLs"]) if "pingURLs" in input else technician_config.ping_urls ) @@ -75,6 +86,7 @@ class TechnicianConfigMutation(QueryABC): self._update_technician_ids(technician_config) self._db.save_changes() + self._config_service.reload_technician_config() return technician_config def _update_ping_urls(self, new_config: TechnicianConfig): @@ -109,5 +121,3 @@ class TechnicianConfigMutation(QueryABC): continue self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id)) - - self._bot.loop.create_task(self._config_service.reload_technician_config()) diff --git a/kdb-bot/src/modules/achievements/achievements.json b/kdb-bot/src/modules/achievements/achievements.json index 035ca7db..033548c6 100644 --- a/kdb-bot/src/modules/achievements/achievements.json +++ b/kdb-bot/src/modules/achievements/achievements.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/modules/auto_role/auto-role.json b/kdb-bot/src/modules/auto_role/auto-role.json index d3859286..2a78346e 100644 --- a/kdb-bot/src/modules/auto_role/auto-role.json +++ b/kdb-bot/src/modules/auto_role/auto-role.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/base/base.json b/kdb-bot/src/modules/base/base.json index eb7a6f61..e7f69ff0 100644 --- a/kdb-bot/src/modules/base/base.json +++ b/kdb-bot/src/modules/base/base.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/boot_log/boot-log.json b/kdb-bot/src/modules/boot_log/boot-log.json index ec83a0c1..444f31fd 100644 --- a/kdb-bot/src/modules/boot_log/boot-log.json +++ b/kdb-bot/src/modules/boot_log/boot-log.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/config/config.json b/kdb-bot/src/modules/config/config.json index deb2da01..5dcc1695 100644 --- a/kdb-bot/src/modules/config/config.json +++ b/kdb-bot/src/modules/config/config.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/config/config_extension.py b/kdb-bot/src/modules/config/config_extension.py index 810d2214..ce164180 100644 --- a/kdb-bot/src/modules/config/config_extension.py +++ b/kdb-bot/src/modules/config/config_extension.py @@ -19,4 +19,4 @@ class ConfigExtension(ApplicationExtensionABC): logger: LoggerABC = services.get_service(LoggerABC) logger.debug(__name__, "Config extension started") config: ConfigService = services.get_service(ConfigService) - await config.reload_technician_config() + config.reload_technician_config() diff --git a/kdb-bot/src/modules/database/database.json b/kdb-bot/src/modules/database/database.json index 387a3e0d..c82f9f24 100644 --- a/kdb-bot/src/modules/database/database.json +++ b/kdb-bot/src/modules/database/database.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/modules/level/level.json b/kdb-bot/src/modules/level/level.json index c3cb2e2c..01ca6ac4 100644 --- a/kdb-bot/src/modules/level/level.json +++ b/kdb-bot/src/modules/level/level.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/permission/permission.json b/kdb-bot/src/modules/permission/permission.json index 2af5b112..2ea792a8 100644 --- a/kdb-bot/src/modules/permission/permission.json +++ b/kdb-bot/src/modules/permission/permission.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/permission/service/permission_service.py b/kdb-bot/src/modules/permission/service/permission_service.py index 7ea356f9..9ac28c55 100644 --- a/kdb-bot/src/modules/permission/service/permission_service.py +++ b/kdb-bot/src/modules/permission/service/permission_service.py @@ -29,10 +29,11 @@ class PermissionService(PermissionServiceABC): self._technician_configs = technician_configs def _has_member_role(self, member: discord.Member, team_member_type: TeamMemberTypeEnum) -> bool: - self._logger.debug(__name__, f"Checking permissions for {member.name}") if member is None or member.guild is None: return False + self._logger.debug(__name__, f"Checking is member {member.name} {team_member_type.value}") + try: server = self._servers.get_server_by_discord_id(member.guild.id) config = self._server_configs.get_server_config_by_server(server.id) @@ -58,10 +59,11 @@ class PermissionService(PermissionServiceABC): ) def is_member_technician(self, member: discord.Member) -> bool: - self._logger.debug(__name__, f"Checking is member {member.name} technician") if member is None or member.guild is None: return False + self._logger.debug(__name__, f"Checking is member {member.name} technician") + try: tech_config = self._technician_configs.get_technician_config() if member.id in tech_config.technician_ids: diff --git a/kdb-bot/src/modules/technician/technician.json b/kdb-bot/src/modules/technician/technician.json index 25f1f961..7ae46664 100644 --- a/kdb-bot/src/modules/technician/technician.json +++ b/kdb-bot/src/modules/technician/technician.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/tools/checks/checks.json b/kdb-bot/tools/checks/checks.json index 55a30899..295f0a4b 100644 --- a/kdb-bot/tools/checks/checks.json +++ b/kdb-bot/tools/checks/checks.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/get_version/get-version.json b/kdb-bot/tools/get_version/get-version.json index 5b80daae..0c0aacb6 100644 --- a/kdb-bot/tools/get_version/get-version.json +++ b/kdb-bot/tools/get_version/get-version.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/post_build/post-build.json b/kdb-bot/tools/post_build/post-build.json index 1f101efc..f499bc71 100644 --- a/kdb-bot/tools/post_build/post-build.json +++ b/kdb-bot/tools/post_build/post-build.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/set_version/set-version.json b/kdb-bot/tools/set_version/set-version.json index 1908eae0..6ea92728 100644 --- a/kdb-bot/tools/set_version/set-version.json +++ b/kdb-bot/tools/set_version/set-version.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-web/package.json b/kdb-web/package.json index 1141d3da..1b99a94e 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.1.9", + "version": "1.1.10", "scripts": { "ng": "ng", "update-version": "ts-node update-version.ts", diff --git a/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts b/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts index 28769084..13b1b690 100644 --- a/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts +++ b/kdb-web/src/app/modules/shared/guards/auth/auth.guard.ts @@ -34,11 +34,11 @@ export class AuthGuard implements CanActivate { const role = route.data["role"]; const memberRole = route.data["memberRole"]; + const authUser = await this.authService.getLoggedInUser(); + const isTechnician = (authUser?.users?.map(u => u.isTechnician).filter(u => u) ?? []).length > 0; + if (role !== undefined) { 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; @@ -49,12 +49,15 @@ export class AuthGuard implements CanActivate { if (memberRole !== undefined) { let userHasAccess = false; - let authUser = await this.authService.getLoggedInUser(); let server = route.params["serverId"]; - if (!authUser || !authUser.users) { + if (this.sidebarService.hasFeature("TechnicianFullAccess") && isTechnician) { return true; } + + if (!authUser || !authUser.users) { + return false; + } authUser?.users?.forEach(u => { if (u.server === +(server ?? 0)) { if ( diff --git a/kdb-web/src/app/services/sidebar/sidebar.service.ts b/kdb-web/src/app/services/sidebar/sidebar.service.ts index 1965eb13..a416e57c 100644 --- a/kdb-web/src/app/services/sidebar/sidebar.service.ts +++ b/kdb-web/src/app/services/sidebar/sidebar.service.ts @@ -15,216 +15,218 @@ import { DataService } from "../data/data.service"; import { FeatureFlag } from "../../models/config/feature-flags.model"; @Injectable({ - providedIn: "root" + providedIn: "root" }) export class SidebarService { - isSidebarOpen: boolean = true; - menuItems$ = new BehaviorSubject(new Array()); - server!: Server | undefined; + isSidebarOpen: boolean = true; + menuItems$ = new BehaviorSubject(new Array()); + server!: Server | undefined; - dashboard: MenuItem = {}; - serverDashboard: MenuItem = {}; - serverProfile: MenuItem = {}; - serverMembers: MenuItem = {}; - serverAutoRoles: MenuItem = {}; - serverLevels: MenuItem = {}; - serverAchievements: MenuItem = {}; - serverShortRoleNames: MenuItem = {}; - serverConfig: MenuItem = {}; - serverMenu: MenuItem = {}; - adminConfig: MenuItem = {}; - adminUsers: MenuItem = {}; - adminMenu: MenuItem = {}; + dashboard: MenuItem = {}; + serverDashboard: MenuItem = {}; + serverProfile: MenuItem = {}; + serverMembers: MenuItem = {}; + serverAutoRoles: MenuItem = {}; + serverLevels: MenuItem = {}; + serverAchievements: MenuItem = {}; + serverShortRoleNames: MenuItem = {}; + serverConfig: MenuItem = {}; + serverMenu: MenuItem = {}; + adminConfig: MenuItem = {}; + adminUsers: MenuItem = {}; + adminMenu: MenuItem = {}; - featureFlags: FeatureFlag[] = []; + featureFlags: FeatureFlag[] = []; - constructor( - private themeService: ThemeService, - private authService: AuthService, - private translateService: TranslateService, - private router: Router, - private serverService: ServerService, - private data: DataService - ) { - this.themeService.isSidebarOpen$.subscribe(value => { - this.isSidebarOpen = value; - this.setMenu(true); + constructor( + private themeService: ThemeService, + private authService: AuthService, + private translateService: TranslateService, + private router: Router, + private serverService: ServerService, + private data: DataService + ) { + this.themeService.isSidebarOpen$.subscribe(value => { + this.isSidebarOpen = value; + 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("{possibleFeatureFlags}" + ).subscribe(data => { + let observables: Observable[] = []; + data.possibleFeatureFlags.forEach(flag => { + observables.push( + this.data.query(Queries.hasServerFeatureFlag, { + filter: { id: server.id }, + flag: flag + }, + function(data: Query) { + return data.servers[0]; + } + ) + ); }); - this.translateService.onLangChange.subscribe(_ => { - this.setMenu(true); - }); - - this.serverService.server$.subscribe(server => { - this.server = server; - if (server) { - this.setMenu(true); - } else { - this.setMenu(false); + forkJoin(observables).subscribe(data => { + data.forEach(flag => { + if (!flag.hasFeatureFlag.value) { + return; } + this.featureFlags.push(flag.hasFeatureFlag); + }); + this._setMenu(build); }); + }); + } else { + this._setMenu(build); } + } - 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` - }; + 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) ?? []).length > 0; + let isTechnicianAndFullAccessActive = this.hasFeature("TechnicianFullAccess") && isTechnician; + console.log(this.hasFeature("TechnicianFullAccess")) - 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` - }; + if (build || this.menuItems$.value.length == 0) { + await this.buildMenu(user, hasPermission, isTechnician); + } - this.serverLevels = { - label: this.isSidebarOpen ? this.translateService.instant("sidebar.server.levels") : "", - icon: "pi pi-book", - visible: true, - routerLink: `server/${this.server?.id}/levels` - }; + if (this.server) { + this.serverMenu.visible = true; + this.serverMembers.visible = isTechnicianAndFullAccessActive || user?.isModerator; + this.serverAutoRoles.visible = isTechnicianAndFullAccessActive || this.hasFeature("AutoRoleModule") && user?.isModerator; + this.serverLevels.visible = isTechnicianAndFullAccessActive || this.hasFeature("LevelModule") && user?.isModerator; + this.serverAchievements.visible = isTechnicianAndFullAccessActive || this.hasFeature("AchievementsModule") && user?.isModerator; + this.serverShortRoleNames.visible = isTechnicianAndFullAccessActive || this.hasFeature("ShortRoleName") && user?.isAdmin; - 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.serverConfig.visible = isTechnicianAndFullAccessActive || user?.isAdmin; + } else { + this.serverMenu.visible = false; + } - 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` - }; + let menuItems: MenuItem[] = [ + this.dashboard, + this.serverMenu, + this.adminMenu + ]; + this.menuItems$.next(menuItems); + }); + } - 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("{possibleFeatureFlags}" - ).subscribe(data => { - let observables: Observable[] = []; - data.possibleFeatureFlags.forEach(flag => { - observables.push( - this.data.query(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; + public hasFeature(key: string): boolean { + const flag = this.featureFlags.filter(flag => flag.key == key); + if (flag.length == 0) { + return false; } + return flag[0].value; + } } diff --git a/kdb-web/src/assets/version.json b/kdb-web/src/assets/version.json index 499614ab..f7826e37 100644 --- a/kdb-web/src/assets/version.json +++ b/kdb-web/src/assets/version.json @@ -2,6 +2,6 @@ "WebVersion": { "Major": "1", "Minor": "1", - "Micro": "9" + "Micro": "10" } }