2021-03-31 21:07:57 +00:00
|
|
|
import { ScopeMapping, PropertymappingsApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-05-11 10:12:31 +00:00
|
|
|
import { customElement } from "lit-element";
|
2021-03-31 21:07:57 +00:00
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
2021-05-11 09:48:34 +00:00
|
|
|
import { ModelForm } from "../../elements/forms/ModelForm";
|
2021-03-31 21:07:57 +00:00
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../elements/forms/HorizontalFormElement";
|
2021-04-01 13:39:59 +00:00
|
|
|
import "../../elements/CodeMirror";
|
2021-03-31 21:07:57 +00:00
|
|
|
|
|
|
|
@customElement("ak-property-mapping-scope-form")
|
2021-05-11 09:48:34 +00:00
|
|
|
export class PropertyMappingScopeForm extends ModelForm<ScopeMapping, string> {
|
2021-03-31 21:07:57 +00:00
|
|
|
|
2021-05-11 09:48:34 +00:00
|
|
|
loadInstance(pk: string): Promise<ScopeMapping> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeRetrieve({
|
2021-05-11 09:48:34 +00:00
|
|
|
pmUuid: pk,
|
2021-03-31 21:07:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated mapping.`;
|
2021-03-31 21:07:57 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created mapping.`;
|
2021-03-31 21:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: ScopeMapping): Promise<ScopeMapping> => {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-03-31 21:07:57 +00:00
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeUpdate({
|
2021-05-11 09:48:34 +00:00
|
|
|
pmUuid: this.instance.pk || "",
|
2021-05-16 16:24:15 +00:00
|
|
|
scopeMappingRequest: data
|
2021-03-31 21:07:57 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeCreate({
|
2021-05-16 16:24:15 +00:00
|
|
|
scopeMappingRequest: data
|
2021-03-31 21:07:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Name`}
|
2021-03-31 21:07:57 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
2021-03-31 21:07:57 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Scope name`}
|
2021-03-31 21:07:57 +00:00
|
|
|
?required=${true}
|
|
|
|
name="scopeName">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.scopeName)}" class="pf-c-form-control" required>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Scope which the client can specify to access these properties.`}</p>
|
2021-03-31 21:07:57 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Description`}
|
2021-03-31 21:07:57 +00:00
|
|
|
?required=${true}
|
|
|
|
name="description">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.description)}" class="pf-c-form-control" required>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Description shown to the user when consenting. If left empty, the user won't be informed.`}</p>
|
2021-03-31 21:07:57 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Expression`}
|
2021-04-22 08:33:36 +00:00
|
|
|
?required=${true}
|
2021-03-31 21:07:57 +00:00
|
|
|
name="expression">
|
2021-05-11 09:48:34 +00:00
|
|
|
<ak-codemirror mode="python" value="${ifDefined(this.instance?.expression)}">
|
2021-03-31 21:07:57 +00:00
|
|
|
</ak-codemirror>
|
|
|
|
<p class="pf-c-form__helper-text">
|
2021-04-03 18:42:08 +00:00
|
|
|
${t`Expression using Python.`}
|
2021-04-04 11:41:18 +00:00
|
|
|
<a target="_blank" href="https://goauthentik.io/docs/property-mappings/expression/">
|
2021-04-03 18:42:08 +00:00
|
|
|
${t`See documentation for a list of all variables.`}
|
|
|
|
</a>
|
2021-03-31 21:07:57 +00:00
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|