diff --git a/web/src/interfaces/UserInterface.ts b/web/src/interfaces/UserInterface.ts index ac1bb3261..df8282d21 100644 --- a/web/src/interfaces/UserInterface.ts +++ b/web/src/interfaces/UserInterface.ts @@ -33,7 +33,7 @@ import "../elements/sidebar/Sidebar"; import { DefaultTenant } from "../elements/sidebar/SidebarBrand"; import "../elements/sidebar/SidebarItem"; import { ROUTES } from "../routesUser"; -import { uiConfig } from "../user/config"; +import { uiConfig, UserDisplay } from "../user/config"; import { first } from "../utils"; import "./locale"; @@ -235,11 +235,11 @@ export class UserInterface extends LitElement { ${until( me().then((me) => { switch (config.navbar.userDisplay) { - case "username": + case UserDisplay.username: return me.user.username; - case "name": + case UserDisplay.name: return me.user.name; - case "email": + case UserDisplay.email: return me.user.email; default: return me.user.username; diff --git a/web/src/pages/stages/prompt/PromptForm.ts b/web/src/pages/stages/prompt/PromptForm.ts index 55387ada0..917737b83 100644 --- a/web/src/pages/stages/prompt/PromptForm.ts +++ b/web/src/pages/stages/prompt/PromptForm.ts @@ -7,6 +7,7 @@ import { ifDefined } from "lit/directives/if-defined"; import { Prompt, PromptTypeEnum, StagesApi } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; +import "../../../elements/CodeMirror"; import "../../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../../elements/forms/ModelForm"; import { first } from "../../../utils"; diff --git a/web/src/user/config.ts b/web/src/user/config.ts index 66e7838c9..482ca13bf 100644 --- a/web/src/user/config.ts +++ b/web/src/user/config.ts @@ -1,3 +1,11 @@ +import { me } from "../api/Users"; + +export enum UserDisplay { + "username", + "name", + "email", +} + export interface UIConfig { enabledFeatures: { // API Request drawer in navbar @@ -12,7 +20,7 @@ export interface UIConfig { search: boolean; }; navbar: { - userDisplay: "username" | "name" | "email"; + userDisplay: UserDisplay; }; color: { background: string; @@ -20,23 +28,36 @@ export interface UIConfig { }; } -export const DefaultUIConfig: UIConfig = { - enabledFeatures: { +export class DefaultUIConfig implements UIConfig { + enabledFeatures = { apiDrawer: true, notificationDrawer: true, settings: true, applicationEdit: true, search: true, - }, - navbar: { - userDisplay: "name", - }, - color: { + }; + navbar = { + userDisplay: UserDisplay.username, + }; + color = { background: "", cardBackground: "", - }, -}; + }; +} + +export function parseConfig(raw: string): UIConfig { + const c = JSON.parse(raw); + return Object.assign(new DefaultUIConfig(), c); +} export function uiConfig(): Promise { - return Promise.resolve(DefaultUIConfig); + return me().then((user) => { + const settings = user.user.settings; + let config = new DefaultUIConfig(); + if ("userInterface" in settings) { + config = parseConfig(settings.userInterface); + } + console.debug(JSON.stringify(config)); + return config; + }); }