web/user: load interface settings from user settings

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-09 15:52:36 +02:00
parent b33ea9cc61
commit 3ee5a672f1
3 changed files with 37 additions and 15 deletions

View file

@ -33,7 +33,7 @@ import "../elements/sidebar/Sidebar";
import { DefaultTenant } from "../elements/sidebar/SidebarBrand"; import { DefaultTenant } from "../elements/sidebar/SidebarBrand";
import "../elements/sidebar/SidebarItem"; import "../elements/sidebar/SidebarItem";
import { ROUTES } from "../routesUser"; import { ROUTES } from "../routesUser";
import { uiConfig } from "../user/config"; import { uiConfig, UserDisplay } from "../user/config";
import { first } from "../utils"; import { first } from "../utils";
import "./locale"; import "./locale";
@ -235,11 +235,11 @@ export class UserInterface extends LitElement {
${until( ${until(
me().then((me) => { me().then((me) => {
switch (config.navbar.userDisplay) { switch (config.navbar.userDisplay) {
case "username": case UserDisplay.username:
return me.user.username; return me.user.username;
case "name": case UserDisplay.name:
return me.user.name; return me.user.name;
case "email": case UserDisplay.email:
return me.user.email; return me.user.email;
default: default:
return me.user.username; return me.user.username;

View file

@ -7,6 +7,7 @@ import { ifDefined } from "lit/directives/if-defined";
import { Prompt, PromptTypeEnum, StagesApi } from "@goauthentik/api"; import { Prompt, PromptTypeEnum, StagesApi } from "@goauthentik/api";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import "../../../elements/CodeMirror";
import "../../../elements/forms/HorizontalFormElement"; import "../../../elements/forms/HorizontalFormElement";
import { ModelForm } from "../../../elements/forms/ModelForm"; import { ModelForm } from "../../../elements/forms/ModelForm";
import { first } from "../../../utils"; import { first } from "../../../utils";

View file

@ -1,3 +1,11 @@
import { me } from "../api/Users";
export enum UserDisplay {
"username",
"name",
"email",
}
export interface UIConfig { export interface UIConfig {
enabledFeatures: { enabledFeatures: {
// API Request drawer in navbar // API Request drawer in navbar
@ -12,7 +20,7 @@ export interface UIConfig {
search: boolean; search: boolean;
}; };
navbar: { navbar: {
userDisplay: "username" | "name" | "email"; userDisplay: UserDisplay;
}; };
color: { color: {
background: string; background: string;
@ -20,23 +28,36 @@ export interface UIConfig {
}; };
} }
export const DefaultUIConfig: UIConfig = { export class DefaultUIConfig implements UIConfig {
enabledFeatures: { enabledFeatures = {
apiDrawer: true, apiDrawer: true,
notificationDrawer: true, notificationDrawer: true,
settings: true, settings: true,
applicationEdit: true, applicationEdit: true,
search: true, search: true,
}, };
navbar: { navbar = {
userDisplay: "name", userDisplay: UserDisplay.username,
}, };
color: { color = {
background: "", background: "",
cardBackground: "", cardBackground: "",
}, };
}; }
export function parseConfig(raw: string): UIConfig {
const c = JSON.parse(raw);
return Object.assign(new DefaultUIConfig(), c);
}
export function uiConfig(): Promise<UIConfig> { export function uiConfig(): Promise<UIConfig> {
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;
});
} }