api: add set_*_url method for Application and Flow to set icon/background to URL
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import { CoreApi, Application, ProvidersApi, Provider, PolicyEngineMode } from "authentik-api";
|
||||
import { CoreApi, Application, ProvidersApi, Provider, PolicyEngineMode, CapabilitiesEnum } from "authentik-api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { CSSResult, customElement, property } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { config, DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../elements/buttons/Dropdown";
|
||||
@ -13,6 +13,7 @@ import "../../elements/forms/HorizontalFormElement";
|
||||
import "../../elements/forms/FormGroup";
|
||||
import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
import { first } from "../../utils";
|
||||
|
||||
@customElement("ak-application-form")
|
||||
export class ApplicationForm extends ModelForm<Application, string> {
|
||||
@ -50,16 +51,28 @@ export class ApplicationForm extends ModelForm<Application, string> {
|
||||
applicationRequest: data
|
||||
});
|
||||
}
|
||||
const icon = this.getFormFile();
|
||||
if (icon) {
|
||||
return writeOp.then(app => {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({
|
||||
slug: app.slug,
|
||||
file: icon
|
||||
return config().then((c) => {
|
||||
if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) {
|
||||
const icon = this.getFormFile();
|
||||
if (icon) {
|
||||
return writeOp.then(app => {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({
|
||||
slug: app.slug,
|
||||
file: icon
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return writeOp.then(app => {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({
|
||||
slug: app.slug,
|
||||
setIconURLRequest: {
|
||||
url: data.metaIcon || "",
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
return writeOp;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
groupProviders(providers: Provider[]): TemplateResult {
|
||||
@ -164,11 +177,18 @@ export class ApplicationForm extends ModelForm<Application, string> {
|
||||
<input type="text" value="${ifDefined(this.instance?.metaLaunchUrl)}" class="pf-c-form-control">
|
||||
<p class="pf-c-form__helper-text">${t`If left empty, authentik will try to extract the launch URL based on the selected provider.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Icon`}
|
||||
name="metaIcon">
|
||||
<input type="file" value="${ifDefined(this.instance?.metaIcon)}" class="pf-c-form-control">
|
||||
</ak-form-element-horizontal>
|
||||
${until(config().then((c) => {
|
||||
let type = "text";
|
||||
if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) {
|
||||
type = "file";
|
||||
}
|
||||
return html`<ak-form-element-horizontal
|
||||
label=${t`Icon`}
|
||||
name="metaIcon">
|
||||
<!-- @ts-ignore -->
|
||||
<input type=${type} value="${first(this.instance?.metaIcon, "")}" class="pf-c-form-control">
|
||||
</ak-form-element-horizontal>`;
|
||||
}))}
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Description`}
|
||||
name="metaDescription">
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { Flow, FlowDesignationEnum, PolicyEngineMode, FlowsApi } from "authentik-api";
|
||||
import { Flow, FlowDesignationEnum, PolicyEngineMode, FlowsApi, CapabilitiesEnum } from "authentik-api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { config, DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { first } from "../../utils";
|
||||
|
||||
@customElement("ak-flow-form")
|
||||
export class FlowForm extends ModelForm<Flow, string> {
|
||||
@ -36,16 +38,28 @@ export class FlowForm extends ModelForm<Flow, string> {
|
||||
flowRequest: data
|
||||
});
|
||||
}
|
||||
const background = this.getFormFile();
|
||||
if (background) {
|
||||
return writeOp.then(flow => {
|
||||
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({
|
||||
slug: flow.slug,
|
||||
file: background
|
||||
return config().then((c) => {
|
||||
if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) {
|
||||
const icon = this.getFormFile();
|
||||
if (icon) {
|
||||
return writeOp.then(app => {
|
||||
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({
|
||||
slug: app.slug,
|
||||
file: icon
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return writeOp.then(app => {
|
||||
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({
|
||||
slug: app.slug,
|
||||
setIconURLRequest: {
|
||||
url: data.background || "",
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
return writeOp;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
renderDesignations(): TemplateResult {
|
||||
@ -119,12 +133,19 @@ export class FlowForm extends ModelForm<Flow, string> {
|
||||
</select>
|
||||
<p class="pf-c-form__helper-text">${t`Decides what this Flow is used for. For example, the Authentication flow is redirect to when an un-authenticated user visits authentik.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${t`Background`}
|
||||
name="background">
|
||||
<input type="file" value="${ifDefined(this.instance?.background)}" class="pf-c-form-control">
|
||||
<p class="pf-c-form__helper-text">${t`Background shown during execution.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
${until(config().then((c) => {
|
||||
let type = "text";
|
||||
if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) {
|
||||
type = "file";
|
||||
}
|
||||
return html`<ak-form-element-horizontal
|
||||
label=${t`Background`}
|
||||
name="background">
|
||||
<!-- @ts-ignore -->
|
||||
<input type=${type} value="${first(this.instance?.background, "/static/dist/assets/images/flow_background.jpg")}" class="pf-c-form-control">
|
||||
<p class="pf-c-form__helper-text">${t`Background shown during execution.`}</p>
|
||||
</ak-form-element-horizontal>`;
|
||||
}))}
|
||||
</form>`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user