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-03-31 21:07:57 +00:00
|
|
|
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";
|
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")
|
|
|
|
export class PropertyMappingScopeForm extends Form<ScopeMapping> {
|
|
|
|
|
|
|
|
set mappingUUID(value: string) {
|
|
|
|
new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeRead({
|
|
|
|
pmUuid: value,
|
|
|
|
}).then(mapping => {
|
|
|
|
this.mapping = mapping;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
mapping?: ScopeMapping;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
if (this.mapping) {
|
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> => {
|
|
|
|
if (this.mapping) {
|
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeUpdate({
|
|
|
|
pmUuid: this.mapping.pk || "",
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeCreate({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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">
|
|
|
|
<input type="text" value="${ifDefined(this.mapping?.name)}" class="pf-c-form-control" required>
|
|
|
|
</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">
|
|
|
|
<input type="text" value="${ifDefined(this.mapping?.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">
|
|
|
|
<input type="text" value="${ifDefined(this.mapping?.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-03-31 21:07:57 +00:00
|
|
|
name="expression">
|
2021-04-01 13:39:59 +00:00
|
|
|
<ak-codemirror mode="python" value="${ifDefined(this.mapping?.expression)}">
|
2021-03-31 21:07:57 +00:00
|
|
|
</ak-codemirror>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
Expression using Python. See <a href="https://goauthentik.io/docs/property-mappings/expression/">here</a> for a list of all variables.
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|