web/admin: add UserTokenForm
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
64fa04306c
commit
c0cfd75a2e
|
@ -18,8 +18,8 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import { until } from "lit-html/directives/until";
|
import { until } from "lit-html/directives/until";
|
||||||
import { ifDefined } from "lit-html/directives/if-defined";
|
import { ifDefined } from "lit-html/directives/if-defined";
|
||||||
import "../../elements/Tabs";
|
import "../../elements/Tabs";
|
||||||
|
import "./tokens/UserTokenList";
|
||||||
import "./UserDetailsPage";
|
import "./UserDetailsPage";
|
||||||
import "./UserTokenList";
|
|
||||||
import "./settings/UserSettingsAuthenticatorTOTP";
|
import "./settings/UserSettingsAuthenticatorTOTP";
|
||||||
import "./settings/UserSettingsAuthenticatorStatic";
|
import "./settings/UserSettingsAuthenticatorStatic";
|
||||||
import "./settings/UserSettingsAuthenticatorWebAuthn";
|
import "./settings/UserSettingsAuthenticatorWebAuthn";
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { CoreApi, Token } from "authentik-api";
|
||||||
|
import { gettext } from "django";
|
||||||
|
import { customElement, property } from "lit-element";
|
||||||
|
import { html, TemplateResult } from "lit-html";
|
||||||
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
||||||
|
import { Form } from "../../../elements/forms/Form";
|
||||||
|
import { ifDefined } from "lit-html/directives/if-defined";
|
||||||
|
import "../../../elements/forms/HorizontalFormElement";
|
||||||
|
|
||||||
|
@customElement("ak-user-token-form")
|
||||||
|
export class UserTokenForm extends Form<Token> {
|
||||||
|
|
||||||
|
@property({attribute: false})
|
||||||
|
token?: Token;
|
||||||
|
|
||||||
|
getSuccessMessage(): string {
|
||||||
|
if (this.token) {
|
||||||
|
return gettext("Successfully updated token.");
|
||||||
|
} else {
|
||||||
|
return gettext("Successfully created token.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send = (data: Token): Promise<Token> => {
|
||||||
|
if (this.token) {
|
||||||
|
return new CoreApi(DEFAULT_CONFIG).coreTokensUpdate({
|
||||||
|
identifier: this.token.identifier,
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new CoreApi(DEFAULT_CONFIG).coreTokensCreate({
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
renderForm(): TemplateResult {
|
||||||
|
return html`<form class="pf-c-form pf-m-horizontal">
|
||||||
|
<ak-form-element-horizontal
|
||||||
|
label=${gettext("Identifier")}
|
||||||
|
?required=${true}
|
||||||
|
name="identifier">
|
||||||
|
<input type="text" value="${ifDefined(this.token?.identifier)}" class="pf-c-form-control" required>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
<ak-form-element-horizontal
|
||||||
|
label=${gettext("Description")}
|
||||||
|
?required=${true}
|
||||||
|
name="description">
|
||||||
|
<input type="text" value="${ifDefined(this.token?.description)}" class="pf-c-form-control" required>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
</form>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,16 +1,19 @@
|
||||||
import { gettext } from "django";
|
import { gettext } from "django";
|
||||||
import { customElement, html, property, TemplateResult } from "lit-element";
|
import { CSSResult, customElement, html, property, TemplateResult } from "lit-element";
|
||||||
import { AKResponse } from "../../api/Client";
|
import { AKResponse } from "../../../api/Client";
|
||||||
|
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
|
||||||
|
|
||||||
import "../../elements/forms/DeleteForm";
|
import "../../../elements/forms/DeleteForm";
|
||||||
import "../../elements/buttons/ModalButton";
|
import "../../../elements/forms/ModalForm";
|
||||||
import "../../elements/buttons/Dropdown";
|
import "../../../elements/buttons/ModalButton";
|
||||||
import "../../elements/buttons/TokenCopyButton";
|
import "../../../elements/buttons/Dropdown";
|
||||||
import { Table, TableColumn } from "../../elements/table/Table";
|
import "../../../elements/buttons/TokenCopyButton";
|
||||||
import { PAGE_SIZE } from "../../constants";
|
import { Table, TableColumn } from "../../../elements/table/Table";
|
||||||
|
import { PAGE_SIZE } from "../../../constants";
|
||||||
import { CoreApi, Token } from "authentik-api";
|
import { CoreApi, Token } from "authentik-api";
|
||||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
||||||
import { AdminURLManager } from "../../api/legacy";
|
import { AdminURLManager } from "../../../api/legacy";
|
||||||
|
import "./UserTokenForm";
|
||||||
|
|
||||||
@customElement("ak-user-token-list")
|
@customElement("ak-user-token-list")
|
||||||
export class UserTokenList extends Table<Token> {
|
export class UserTokenList extends Table<Token> {
|
||||||
|
@ -39,14 +42,25 @@ export class UserTokenList extends Table<Token> {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult[] {
|
||||||
|
return super.styles.concat(PFDescriptionList);
|
||||||
|
}
|
||||||
|
|
||||||
renderToolbar(): TemplateResult {
|
renderToolbar(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ak-modal-button href="/-/user/tokens/create/">
|
<ak-forms-modal>
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-primary">
|
<span slot="submit">
|
||||||
${gettext("Create")}
|
${gettext("Create")}
|
||||||
</ak-spinner-button>
|
</span>
|
||||||
<div slot="modal"></div>
|
<span slot="header">
|
||||||
</ak-modal-button>
|
${gettext("Create Token")}
|
||||||
|
</span>
|
||||||
|
<ak-user-token-form slot="form">
|
||||||
|
</ak-user-token-form>
|
||||||
|
<button slot="trigger" class="pf-c-button pf-m-primary">
|
||||||
|
${gettext("Create")}
|
||||||
|
</button>
|
||||||
|
</ak-forms-modal>
|
||||||
${super.renderToolbar()}
|
${super.renderToolbar()}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -90,12 +104,19 @@ export class UserTokenList extends Table<Token> {
|
||||||
return [
|
return [
|
||||||
html`${item.identifier}`,
|
html`${item.identifier}`,
|
||||||
html`
|
html`
|
||||||
<ak-modal-button href="${AdminURLManager.tokens(`${item.identifier}/update/`)}">
|
<ak-forms-modal>
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-secondary">
|
<span slot="submit">
|
||||||
|
${gettext("Update")}
|
||||||
|
</span>
|
||||||
|
<span slot="header">
|
||||||
|
${gettext("Update Token")}
|
||||||
|
</span>
|
||||||
|
<ak-user-token-form slot="form" .token=${item}>
|
||||||
|
</ak-user-token-form>
|
||||||
|
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
||||||
${gettext("Edit")}
|
${gettext("Edit")}
|
||||||
</ak-spinner-button>
|
</button>
|
||||||
<div slot="modal"></div>
|
</ak-forms-modal>
|
||||||
</ak-modal-button>
|
|
||||||
<ak-forms-delete
|
<ak-forms-delete
|
||||||
.obj=${item}
|
.obj=${item}
|
||||||
objectLabel=${gettext("Token")}
|
objectLabel=${gettext("Token")}
|
Reference in New Issue