web: detangle element to admin references (#6864)
* Web: Detangling some circular dependencies in Admin and User Admin, User, and Flow should not dependend upon each other, at least not in a circular way. If Admin and User depend on Flow, that's fine, but Flow should not correspondingly depend upon elements of either; if they have something in common, let's put them in `@goauthentik/common` or find some other smart place to store them. This commit refactors the intentToLabel and actionToLabel functions into `@goauthentik/common/labels` and converts them to static tables for maintenance purposes. * web: "Consistency is the hobgoblin of small minds" - Ralph Waldo Emerson * web: I found these confusing to look at, so I added comments. * web: remove admin-to-user component reference(s) There was only one: AppIcon. This has been moved to `components`. Touching the LibraryApplications page triggered a cyclomatic complexity check. Extracting the expansion block and streamlining the class and style declarations with lit directives helped. * web: remove admin from elements This commit removes the two references from `elements` to `admin`: the list of UserEvents and a reference to the FlowSearch type, used by the Forms manager to decide how to extract a value. For FlowSearch, a different convention for detecting the type was implemented (instances of the object have a unique fieldname for the value holder). UserEvents and ObjectChangelog have been moved to `components` as they're clearly dependent upon the API. This defers work on removing Admin from Components, as that is (again) references going the wrong way, but that can happen later. * web: remove admin-to-user component reference(s) (#6856) There was only one: AppIcon. This has been moved to `components`. Touching the LibraryApplications page triggered a cyclomatic complexity check. Extracting the expansion block and streamlining the class and style declarations with lit directives helped. * This was supposed to be merged.
This commit is contained in:
106
web/src/components/events/ObjectChangelog.ts
Normal file
106
web/src/components/events/ObjectChangelog.ts
Normal file
@ -0,0 +1,106 @@
|
||||
import "@goauthentik/admin/events/EventInfo";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { EventWithContext } from "@goauthentik/common/events";
|
||||
import { uiConfig } from "@goauthentik/common/ui/config";
|
||||
import "@goauthentik/elements/Tabs";
|
||||
import "@goauthentik/elements/buttons/Dropdown";
|
||||
import "@goauthentik/elements/buttons/ModalButton";
|
||||
import "@goauthentik/elements/buttons/SpinnerButton";
|
||||
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
||||
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
|
||||
|
||||
import { msg, str } from "@lit/localize";
|
||||
import { TemplateResult, html } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
|
||||
import { Event, EventsApi } from "@goauthentik/api";
|
||||
|
||||
@customElement("ak-object-changelog")
|
||||
export class ObjectChangelog extends Table<Event> {
|
||||
expandable = true;
|
||||
|
||||
@property()
|
||||
order = "-created";
|
||||
|
||||
@property()
|
||||
targetModelPk!: string | number;
|
||||
|
||||
@property()
|
||||
targetModelApp?: string;
|
||||
|
||||
private _targetModelName = "";
|
||||
|
||||
@property()
|
||||
set targetModelName(value: string) {
|
||||
this._targetModelName = value;
|
||||
this.fetch();
|
||||
}
|
||||
|
||||
get targetModelName(): string {
|
||||
return this._targetModelName;
|
||||
}
|
||||
|
||||
async apiEndpoint(page: number): Promise<PaginatedResponse<Event>> {
|
||||
let modelName = this._targetModelName;
|
||||
let appName = this.targetModelApp;
|
||||
if (this._targetModelName.indexOf(".") !== -1) {
|
||||
const parts = this._targetModelName.split(".");
|
||||
appName = parts[0];
|
||||
modelName = parts[1];
|
||||
}
|
||||
if (this._targetModelName === "") {
|
||||
return Promise.reject();
|
||||
}
|
||||
return new EventsApi(DEFAULT_CONFIG).eventsEventsList({
|
||||
action: "model_",
|
||||
page: page,
|
||||
ordering: this.order,
|
||||
pageSize: (await uiConfig()).pagination.perPage,
|
||||
contextModelApp: appName,
|
||||
contextModelName: modelName,
|
||||
contextModelPk: this.targetModelPk.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
columns(): TableColumn[] {
|
||||
return [
|
||||
new TableColumn(msg("Action"), "action"),
|
||||
new TableColumn(msg("User"), "enabled"),
|
||||
new TableColumn(msg("Creation Date"), "created"),
|
||||
new TableColumn(msg("Client IP"), "client_ip"),
|
||||
];
|
||||
}
|
||||
|
||||
row(item: EventWithContext): TemplateResult[] {
|
||||
return [
|
||||
html`${item.action}`,
|
||||
html`<div>${item.user?.username}</div>
|
||||
${item.user.on_behalf_of
|
||||
? html`<small>
|
||||
${msg(str`On behalf of ${item.user.on_behalf_of.username}`)}
|
||||
</small>`
|
||||
: html``}`,
|
||||
html`<span>${item.created?.toLocaleString()}</span>`,
|
||||
html`<span>${item.clientIp || msg("-")}</span>`,
|
||||
];
|
||||
}
|
||||
|
||||
renderExpanded(item: Event): TemplateResult {
|
||||
return html` <td role="cell" colspan="4">
|
||||
<div class="pf-c-table__expandable-row-content">
|
||||
<ak-event-info .event=${item as EventWithContext}></ak-event-info>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>`;
|
||||
}
|
||||
|
||||
renderEmpty(): TemplateResult {
|
||||
return super.renderEmpty(
|
||||
html`<ak-empty-state header=${msg("No Events found.")}>
|
||||
<div slot="body">${msg("No matching events could be found.")}</div>
|
||||
</ak-empty-state>`,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user