Skip to content

Commit

Permalink
feat(settings): add feature flags to hide modes if disabled (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoronex authored Nov 17, 2024
2 parents 493c890 + 2c58376 commit 1ce1740
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/components/shortcuts/ShortcutBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ import { type IShortcutItem } from '@/components/shortcuts/IShortcutItem';
import AppContainer from '@/layout/AppContainer.vue';
import { disableAllModes } from '@/api';
import { useAuthStore } from '@/stores/auth.store';
import { useServerSettingsStore } from '@/stores/server-settings.store';
const handlersStore = useHandlersStore();
const subscriberStore = useSubscriberStore();
const sceneStore = useSceneControllerStore();
const authStore = useAuthStore();
const settingsStore = useServerSettingsStore();
const centurionModeStore = useCenturionStore();
if (authStore.isInSecurityGroup('centurion', 'privileged')) {
Expand Down Expand Up @@ -141,9 +143,11 @@ const lights = computed<IShortcutItem[] | boolean>(() => {
// Add items based on the user's security groups
const modes = computed<IShortcutItem[] | boolean>(() => {
const showModes = authStore.isInSecurityGroup('mode', 'base');
const showCenturion = authStore.isInSecurityGroup('centurion', 'privileged');
const showTimeTrail = authStore.isInSecurityGroup('timetrail', 'base');
const showCenturion =
authStore.isInSecurityGroup('centurion', 'privileged') && settingsStore.featureEnabled('Centurion');
const showTimeTrail =
authStore.isInSecurityGroup('timetrail', 'base') && settingsStore.featureEnabled('TimeTrailRace');
const showModes = authStore.isInSecurityGroup('mode', 'base') && (showCenturion || showTimeTrail);
if (!(showModes || showCenturion || showTimeTrail)) {
return false;
Expand Down Expand Up @@ -182,7 +186,7 @@ const modes = computed<IShortcutItem[] | boolean>(() => {
enabledIcon: timeTrailRaceModeStore.enabled,
disabledIcon: timeTrailRaceModeStore.disabled,
},
],
].filter(Boolean),
},
].filter(Boolean) as IShortcutItem[];
});
Expand Down
8 changes: 6 additions & 2 deletions src/layout/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import { computed } from 'vue';
import AppMenuItem, { type MenuItem } from './AppMenuItem.vue';
import { useAuthStore } from '@/stores/auth.store';
import { useServerSettingsStore } from '@/stores/server-settings.store';
const authStore = useAuthStore();
const settingsStore = useServerSettingsStore();
// Calculate all items in the menu based on the user's security groups
const model = computed<MenuItem[]>(() => {
const showPosters = authStore.isInSecurityGroup('poster', 'base');
const showAudit = authStore.isInSecurityGroup('audit', 'base');
const showCenturion = authStore.isInSecurityGroup('centurion', 'privileged');
const showTimeTrail = authStore.isInSecurityGroup('timetrail', 'base');
const showCenturion =
authStore.isInSecurityGroup('centurion', 'privileged') && settingsStore.featureEnabled('Centurion');
const showTimeTrail =
authStore.isInSecurityGroup('timetrail', 'base') && settingsStore.featureEnabled('TimeTrailRace');
const showEffects = authStore.isInSecurityGroup('effects', 'base');
const showScenes = authStore.isInSecurityGroup('scenes', 'base');
Expand Down
5 changes: 4 additions & 1 deletion src/stores/auth.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ export const useAuthStore = defineStore('auth', {
* Initialize the stores -- only those which the user has access to
*/
async initStores(): Promise<void> {
await useServerSettingsStore().initFeatureFlags();
await useSocketStore().connect();
await useServerSettingsStore().init();
if (this.isInSecurityGroup('serverSettings', 'privileged')) {
await useServerSettingsStore().initSettings();
}
if (this.isInSecurityGroup('handler', 'base')) {
await useHandlersStore().init();
}
Expand Down
16 changes: 9 additions & 7 deletions src/stores/server-settings.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export const useServerSettingsStore = defineStore('server-settings', {
loading: true,
}),
actions: {
async init(): Promise<void> {
await getSettings().then((res) => {
if (res && res.data) this.serverSettings = res.data;
});
await getFeatureFlags().then((res) => {
if (res && res.data) this.featureFlags = res.data;
});
async initFeatureFlags(): Promise<void> {
const res = await getFeatureFlags();
if (res && res.data) this.featureFlags = res.data;
this.loading = false;
},
async initSettings(): Promise<void> {
this.loading = true;
const res = await getSettings();
if (res && res.data) this.serverSettings = res.data;
this.loading = false;
},
isFeatureFlag(setting: string | keyof ISettings): boolean {
Expand Down

0 comments on commit 1ce1740

Please sign in to comment.