diff --git a/authentik/core/api/propertymappings.py b/authentik/core/api/propertymappings.py
index cc2542483..b1a32cc28 100644
--- a/authentik/core/api/propertymappings.py
+++ b/authentik/core/api/propertymappings.py
@@ -116,9 +116,7 @@ class PropertyMappingViewSet(
if not users.exists():
raise PermissionDenied()
- response_data = {
- "successful": True
- }
+ response_data = {"successful": True}
try:
result = mapping.evaluate(
users.first(),
diff --git a/web/src/elements/CodeMirror.ts b/web/src/elements/CodeMirror.ts
index 897b730be..4340fe902 100644
--- a/web/src/elements/CodeMirror.ts
+++ b/web/src/elements/CodeMirror.ts
@@ -10,6 +10,7 @@ import "codemirror/mode/python/python.js";
import CodeMirrorStyle from "codemirror/lib/codemirror.css";
import CodeMirrorTheme from "codemirror/theme/monokai.css";
import { ifDefined } from "lit-html/directives/if-defined";
+import YAML from "yaml";
@customElement("ak-codemirror")
export class CodeMirrorTextarea extends LitElement {
@@ -22,11 +23,37 @@ export class CodeMirrorTextarea extends LitElement {
@property()
name?: string;
- @property()
- value?: string;
-
editor?: CodeMirror.EditorFromTextArea;
+ private _value?: string;
+
+ @property()
+ set value(v: string) {
+ this._value = v.toString();
+ }
+
+ get value(): string {
+ switch (this.mode.toLowerCase()) {
+ case "yaml":
+ return YAML.parse(this.getInnerValue());
+ case "javascript":
+ return JSON.parse(this.getInnerValue());
+ default:
+ return this.getInnerValue();
+ }
+ }
+
+ private getInnerValue(): string {
+ if (!this.shadowRoot) {
+ return "";
+ }
+ const ta = this.shadowRoot?.querySelector("textarea");
+ if (!ta) {
+ return "";
+ }
+ return ta.value;
+ }
+
static get styles(): CSSResult[] {
return [PFForm, CodeMirrorStyle, CodeMirrorTheme];
}
@@ -49,6 +76,6 @@ export class CodeMirrorTextarea extends LitElement {
}
render(): TemplateResult {
- return html``;
+ return html``;
}
}
diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts
index c0fae4c54..9940b0e1f 100644
--- a/web/src/elements/forms/Form.ts
+++ b/web/src/elements/forms/Form.ts
@@ -78,10 +78,9 @@ export class Form extends LitElement {
}
serializeForm(form: IronFormElement): T {
- const elements = form._getSubmittableElements();
+ const elements: HTMLInputElement[] = form._getSubmittableElements();
const json: { [key: string]: unknown } = {};
- for (let i = 0; i < elements.length; i++) {
- const element = elements[i] as HTMLInputElement;
+ elements.forEach(element => {
const values = form._serializeElementValues(element);
if (element.tagName.toLowerCase() === "select" && "multiple" in element.attributes) {
json[element.name] = values;
@@ -90,7 +89,7 @@ export class Form extends LitElement {
form._addSerializedElement(json, element.name, values[v]);
}
}
- }
+ });
return json as unknown as T;
}
diff --git a/web/src/pages/property-mappings/PropertyMappingTestForm.ts b/web/src/pages/property-mappings/PropertyMappingTestForm.ts
index 555c67a52..e90a60cf6 100644
--- a/web/src/pages/property-mappings/PropertyMappingTestForm.ts
+++ b/web/src/pages/property-mappings/PropertyMappingTestForm.ts
@@ -34,7 +34,7 @@ export class PolicyTestForm extends Form {
return html`
${this.result?.successful ?
- html`
+ html`
`:
html`