This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/common/config.ts
Jens Langhammer e38d03b304 web/user: make more themable
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2022-04-05 23:47:15 +02:00

90 lines
1.9 KiB
TypeScript

import { UserSelf } from "@goauthentik/api";
import { me } from "../api/Users";
export enum UserDisplay {
username = "username",
name = "name",
email = "email",
}
export enum LayoutType {
row = "row",
column_2 = "2-column",
column_3 = "3-column",
}
export interface UIConfig {
enabledFeatures: {
// API Request drawer in navbar
apiDrawer: boolean;
// Notification drawer in navbar
notificationDrawer: boolean;
// Settings in user dropdown
settings: boolean;
// Application edit in library (only shown when user is superuser)
applicationEdit: boolean;
// Search bar
search: boolean;
};
navbar: {
userDisplay: UserDisplay;
};
theme: {
background: string;
cardBackground: string;
};
pagination: {
perPage: number;
};
layout: {
type: LayoutType;
};
locale: string;
}
export class DefaultUIConfig implements UIConfig {
enabledFeatures = {
apiDrawer: true,
notificationDrawer: true,
settings: true,
applicationEdit: true,
search: true,
};
layout = {
type: LayoutType.row,
};
navbar = {
userDisplay: UserDisplay.username,
};
theme = {
background: "",
cardBackground: "",
};
pagination = {
perPage: 20,
};
locale = "";
}
let globalUiConfig: Promise<UIConfig>;
export function getConfigForUser(user: UserSelf): UIConfig {
const settings = user.settings;
let config = new DefaultUIConfig();
if (!settings) {
return config;
}
config = Object.assign(new DefaultUIConfig(), settings);
return config;
}
export function uiConfig(): Promise<UIConfig> {
if (!globalUiConfig) {
globalUiConfig = me().then((user) => {
return getConfigForUser(user.user);
});
}
return globalUiConfig;
}