diff --git a/bot/src/bot_graphql/graphql/query.gql b/bot/src/bot_graphql/graphql/query.gql index cf1f4223..655abe4d 100644 --- a/bot/src/bot_graphql/graphql/query.gql +++ b/bot/src/bot_graphql/graphql/query.gql @@ -52,4 +52,5 @@ type Query { discord: Discord hasFeatureFlag(flag: String): FeatureFlag + featureFlags: [FeatureFlag] } \ No newline at end of file diff --git a/bot/src/bot_graphql/graphql/server.gql b/bot/src/bot_graphql/graphql/server.gql index 4624ffca..63d07b3f 100644 --- a/bot/src/bot_graphql/graphql/server.gql +++ b/bot/src/bot_graphql/graphql/server.gql @@ -40,6 +40,7 @@ type Server implements TableWithHistoryQuery { config: ServerConfig hasFeatureFlag(flag: String): FeatureFlag + featureFlags: [FeatureFlag] statistic(date: String): ServerStatistic diff --git a/bot/src/bot_graphql/queries/server_query.py b/bot/src/bot_graphql/queries/server_query.py index 3760db07..eac863b9 100644 --- a/bot/src/bot_graphql/queries/server_query.py +++ b/bot/src/bot_graphql/queries/server_query.py @@ -116,6 +116,10 @@ class ServerQuery(DataQueryWithHistoryABC): "hasFeatureFlag", lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs), ) + self.set_field( + "featureFlags", + lambda server, *_, **kwargs: self._resolve_feature_flags(server, *_), + ) self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs)) @staticmethod @@ -142,3 +146,13 @@ class ServerQuery(DataQueryWithHistoryABC): "key": kwargs["flag"], "value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])), } + + def _resolve_feature_flags(self, server: Server, *_) -> list[dict]: + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}") + return [ + { + "key": flag, + "value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)), + } + for flag in [e.value for e in FeatureFlagsEnum] + ] diff --git a/bot/src/bot_graphql/query.py b/bot/src/bot_graphql/query.py index aa3f56b6..71223f91 100644 --- a/bot/src/bot_graphql/query.py +++ b/bot/src/bot_graphql/query.py @@ -131,6 +131,10 @@ class Query(QueryABC): "hasFeatureFlag", lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs), ) + self.set_field( + "featureFlags", + lambda *_, **kwargs: self._resolve_feature_flags(*_), + ) def _resolve_has_feature_flag(self, *_, **kwargs): settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig) @@ -140,3 +144,13 @@ class Query(QueryABC): "key": kwargs["flag"], "value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])), } + + def _resolve_feature_flags(self, *_) -> list[dict]: + settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig) + return [ + { + "key": flag, + "value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)), + } + for flag in [e.value for e in FeatureFlagsEnum] + ] diff --git a/web/src/app/models/graphql/queries.model.ts b/web/src/app/models/graphql/queries.model.ts index 402d9f09..aacf980d 100644 --- a/web/src/app/models/graphql/queries.model.ts +++ b/web/src/app/models/graphql/queries.model.ts @@ -128,6 +128,17 @@ export class Queries { } `; + static serverFeatureFlags = ` + query HasServerFeatureFlag($filter: ServerFilter) { + servers(filter: $filter) { + featureFlags { + key + value + } + } + } + `; + static gameServerQuery = ` query GameServersList($serverId: ID) { servers(filter: {id: $serverId}) { diff --git a/web/src/app/models/graphql/query.model.ts b/web/src/app/models/graphql/query.model.ts index b7da6553..d909cc28 100644 --- a/web/src/app/models/graphql/query.model.ts +++ b/web/src/app/models/graphql/query.model.ts @@ -1,7 +1,7 @@ import { GameServer, Server } from "../data/server.model"; import { User } from "../data/user.model"; import { AutoRole, AutoRoleRule } from "../data/auto_role.model"; -import { Discord, Guild } from "../data/discord.model"; +import { Discord } from "../data/discord.model"; import { Level } from "../data/level.model"; import { Achievement, AchievementAttribute } from "../data/achievement.model"; import { TechnicianConfig } from "../config/technician-config.model"; @@ -82,6 +82,10 @@ export interface HasServerFeatureFlagQuery { hasFeatureFlag: FeatureFlag; } +export interface FeatureFlagsQuery { + featureFlags: FeatureFlag[]; +} + export interface ShortRoleNameListQuery { shortRoleNameCount: number; shortRoleNames: ShortRoleName[]; diff --git a/web/src/app/services/sidebar/sidebar.service.ts b/web/src/app/services/sidebar/sidebar.service.ts index 14c55841..b5c887f6 100644 --- a/web/src/app/services/sidebar/sidebar.service.ts +++ b/web/src/app/services/sidebar/sidebar.service.ts @@ -1,6 +1,6 @@ import { Injectable } from "@angular/core"; import { MenuItem } from "primeng/api"; -import { BehaviorSubject, forkJoin, Observable } from "rxjs"; +import { BehaviorSubject } from "rxjs"; import { AuthRoles } from "../../models/auth/auth-roles.enum"; import { AuthService } from "../auth/auth.service"; import { TranslateService } from "@ngx-translate/core"; @@ -9,7 +9,7 @@ import { ThemeService } from "../theme/theme.service"; import { Server } from "../../models/data/server.model"; import { UserDTO } from "../../models/auth/auth-user.dto"; import { ServerService } from "../server.service"; -import { HasServerFeatureFlagQuery, PossibleFeatureFlagsQuery, Query } from "../../models/graphql/query.model"; +import { FeatureFlagsQuery, Query } from "../../models/graphql/query.model"; import { Queries } from "../../models/graphql/queries.model"; import { DataService } from "../data/data.service"; import { FeatureFlag } from "../../models/config/feature-flags.model"; @@ -165,31 +165,15 @@ export class SidebarService { 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); - }); + this.data.query(Queries.serverFeatureFlags, { + filter: { id: server.id } + }, + function(data: Query) { + return data.servers[0]; + }).subscribe(data => { + this.featureFlags = data.featureFlags; + this._setMenu(build); }); } else { this._setMenu(build);