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 "../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;

View File

@ -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";

View File

@ -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<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;
});
}