web/admin: migrate more forms
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
4d11d82c6e
commit
ff9ff18c11
|
@ -13,15 +13,19 @@ import "../../elements/chips/Chip";
|
|||
import "./MemberSelectModal";
|
||||
import YAML from "yaml";
|
||||
import { first } from "../../utils";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
|
||||
@customElement("ak-group-form")
|
||||
export class GroupForm extends Form<Group> {
|
||||
export class GroupForm extends ModelForm<Group, string> {
|
||||
|
||||
@property({attribute: false})
|
||||
group?: Group;
|
||||
loadInstance(pk: string): Promise<Group> {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreGroupsRead({
|
||||
groupUuid: pk
|
||||
});
|
||||
}
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.group) {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated group.`;
|
||||
} else {
|
||||
return t`Successfully created group.`;
|
||||
|
@ -29,13 +33,13 @@ export class GroupForm extends Form<Group> {
|
|||
}
|
||||
|
||||
send = (data: Group): Promise<Group> => {
|
||||
if (this.group?.pk) {
|
||||
if (this.instance?.pk) {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreGroupsUpdate({
|
||||
groupUuid: this.group.pk || "",
|
||||
groupUuid: this.instance.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
data.users = Array.from(this.group?.users || []) as unknown as Set<number>;
|
||||
data.users = Array.from(this.instance?.users || []) as unknown as Set<number>;
|
||||
return new CoreApi(DEFAULT_CONFIG).coreGroupsCreate({
|
||||
data: data
|
||||
});
|
||||
|
@ -48,11 +52,11 @@ export class GroupForm extends Form<Group> {
|
|||
label=${t`Name`}
|
||||
?required=${true}
|
||||
name="name">
|
||||
<input type="text" value="${ifDefined(this.group?.name)}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="isSuperuser">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.group?.isSuperuser, false)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.isSuperuser, false)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Is superuser`}
|
||||
</label>
|
||||
|
@ -63,10 +67,10 @@ export class GroupForm extends Form<Group> {
|
|||
label=${t`Parent`}
|
||||
name="parent">
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.group?.parent === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.parent === undefined}>---------</option>
|
||||
${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => {
|
||||
return groups.results.map(group => {
|
||||
return html`<option value=${ifDefined(group.pk)} ?selected=${this.group?.parent === group.pk}>${group.name}</option>`;
|
||||
return html`<option value=${ifDefined(group.pk)} ?selected=${this.instance?.parent === group.pk}>${group.name}</option>`;
|
||||
});
|
||||
}), html`<option>${t`Loading...`}</option>`)}
|
||||
</select>
|
||||
|
@ -79,8 +83,8 @@ export class GroupForm extends Form<Group> {
|
|||
.confirm=${(items: User[]) => {
|
||||
// Because the model only has the IDs, map the user list to IDs
|
||||
const ids = items.map(u => u.pk || 0);
|
||||
if (!this.group) this.group = {} as Group;
|
||||
this.group.users = new Set(Array.from(this.group?.users || []).concat(ids));
|
||||
if (!this.instance) this.instance = {} as Group;
|
||||
this.instance.users = new Set(Array.from(this.instance?.users || []).concat(ids));
|
||||
this.requestUpdate();
|
||||
return Promise.resolve();
|
||||
}}>
|
||||
|
@ -94,7 +98,7 @@ export class GroupForm extends Form<Group> {
|
|||
ordering: "username",
|
||||
}).then(users => {
|
||||
return users.results.map(user => {
|
||||
const selected = Array.from(this.group?.users || []).some(su => {
|
||||
const selected = Array.from(this.instance?.users || []).some(su => {
|
||||
return su == user.pk;
|
||||
});
|
||||
if (!selected) return;
|
||||
|
@ -102,11 +106,11 @@ export class GroupForm extends Form<Group> {
|
|||
.removable=${true}
|
||||
value=${ifDefined(user.pk)}
|
||||
@remove=${() => {
|
||||
if (!this.group) return;
|
||||
const users = Array.from(this.group?.users || []);
|
||||
if (!this.instance) return;
|
||||
const users = Array.from(this.instance?.users || []);
|
||||
const idx = users.indexOf(user.pk || 0);
|
||||
users.splice(idx, 1);
|
||||
this.group.users = new Set(users);
|
||||
this.instance.users = new Set(users);
|
||||
this.requestUpdate();
|
||||
}}>
|
||||
${user.username}
|
||||
|
@ -122,7 +126,7 @@ export class GroupForm extends Form<Group> {
|
|||
label=${t`Attributes`}
|
||||
?required=${true}
|
||||
name="attributes">
|
||||
<ak-codemirror mode="yaml" value="${YAML.stringify(first(this.group?.attributes, {}))}">
|
||||
<ak-codemirror mode="yaml" value="${YAML.stringify(first(this.instance?.attributes, {}))}">
|
||||
</ak-codemirror>
|
||||
<p class="pf-c-form__helper-text">${t`Set custom attributes using YAML or JSON.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
|
|
|
@ -63,7 +63,7 @@ export class GroupListPage extends TablePage<Group> {
|
|||
<span slot="header">
|
||||
${t`Update Group`}
|
||||
</span>
|
||||
<ak-group-form slot="form" .group=${item}>
|
||||
<ak-group-form slot="form" .instancePk=${item.pk}>
|
||||
</ak-group-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
||||
${t`Edit`}
|
||||
|
|
|
@ -1,30 +1,25 @@
|
|||
import { CryptoApi, DockerServiceConnection, OutpostsApi } from "authentik-api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { customElement } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { Form } from "../../elements/forms/Form";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
import { first } from "../../utils";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
|
||||
@customElement("ak-service-connection-docker-form")
|
||||
export class ServiceConnectionDockerForm extends Form<DockerServiceConnection> {
|
||||
export class ServiceConnectionDockerForm extends ModelForm<DockerServiceConnection, string> {
|
||||
|
||||
set scUUID(value: string) {
|
||||
new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsDockerRead({
|
||||
uuid: value,
|
||||
}).then(sc => {
|
||||
this.sc = sc;
|
||||
loadInstance(pk: string): Promise<DockerServiceConnection> {
|
||||
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsDockerRead({
|
||||
uuid: pk,
|
||||
});
|
||||
}
|
||||
|
||||
@property({attribute: false})
|
||||
sc?: DockerServiceConnection;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.sc) {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated service-connection.`;
|
||||
} else {
|
||||
return t`Successfully created service-connection.`;
|
||||
|
@ -32,9 +27,9 @@ export class ServiceConnectionDockerForm extends Form<DockerServiceConnection> {
|
|||
}
|
||||
|
||||
send = (data: DockerServiceConnection): Promise<DockerServiceConnection> => {
|
||||
if (this.sc) {
|
||||
if (this.instance) {
|
||||
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsDockerUpdate({
|
||||
uuid: this.sc.pk || "",
|
||||
uuid: this.instance.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
|
@ -50,11 +45,11 @@ export class ServiceConnectionDockerForm extends Form<DockerServiceConnection> {
|
|||
label=${t`Name`}
|
||||
?required=${true}
|
||||
name="name">
|
||||
<input type="text" value="${ifDefined(this.sc?.name)}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="local">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.sc?.local, false)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.local, false)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Local`}
|
||||
</label>
|
||||
|
@ -65,19 +60,19 @@ export class ServiceConnectionDockerForm extends Form<DockerServiceConnection> {
|
|||
label=${t`Docker URL`}
|
||||
?required=${true}
|
||||
name="url">
|
||||
<input type="text" value="${ifDefined(this.sc?.url)}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.instance?.url)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${t`Can be in the format of 'unix://' when connecting to a local docker daemon, or 'https://:2376' when connecting to a remote system.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`TLS Verification Certificate`}
|
||||
name="tlsVerification">
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.sc?.tlsVerification === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.tlsVerification === undefined}>---------</option>
|
||||
${until(new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsList({
|
||||
ordering: "pk"
|
||||
}).then(certs => {
|
||||
return certs.results.map(cert => {
|
||||
return html`<option value=${ifDefined(cert.pk)} ?selected=${this.sc?.tlsVerification === cert.pk}>${cert.name}</option>`;
|
||||
return html`<option value=${ifDefined(cert.pk)} ?selected=${this.instance?.tlsVerification === cert.pk}>${cert.name}</option>`;
|
||||
});
|
||||
}), html`<option>${t`Loading...`}</option>`)}
|
||||
</select>
|
||||
|
@ -87,12 +82,12 @@ export class ServiceConnectionDockerForm extends Form<DockerServiceConnection> {
|
|||
label=${t`TLS Authentication Certificate`}
|
||||
name="tlsAuthentication">
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.sc?.tlsAuthentication === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.tlsAuthentication === undefined}>---------</option>
|
||||
${until(new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsList({
|
||||
ordering: "pk"
|
||||
}).then(certs => {
|
||||
return certs.results.map(cert => {
|
||||
return html`<option value=${ifDefined(cert.pk)} ?selected=${this.sc?.tlsAuthentication === cert.pk}>${cert.name}</option>`;
|
||||
return html`<option value=${ifDefined(cert.pk)} ?selected=${this.instance?.tlsAuthentication === cert.pk}>${cert.name}</option>`;
|
||||
});
|
||||
}), html`<option>${t`Loading...`}</option>`)}
|
||||
</select>
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
import { KubernetesServiceConnection, OutpostsApi } from "authentik-api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { customElement } 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";
|
||||
import "../../elements/CodeMirror";
|
||||
import YAML from "yaml";
|
||||
import { first } from "../../utils";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
|
||||
@customElement("ak-service-connection-kubernetes-form")
|
||||
export class ServiceConnectionKubernetesForm extends Form<KubernetesServiceConnection> {
|
||||
export class ServiceConnectionKubernetesForm extends ModelForm<KubernetesServiceConnection, string> {
|
||||
|
||||
set scUUID(value: string) {
|
||||
new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesRead({
|
||||
uuid: value,
|
||||
}).then(sc => {
|
||||
this.sc = sc;
|
||||
loadInstance(pk: string): Promise<KubernetesServiceConnection> {
|
||||
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesRead({
|
||||
uuid: pk,
|
||||
});
|
||||
}
|
||||
|
||||
@property({attribute: false})
|
||||
sc?: KubernetesServiceConnection;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.sc) {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated service-connection.`;
|
||||
} else {
|
||||
return t`Successfully created service-connection.`;
|
||||
|
@ -33,9 +28,9 @@ export class ServiceConnectionKubernetesForm extends Form<KubernetesServiceConne
|
|||
}
|
||||
|
||||
send = (data: KubernetesServiceConnection): Promise<KubernetesServiceConnection> => {
|
||||
if (this.sc) {
|
||||
if (this.instance) {
|
||||
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesUpdate({
|
||||
uuid: this.sc.pk || "",
|
||||
uuid: this.instance.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
|
@ -51,11 +46,11 @@ export class ServiceConnectionKubernetesForm extends Form<KubernetesServiceConne
|
|||
label=${t`Name`}
|
||||
?required=${true}
|
||||
name="name">
|
||||
<input type="text" value="${ifDefined(this.sc?.name)}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="local">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.sc?.local, false)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.local, false)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Local`}
|
||||
</label>
|
||||
|
@ -65,7 +60,7 @@ export class ServiceConnectionKubernetesForm extends Form<KubernetesServiceConne
|
|||
<ak-form-element-horizontal
|
||||
label=${t`Kubeconfig`}
|
||||
name="kubeconfig">
|
||||
<ak-codemirror mode="yaml" value="${YAML.stringify(first(this.sc?.kubeconfig, {}))}">
|
||||
<ak-codemirror mode="yaml" value="${YAML.stringify(first(this.instance?.kubeconfig, {}))}">
|
||||
</ak-codemirror>
|
||||
<p class="pf-c-form__helper-text">${t`Set custom attributes using YAML or JSON.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
|
|
|
@ -82,7 +82,7 @@ export class OutpostServiceConnectionListPage extends TablePage<ServiceConnectio
|
|||
<ak-proxy-form
|
||||
slot="form"
|
||||
.args=${{
|
||||
"scUUID": item.pk
|
||||
"instancePk": item.pk
|
||||
}}
|
||||
type=${ifDefined(item.component)}>
|
||||
</ak-proxy-form>
|
||||
|
|
|
@ -88,7 +88,7 @@ export class BoundPoliciesList extends Table<PolicyBinding> {
|
|||
<span slot="header">
|
||||
${t`Update Group`}
|
||||
</span>
|
||||
<ak-group-form slot="form" .group=${item.groupObj}>
|
||||
<ak-group-form slot="form" .instancePk=${item.groupObj?.pk}>
|
||||
</ak-group-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
||||
${t`Edit Group`}
|
||||
|
@ -128,7 +128,7 @@ export class BoundPoliciesList extends Table<PolicyBinding> {
|
|||
<span slot="header">
|
||||
${t`Update Binding`}
|
||||
</span>
|
||||
<ak-policy-binding-form slot="form" .binding=${item} targetPk=${ifDefined(this.target)} ?policyOnly=${this.policyOnly}>
|
||||
<ak-policy-binding-form slot="form" .instancePk=${item.pk} targetPk=${ifDefined(this.target)} ?policyOnly=${this.policyOnly}>
|
||||
</ak-policy-binding-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
||||
${t`Edit Binding`}
|
||||
|
|
|
@ -3,41 +3,38 @@ import { t } from "@lingui/macro";
|
|||
import { css, CSSResult, customElement, property } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { Form } from "../../elements/forms/Form";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import { first, groupBy } from "../../utils";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
import PFToggleGroup from "@patternfly/patternfly/components/ToggleGroup/toggle-group.css";
|
||||
import PFContent from "@patternfly/patternfly/components/Content/content.css";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
|
||||
enum target {
|
||||
policy, group, user
|
||||
}
|
||||
|
||||
@customElement("ak-policy-binding-form")
|
||||
export class PolicyBindingForm extends Form<PolicyBinding> {
|
||||
export class PolicyBindingForm extends ModelForm<PolicyBinding, string> {
|
||||
|
||||
@property({attribute: false})
|
||||
set binding(value: PolicyBinding | undefined) {
|
||||
this._binding = value;
|
||||
if (value?.policyObj) {
|
||||
this.policyGroupUser = target.policy;
|
||||
}
|
||||
if (value?.groupObj) {
|
||||
this.policyGroupUser = target.group;
|
||||
}
|
||||
if (value?.userObj) {
|
||||
this.policyGroupUser = target.user;
|
||||
}
|
||||
loadInstance(pk: string): Promise<PolicyBinding> {
|
||||
return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsRead({
|
||||
policyBindingUuid: pk
|
||||
}).then(binding => {
|
||||
if (binding?.policyObj) {
|
||||
this.policyGroupUser = target.policy;
|
||||
}
|
||||
if (binding?.groupObj) {
|
||||
this.policyGroupUser = target.group;
|
||||
}
|
||||
if (binding?.userObj) {
|
||||
this.policyGroupUser = target.user;
|
||||
}
|
||||
return binding;
|
||||
});
|
||||
}
|
||||
|
||||
get binding(): PolicyBinding | undefined {
|
||||
return this._binding;
|
||||
}
|
||||
|
||||
_binding?: PolicyBinding;
|
||||
|
||||
@property()
|
||||
targetPk?: string;
|
||||
|
||||
|
@ -48,7 +45,7 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
policyOnly = false;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.binding) {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated binding.`;
|
||||
} else {
|
||||
return t`Successfully created binding.`;
|
||||
|
@ -64,9 +61,9 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
}
|
||||
|
||||
send = (data: PolicyBinding): Promise<PolicyBinding> => {
|
||||
if (this.binding) {
|
||||
if (this.instance) {
|
||||
return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsUpdate({
|
||||
policyBindingUuid: this.binding.pk || "",
|
||||
policyBindingUuid: this.instance.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
|
@ -81,7 +78,7 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
${groupBy<Policy>(policies, (p => p.verboseName || "")).map(([group, policies]) => {
|
||||
return html`<optgroup label=${group}>
|
||||
${policies.map(p => {
|
||||
const selected = (this.binding?.policy === p.pk);
|
||||
const selected = (this.instance?.policy === p.pk);
|
||||
return html`<option ?selected=${selected} value=${ifDefined(p.pk)}>${p.name}</option>`;
|
||||
})}
|
||||
</optgroup>`;
|
||||
|
@ -90,8 +87,8 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
}
|
||||
|
||||
getOrder(): Promise<number> {
|
||||
if (this.binding) {
|
||||
return Promise.resolve(this.binding.order);
|
||||
if (this.instance) {
|
||||
return Promise.resolve(this.instance.order);
|
||||
}
|
||||
return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsList({
|
||||
target: this.targetPk || "",
|
||||
|
@ -154,7 +151,7 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
name="policy"
|
||||
?hidden=${this.policyGroupUser !== target.policy}>
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.binding?.policy === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.policy === undefined}>---------</option>
|
||||
${until(new PoliciesApi(DEFAULT_CONFIG).policiesAllList({
|
||||
ordering: "pk"
|
||||
}).then(policies => {
|
||||
|
@ -167,12 +164,12 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
name="group"
|
||||
?hidden=${this.policyGroupUser !== target.group}>
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.binding?.group === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.group === undefined}>---------</option>
|
||||
${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({
|
||||
ordering: "pk"
|
||||
}).then(groups => {
|
||||
return groups.results.map(group => {
|
||||
return html`<option value=${ifDefined(group.pk)} ?selected=${group.pk === this.binding?.group}>${group.name}</option>`;
|
||||
return html`<option value=${ifDefined(group.pk)} ?selected=${group.pk === this.instance?.group}>${group.name}</option>`;
|
||||
});
|
||||
}), html`<option>${t`Loading...`}</option>`)}
|
||||
</select>
|
||||
|
@ -182,22 +179,22 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
name="user"
|
||||
?hidden=${this.policyGroupUser !== target.user}>
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.binding?.user === undefined}>---------</option>
|
||||
<option value="" ?selected=${this.instance?.user === undefined}>---------</option>
|
||||
${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
||||
ordering: "pk"
|
||||
}).then(users => {
|
||||
return users.results.map(user => {
|
||||
return html`<option value=${ifDefined(user.pk)} ?selected=${user.pk === this.binding?.user}>${user.name}</option>`;
|
||||
return html`<option value=${ifDefined(user.pk)} ?selected=${user.pk === this.instance?.user}>${user.name}</option>`;
|
||||
});
|
||||
}), html`<option>${t`Loading...`}</option>`)}
|
||||
</select>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
</div>
|
||||
<input required name="target" type="hidden" value=${ifDefined(this.binding?.target || this.targetPk)}>
|
||||
<input required name="target" type="hidden" value=${ifDefined(this.instance?.target || this.targetPk)}>
|
||||
<ak-form-element-horizontal name="enabled">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.binding?.enabled, true)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.enabled, true)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Enabled`}
|
||||
</label>
|
||||
|
@ -213,7 +210,7 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
label=${t`Timeout`}
|
||||
?required=${true}
|
||||
name="timeout">
|
||||
<input type="number" value="${first(this.binding?.timeout, 30)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.instance?.timeout, 30)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
</form>`;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ export class PolicyListPage extends TablePage<Policy> {
|
|||
<ak-proxy-form
|
||||
slot="form"
|
||||
.args=${{
|
||||
"policyUUID": item.pk
|
||||
"instancePk": item.pk
|
||||
}}
|
||||
type=${ifDefined(item.component)}>
|
||||
</ak-proxy-form>
|
||||
|
|
|
@ -1,30 +1,25 @@
|
|||
import { DummyPolicy, PoliciesApi } from "authentik-api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { customElement } 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";
|
||||
import "../../../elements/forms/FormGroup";
|
||||
import { first } from "../../../utils";
|
||||
import { ModelForm } from "../../../elements/forms/ModelForm";
|
||||
|
||||
@customElement("ak-policy-dummy-form")
|
||||
export class DummyPolicyForm extends Form<DummyPolicy> {
|
||||
export class DummyPolicyForm extends ModelForm<DummyPolicy, string> {
|
||||
|
||||
set policyUUID(value: string) {
|
||||
new PoliciesApi(DEFAULT_CONFIG).policiesDummyRead({
|
||||
policyUuid: value,
|
||||
}).then(policy => {
|
||||
this.policy = policy;
|
||||
loadInstance(pk: string): Promise<DummyPolicy> {
|
||||
return new PoliciesApi(DEFAULT_CONFIG).policiesDummyRead({
|
||||
policyUuid: pk,
|
||||
});
|
||||
}
|
||||
|
||||
@property({attribute: false})
|
||||
policy?: DummyPolicy;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.policy) {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated policy.`;
|
||||
} else {
|
||||
return t`Successfully created policy.`;
|
||||
|
@ -32,9 +27,9 @@ export class DummyPolicyForm extends Form<DummyPolicy> {
|
|||
}
|
||||
|
||||
send = (data: DummyPolicy): Promise<DummyPolicy> => {
|
||||
if (this.policy) {
|
||||
if (this.instance) {
|
||||
return new PoliciesApi(DEFAULT_CONFIG).policiesDummyUpdate({
|
||||
policyUuid: this.policy.pk || "",
|
||||
policyUuid: this.instance.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
|
@ -53,11 +48,11 @@ export class DummyPolicyForm extends Form<DummyPolicy> {
|
|||
label=${t`Name`}
|
||||
?required=${true}
|
||||
name="name">
|
||||
<input type="text" value="${ifDefined(this.policy?.name || "")}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="executionLogging">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.executionLogging, false)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.executionLogging, false)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Execution logging`}
|
||||
</label>
|
||||
|
@ -73,7 +68,7 @@ export class DummyPolicyForm extends Form<DummyPolicy> {
|
|||
<div slot="body" class="pf-c-form">
|
||||
<ak-form-element-horizontal name="result">
|
||||
<div class="pf-c-check">
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.policy?.result, false)}>
|
||||
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.result, false)}>
|
||||
<label class="pf-c-check__label">
|
||||
${t`Pass policy?`}
|
||||
</label>
|
||||
|
@ -83,14 +78,14 @@ export class DummyPolicyForm extends Form<DummyPolicy> {
|
|||
label=${t`Wait (min)`}
|
||||
?required=${true}
|
||||
name="waitMin">
|
||||
<input type="number" value="${first(this.policy?.waitMin, 1)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.instance?.waitMin, 1)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${t`The policy takes a random time to execute. This controls the minimum time it will take.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Wait (max)`}
|
||||
?required=${true}
|
||||
name="waitMax">
|
||||
<input type="number" value="${first(this.policy?.waitMax, 5)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.instance?.waitMax, 5)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
</ak-form-group>
|
||||
|
|
Reference in a new issue