* rename consent permission Signed-off-by: Jens Langhammer <jens@goauthentik.io> * the user version Signed-off-by: Jens Langhammer <jens@goauthentik.io> t Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial role Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start form Signed-off-by: Jens Langhammer <jens@goauthentik.io> * some minor table refactoring Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix user, add assign Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add roles ui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix backend Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add assign API for roles Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start adding toggle buttons Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start view page Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude add_ permission for per-object perms Signed-off-by: Jens Langhammer <jens@goauthentik.io> * small cleanup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add permission list for roles Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make sidebar update Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix page header not re-rendering? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fixup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add search Signed-off-by: Jens Langhammer <jens@goauthentik.io> * show first category in table groupBy except when its empty Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make model and object PK optional but required together Signed-off-by: Jens Langhammer <jens@goauthentik.io> * allow for setting global perms Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude non-authentik permissions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude models which aren't allowed (base models etc) Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ensure all models have verbose_name set, exclude some more internal objects Signed-off-by: Jens Langhammer <jens@goauthentik.io> * lint fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix role perm assign Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add unasign for global perms Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add meta changes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * clear modal state after submit Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add roles to our group Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix duplicate url names Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make recursive group query more usable Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add name field to role itself and move group creation to signal Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start sync Signed-off-by: Jens Langhammer <jens@goauthentik.io> * move rbac stuff to separate django app Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint and such Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix go Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start API changes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add more API tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make admin interface not require superuser for now, improve error handling Signed-off-by: Jens Langhammer <jens@goauthentik.io> * replace some IsAdminUser where applicable Signed-off-by: Jens Langhammer <jens@goauthentik.io> * migrate flow inspector perms to actual permission Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix license not being a serializermodel Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add permission modal to models without view page Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add additional permissions to assign/unassign permissions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add action to unassign user permissions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add permissions tab to remaining view pages Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix flow inspector permission check Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix codecov config? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add more API tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ensure viewsets have an order set Signed-off-by: Jens Langhammer <jens@goauthentik.io> * hopefully the last api name change Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make perm modal less confusing Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start user view permission page Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only make delete bulk form expandable if usedBy is set Signed-off-by: Jens Langhammer <jens@goauthentik.io> * expand permission tables Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add more things Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add user global permission table Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests' url names Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add tests for assign perms Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add unassign tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rebuild permissions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * prevent assigning/unassigning permissions to internal service accounts Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only enable default api browser in debug Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix role object permissions showing duplicate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix role link on role object permissions table Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix object permission modal having duplicate close buttons Signed-off-by: Jens Langhammer <jens@goauthentik.io> * return error if user has no global perm and no object perms also improve error display on table Signed-off-by: Jens Langhammer <jens@goauthentik.io> * small optimisation Signed-off-by: Jens Langhammer <jens@goauthentik.io> * optimise even more Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update locale Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add system permission for non-object permissions Signed-off-by: Jens Langhammer <jens@goauthentik.io> * allow access to admin interface based on perm Signed-off-by: Jens Langhammer <jens@goauthentik.io> * clean Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't exclude base models Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
297 lines
12 KiB
TypeScript
297 lines
12 KiB
TypeScript
import { ROUTES } from "@goauthentik/admin/Routes";
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
|
import {
|
|
EVENT_API_DRAWER_TOGGLE,
|
|
EVENT_NOTIFICATION_DRAWER_TOGGLE,
|
|
EVENT_SIDEBAR_TOGGLE,
|
|
VERSION,
|
|
} from "@goauthentik/common/constants";
|
|
import { configureSentry } from "@goauthentik/common/sentry";
|
|
import { me } from "@goauthentik/common/users";
|
|
import { WebsocketClient } from "@goauthentik/common/ws";
|
|
import { Interface } from "@goauthentik/elements/Base";
|
|
import "@goauthentik/elements/ak-locale-context";
|
|
import "@goauthentik/elements/enterprise/EnterpriseStatusBanner";
|
|
import "@goauthentik/elements/messages/MessageContainer";
|
|
import "@goauthentik/elements/messages/MessageContainer";
|
|
import "@goauthentik/elements/notifications/APIDrawer";
|
|
import "@goauthentik/elements/notifications/NotificationDrawer";
|
|
import { ID_REGEX, SLUG_REGEX, UUID_REGEX } from "@goauthentik/elements/router/Route";
|
|
import { getURLParam, updateURLParams } from "@goauthentik/elements/router/RouteMatch";
|
|
import "@goauthentik/elements/router/RouterOutlet";
|
|
import "@goauthentik/elements/sidebar/Sidebar";
|
|
import "@goauthentik/elements/sidebar/SidebarItem";
|
|
import { spread } from "@open-wc/lit-helpers";
|
|
|
|
import { msg, str } from "@lit/localize";
|
|
import { CSSResult, TemplateResult, css, html, nothing } from "lit";
|
|
import { customElement, property, state } from "lit/decorators.js";
|
|
import { map } from "lit/directives/map.js";
|
|
|
|
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
|
import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css";
|
|
import PFPage from "@patternfly/patternfly/components/Page/page.css";
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
|
|
import {
|
|
AdminApi,
|
|
CapabilitiesEnum,
|
|
CoreApi,
|
|
SessionUser,
|
|
UiThemeEnum,
|
|
Version,
|
|
} from "@goauthentik/api";
|
|
|
|
@customElement("ak-interface-admin")
|
|
export class AdminInterface extends Interface {
|
|
@property({ type: Boolean })
|
|
sidebarOpen = true;
|
|
|
|
@property({ type: Boolean })
|
|
notificationDrawerOpen = getURLParam("notificationDrawerOpen", false);
|
|
|
|
@property({ type: Boolean })
|
|
apiDrawerOpen = getURLParam("apiDrawerOpen", false);
|
|
|
|
ws: WebsocketClient;
|
|
|
|
@state()
|
|
version?: Version;
|
|
|
|
@state()
|
|
user?: SessionUser;
|
|
|
|
static get styles(): CSSResult[] {
|
|
return [
|
|
PFBase,
|
|
PFPage,
|
|
PFButton,
|
|
PFDrawer,
|
|
css`
|
|
.pf-c-page__main,
|
|
.pf-c-drawer__content,
|
|
.pf-c-page__drawer {
|
|
z-index: auto !important;
|
|
background-color: transparent;
|
|
}
|
|
.display-none {
|
|
display: none;
|
|
}
|
|
.pf-c-page {
|
|
background-color: var(--pf-c-page--BackgroundColor) !important;
|
|
}
|
|
/* Global page background colour */
|
|
:host([theme="dark"]) .pf-c-page {
|
|
--pf-c-page--BackgroundColor: var(--ak-dark-background);
|
|
}
|
|
`,
|
|
];
|
|
}
|
|
|
|
constructor() {
|
|
super();
|
|
this.ws = new WebsocketClient();
|
|
this.sidebarOpen = window.innerWidth >= 1280;
|
|
window.addEventListener("resize", () => {
|
|
this.sidebarOpen = window.innerWidth >= 1280;
|
|
});
|
|
window.addEventListener(EVENT_SIDEBAR_TOGGLE, () => {
|
|
this.sidebarOpen = !this.sidebarOpen;
|
|
});
|
|
window.addEventListener(EVENT_NOTIFICATION_DRAWER_TOGGLE, () => {
|
|
this.notificationDrawerOpen = !this.notificationDrawerOpen;
|
|
updateURLParams({
|
|
notificationDrawerOpen: this.notificationDrawerOpen,
|
|
});
|
|
});
|
|
window.addEventListener(EVENT_API_DRAWER_TOGGLE, () => {
|
|
this.apiDrawerOpen = !this.apiDrawerOpen;
|
|
updateURLParams({
|
|
apiDrawerOpen: this.apiDrawerOpen,
|
|
});
|
|
});
|
|
}
|
|
|
|
async firstUpdated(): Promise<void> {
|
|
configureSentry(true);
|
|
this.version = await new AdminApi(DEFAULT_CONFIG).adminVersionRetrieve();
|
|
this.user = await me();
|
|
const canAccessAdmin =
|
|
this.user.user.isSuperuser ||
|
|
// TODO: somehow add `access_admin_interface` to the API schema
|
|
this.user.user.systemPermissions.includes("access_admin_interface");
|
|
if (!canAccessAdmin && this.user.user.pk > 0) {
|
|
window.location.assign("/if/user");
|
|
}
|
|
}
|
|
|
|
render(): TemplateResult {
|
|
return html` <ak-locale-context>
|
|
<div class="pf-c-page">
|
|
<ak-sidebar
|
|
class="pf-c-page__sidebar ${this.sidebarOpen
|
|
? "pf-m-expanded"
|
|
: "pf-m-collapsed"} ${this.activeTheme === UiThemeEnum.Light
|
|
? "pf-m-light"
|
|
: ""}"
|
|
>
|
|
${this.renderSidebarItems()}
|
|
</ak-sidebar>
|
|
<div class="pf-c-page__drawer">
|
|
<div
|
|
class="pf-c-drawer ${this.notificationDrawerOpen || this.apiDrawerOpen
|
|
? "pf-m-expanded"
|
|
: "pf-m-collapsed"}"
|
|
>
|
|
<div class="pf-c-drawer__main">
|
|
<div class="pf-c-drawer__content">
|
|
<div class="pf-c-drawer__body">
|
|
<main class="pf-c-page__main">
|
|
<ak-router-outlet
|
|
role="main"
|
|
class="pf-c-page__main"
|
|
tabindex="-1"
|
|
id="main-content"
|
|
defaultUrl="/administration/overview"
|
|
.routes=${ROUTES}
|
|
>
|
|
</ak-router-outlet>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
<ak-notification-drawer
|
|
class="pf-c-drawer__panel pf-m-width-33 ${this
|
|
.notificationDrawerOpen
|
|
? ""
|
|
: "display-none"}"
|
|
?hidden=${!this.notificationDrawerOpen}
|
|
></ak-notification-drawer>
|
|
<ak-api-drawer
|
|
class="pf-c-drawer__panel pf-m-width-33 ${this.apiDrawerOpen
|
|
? ""
|
|
: "display-none"}"
|
|
?hidden=${!this.apiDrawerOpen}
|
|
></ak-api-drawer>
|
|
</div>
|
|
</div>
|
|
</div></div
|
|
></ak-locale-context>`;
|
|
}
|
|
|
|
renderSidebarItems(): TemplateResult {
|
|
// The second attribute type is of string[] to help with the 'activeWhen' control, which was
|
|
// commonplace and singular enough to merit its own handler.
|
|
type SidebarEntry = [
|
|
path: string | null,
|
|
label: string,
|
|
attributes?: Record<string, any> | string[] | null, // eslint-disable-line
|
|
children?: SidebarEntry[],
|
|
];
|
|
|
|
// prettier-ignore
|
|
const sidebarContent: SidebarEntry[] = [
|
|
["/if/user/", msg("User interface"), { "?isAbsoluteLink": true, "?highlight": true }],
|
|
[null, msg("Dashboards"), { "?expanded": true }, [
|
|
["/administration/overview", msg("Overview")],
|
|
["/administration/dashboard/users", msg("Users")],
|
|
["/administration/system-tasks", msg("System Tasks")]]],
|
|
[null, msg("Applications"), null, [
|
|
["/core/providers", msg("Providers"), [`^/core/providers/(?<id>${ID_REGEX})$`]],
|
|
["/core/applications", msg("Applications"), [`^/core/applications/(?<slug>${SLUG_REGEX})$`]],
|
|
["/outpost/outposts", msg("Outposts")]]],
|
|
[null, msg("Events"), null, [
|
|
["/events/log", msg("Logs"), [`^/events/log/(?<id>${UUID_REGEX})$`]],
|
|
["/events/rules", msg("Notification Rules")],
|
|
["/events/transports", msg("Notification Transports")]]],
|
|
[null, msg("Customisation"), null, [
|
|
["/policy/policies", msg("Policies")],
|
|
["/core/property-mappings", msg("Property Mappings")],
|
|
["/blueprints/instances", msg("Blueprints")],
|
|
["/policy/reputation", msg("Reputation scores")]]],
|
|
[null, msg("Flows and Stages"), null, [
|
|
["/flow/flows", msg("Flows"), [`^/flow/flows/(?<slug>${SLUG_REGEX})$`]],
|
|
["/flow/stages", msg("Stages")],
|
|
["/flow/stages/prompts", msg("Prompts")]]],
|
|
[null, msg("Directory"), null, [
|
|
["/identity/users", msg("Users"), [`^/identity/users/(?<id>${ID_REGEX})$`]],
|
|
["/identity/groups", msg("Groups"), [`^/identity/groups/(?<id>${UUID_REGEX})$`]],
|
|
["/identity/roles", msg("Roles"), [`^/identity/roles/(?<id>${UUID_REGEX})$`]],
|
|
["/core/sources", msg("Federation and Social login"), [`^/core/sources/(?<slug>${SLUG_REGEX})$`]],
|
|
["/core/tokens", msg("Tokens and App passwords")],
|
|
["/flow/stages/invitations", msg("Invitations")]]],
|
|
[null, msg("System"), null, [
|
|
["/core/tenants", msg("Tenants")],
|
|
["/crypto/certificates", msg("Certificates")],
|
|
["/outpost/integrations", msg("Outpost Integrations")]]]
|
|
];
|
|
|
|
// Typescript requires the type here to correctly type the recursive path
|
|
type SidebarRenderer = (_: SidebarEntry) => TemplateResult;
|
|
|
|
const renderOneSidebarItem: SidebarRenderer = ([path, label, attributes, children]) => {
|
|
const properties = Array.isArray(attributes)
|
|
? { ".activeWhen": attributes }
|
|
: attributes ?? {};
|
|
if (path) {
|
|
properties["path"] = path;
|
|
}
|
|
return html`<ak-sidebar-item ${spread(properties)}>
|
|
${label ? html`<span slot="label">${label}</span>` : nothing}
|
|
${map(children, renderOneSidebarItem)}
|
|
</ak-sidebar-item>`;
|
|
};
|
|
|
|
// prettier-ignore
|
|
return html`
|
|
${this.renderNewVersionMessage()}
|
|
${this.renderImpersonationMessage()}
|
|
${map(sidebarContent, renderOneSidebarItem)}
|
|
${this.renderEnterpriseMessage()}
|
|
`;
|
|
}
|
|
|
|
renderNewVersionMessage() {
|
|
return this.version && this.version.versionCurrent !== VERSION
|
|
? html`
|
|
<ak-sidebar-item ?highlight=${true}>
|
|
<span slot="label"
|
|
>${msg("A newer version of the frontend is available.")}</span
|
|
>
|
|
</ak-sidebar-item>
|
|
`
|
|
: nothing;
|
|
}
|
|
|
|
renderImpersonationMessage() {
|
|
return this.user?.original
|
|
? html`<ak-sidebar-item
|
|
?highlight=${true}
|
|
@click=${() => {
|
|
new CoreApi(DEFAULT_CONFIG).coreUsersImpersonateEndRetrieve().then(() => {
|
|
window.location.reload();
|
|
});
|
|
}}
|
|
>
|
|
<span slot="label"
|
|
>${msg(
|
|
str`You're currently impersonating ${this.user.user.username}. Click to stop.`,
|
|
)}</span
|
|
>
|
|
</ak-sidebar-item>`
|
|
: nothing;
|
|
}
|
|
|
|
renderEnterpriseMessage() {
|
|
return this.config?.capabilities.includes(CapabilitiesEnum.IsEnterprise)
|
|
? html`
|
|
<ak-sidebar-item>
|
|
<span slot="label">${msg("Enterprise")}</span>
|
|
<ak-sidebar-item path="/enterprise/licenses">
|
|
<span slot="label">${msg("Licenses")}</span>
|
|
</ak-sidebar-item>
|
|
</ak-sidebar-item>
|
|
`
|
|
: nothing;
|
|
}
|
|
}
|