diff --git a/web/src/admin/applications/entitlements/ApplicationEntitlementForm.ts b/web/src/admin/applications/entitlements/ApplicationEntitlementForm.ts index fd93ae611578..7a602dca3227 100644 --- a/web/src/admin/applications/entitlements/ApplicationEntitlementForm.ts +++ b/web/src/admin/applications/entitlements/ApplicationEntitlementForm.ts @@ -15,10 +15,7 @@ import { customElement, property } from "lit/decorators.js"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; -import { - ApplicationEntitlement, - CoreApi, -} from "@goauthentik/api"; +import { ApplicationEntitlement, CoreApi } from "@goauthentik/api"; @customElement("ak-application-entitlement-form") export class ApplicationEntitlementForm extends ModelForm { diff --git a/web/src/admin/applications/entitlements/ApplicationEntitlementPage.ts b/web/src/admin/applications/entitlements/ApplicationEntitlementPage.ts index 3ad667dc389b..7dc0aca92cd8 100644 --- a/web/src/admin/applications/entitlements/ApplicationEntitlementPage.ts +++ b/web/src/admin/applications/entitlements/ApplicationEntitlementPage.ts @@ -1,6 +1,7 @@ import "@goauthentik/admin/applications/entitlements/ApplicationEntitlementForm"; import "@goauthentik/admin/groups/GroupForm"; import "@goauthentik/admin/policies/BoundPoliciesList"; +import { PolicyBindingCheckTarget } from "@goauthentik/admin/policies/utils"; import "@goauthentik/admin/users/UserForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { PFSize } from "@goauthentik/common/enums"; @@ -67,20 +68,20 @@ export class ApplicationEntitlementsPage extends Table { return [ html`${item.name}`, html` - ${msg("Update")} - ${msg("Update Entitlement")} - - - - `, + ${msg("Update")} + ${msg("Update Entitlement")} + + + + `, ]; } @@ -94,7 +95,14 @@ export class ApplicationEntitlementsPage extends Table { "These bindings control which users have access to this entitlement.", )}

- + + `; diff --git a/web/src/admin/policies/BoundPoliciesList.ts b/web/src/admin/policies/BoundPoliciesList.ts index 53b4e07158b1..7cbc2133c129 100644 --- a/web/src/admin/policies/BoundPoliciesList.ts +++ b/web/src/admin/policies/BoundPoliciesList.ts @@ -1,6 +1,11 @@ import "@goauthentik/admin/groups/GroupForm"; import "@goauthentik/admin/policies/PolicyBindingForm"; +import { PolicyBindingNotice } from "@goauthentik/admin/policies/PolicyBindingForm"; import "@goauthentik/admin/policies/PolicyWizard"; +import { + PolicyBindingCheckTarget, + PolicyBindingCheckTargetToLabel, +} from "@goauthentik/admin/policies/utils"; import "@goauthentik/admin/users/UserForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { PFSize } from "@goauthentik/common/enums.js"; @@ -13,7 +18,7 @@ import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { Table, TableColumn } from "@goauthentik/elements/table/Table"; import { msg, str } from "@lit/localize"; -import { TemplateResult, html } from "lit"; +import { TemplateResult, html, nothing } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; @@ -24,14 +29,25 @@ export class BoundPoliciesList extends Table { @property() target?: string; - @property({ type: Boolean }) - policyOnly = false; + @property({ type: Array }) + allowedTypes: PolicyBindingCheckTarget[] = [ + PolicyBindingCheckTarget.group, + PolicyBindingCheckTarget.user, + PolicyBindingCheckTarget.policy, + ]; + + @property({ type: Array }) + typeNotices: PolicyBindingNotice[] = []; checkbox = true; clearOnRefresh = true; order = "order"; + get allowedTypesLabel(): string { + return this.allowedTypes.map((ct) => PolicyBindingCheckTargetToLabel(ct)).join(" / "); + } + async apiEndpoint(): Promise> { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsList({ ...(await this.defaultEndpointConfig()), @@ -42,7 +58,7 @@ export class BoundPoliciesList extends Table { columns(): TableColumn[] { return [ new TableColumn(msg("Order"), "order"), - new TableColumn(msg("Policy / User / Group")), + new TableColumn(this.allowedTypesLabel), new TableColumn(msg("Enabled"), "enabled"), new TableColumn(msg("Timeout"), "timeout"), new TableColumn(msg("Actions")), @@ -121,7 +137,7 @@ export class BoundPoliciesList extends Table { return [ { key: msg("Order"), value: item.order.toString() }, { - key: msg("Policy / User / Group"), + key: this.allowedTypesLabel, value: this.getPolicyUserGroupRowLabel(item), }, ]; @@ -156,8 +172,9 @@ export class BoundPoliciesList extends Table { `; } diff --git a/web/src/admin/policies/PolicyBindingForm.ts b/web/src/admin/policies/PolicyBindingForm.ts index 8a47135e00d7..b10b9e7df7db 100644 --- a/web/src/admin/policies/PolicyBindingForm.ts +++ b/web/src/admin/policies/PolicyBindingForm.ts @@ -1,3 +1,7 @@ +import { + PolicyBindingCheckTarget, + PolicyBindingCheckTargetToLabel, +} from "@goauthentik/admin/policies/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first, groupBy } from "@goauthentik/common/utils"; import "@goauthentik/components/ak-toggle-group"; @@ -7,7 +11,7 @@ import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; -import { CSSResult } from "lit"; +import { CSSResult, nothing } from "lit"; import { TemplateResult, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; @@ -25,11 +29,7 @@ import { User, } from "@goauthentik/api"; -enum target { - policy = "policy", - group = "group", - user = "user", -} +export type PolicyBindingNotice = { type: PolicyBindingCheckTarget; notice: string }; @customElement("ak-policy-binding-form") export class PolicyBindingForm extends ModelForm { @@ -38,13 +38,13 @@ export class PolicyBindingForm extends ModelForm { policyBindingUuid: pk, }); if (binding?.policyObj) { - this.policyGroupUser = target.policy; + this.policyGroupUser = PolicyBindingCheckTarget.policy; } if (binding?.groupObj) { - this.policyGroupUser = target.group; + this.policyGroupUser = PolicyBindingCheckTarget.group; } if (binding?.userObj) { - this.policyGroupUser = target.user; + this.policyGroupUser = PolicyBindingCheckTarget.user; } this.defaultOrder = await this.getOrder(); return binding; @@ -54,10 +54,17 @@ export class PolicyBindingForm extends ModelForm { targetPk?: string; @state() - policyGroupUser: target = target.policy; + policyGroupUser: PolicyBindingCheckTarget = PolicyBindingCheckTarget.policy; + + @property({ type: Array }) + allowedTypes: PolicyBindingCheckTarget[] = [ + PolicyBindingCheckTarget.group, + PolicyBindingCheckTarget.user, + PolicyBindingCheckTarget.policy, + ]; - @property({ type: Boolean }) - policyOnly = false; + @property({ type: Array }) + typeNotices: PolicyBindingNotice[] = []; @state() defaultOrder = 0; @@ -74,20 +81,26 @@ export class PolicyBindingForm extends ModelForm { return [...super.styles, PFContent]; } + async load(): Promise { + // Overwrite the default for policyGroupUser with the first allowed type, + // as this function is called when the correct parameters are set + this.policyGroupUser = this.allowedTypes[0]; + } + send(data: PolicyBinding): Promise { if (this.targetPk) { data.target = this.targetPk; } switch (this.policyGroupUser) { - case target.policy: + case PolicyBindingCheckTarget.policy: data.user = null; data.group = null; break; - case target.group: + case PolicyBindingCheckTarget.group: data.policy = null; data.user = null; break; - case target.user: + case PolicyBindingCheckTarget.user: data.policy = null; data.group = null; break; @@ -122,13 +135,18 @@ export class PolicyBindingForm extends ModelForm { renderModeSelector(): TemplateResult { return html` ) => { + @ak-toggle=${(ev: CustomEvent<{ value: PolicyBindingCheckTarget }>) => { this.policyGroupUser = ev.detail.value; }} > - - - + ${Object.keys(PolicyBindingCheckTarget).map((ct) => { + if (this.allowedTypes.includes(ct as PolicyBindingCheckTarget)) { + return html``; + } + return nothing; + })} `; } @@ -139,7 +157,7 @@ export class PolicyBindingForm extends ModelForm { { @@ -169,11 +187,16 @@ export class PolicyBindingForm extends ModelForm { ?blankable=${true} > + ${this.typeNotices + .filter(({ type }) => type === PolicyBindingCheckTarget.policy) + .map((msg) => { + return html`

${msg.notice}

`; + })}
=> { @@ -201,18 +224,16 @@ export class PolicyBindingForm extends ModelForm { ?blankable=${true} > - ${this.policyOnly - ? html`

- ${msg( - "Group mappings can only be checked if a user is already logged in when trying to access this source.", - )} -

` - : html``} + ${this.typeNotices + .filter(({ type }) => type === PolicyBindingCheckTarget.group) + .map((msg) => { + return html`

${msg.notice}

`; + })}
=> { @@ -240,13 +261,11 @@ export class PolicyBindingForm extends ModelForm { ?blankable=${true} > - ${this.policyOnly - ? html`

- ${msg( - "User mappings can only be checked if a user is already logged in when trying to access this source.", - )} -

` - : html``} + ${this.typeNotices + .filter(({ type }) => type === PolicyBindingCheckTarget.user) + .map((msg) => { + return html`

${msg.notice}

`; + })}
diff --git a/web/src/admin/policies/utils.ts b/web/src/admin/policies/utils.ts new file mode 100644 index 000000000000..f64e2e9d95f7 --- /dev/null +++ b/web/src/admin/policies/utils.ts @@ -0,0 +1,18 @@ +import { msg } from "@lit/localize"; + +export enum PolicyBindingCheckTarget { + policy = "policy", + group = "group", + user = "user", +} + +export function PolicyBindingCheckTargetToLabel(ct: PolicyBindingCheckTarget): string { + switch (ct) { + case PolicyBindingCheckTarget.group: + return msg("Group"); + case PolicyBindingCheckTarget.user: + return msg("User"); + case PolicyBindingCheckTarget.policy: + return msg("Policy"); + } +} diff --git a/web/src/admin/sources/oauth/OAuthSourceViewPage.ts b/web/src/admin/sources/oauth/OAuthSourceViewPage.ts index 93cf320fdba0..4e7c94b1cb67 100644 --- a/web/src/admin/sources/oauth/OAuthSourceViewPage.ts +++ b/web/src/admin/sources/oauth/OAuthSourceViewPage.ts @@ -2,6 +2,7 @@ import "@goauthentik/admin/policies/BoundPoliciesList"; import "@goauthentik/admin/rbac/ObjectPermissionsPage"; import "@goauthentik/admin/sources/oauth/OAuthSourceDiagram"; import "@goauthentik/admin/sources/oauth/OAuthSourceForm"; +import { sourceBindingTypeNotices } from "@goauthentik/admin/sources/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import "@goauthentik/components/events/ObjectChangelog"; @@ -240,7 +241,10 @@ export class OAuthSourceViewPage extends AKElement { )}
- +
diff --git a/web/src/admin/sources/plex/PlexSourceViewPage.ts b/web/src/admin/sources/plex/PlexSourceViewPage.ts index 3bd0f09b89a8..270faee0d853 100644 --- a/web/src/admin/sources/plex/PlexSourceViewPage.ts +++ b/web/src/admin/sources/plex/PlexSourceViewPage.ts @@ -1,6 +1,7 @@ import "@goauthentik/admin/policies/BoundPoliciesList"; import "@goauthentik/admin/rbac/ObjectPermissionsPage"; import "@goauthentik/admin/sources/plex/PlexSourceForm"; +import { sourceBindingTypeNotices } from "@goauthentik/admin/sources/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import "@goauthentik/components/events/ObjectChangelog"; @@ -130,7 +131,10 @@ export class PlexSourceViewPage extends AKElement { )}
- +
diff --git a/web/src/admin/sources/saml/SAMLSourceViewPage.ts b/web/src/admin/sources/saml/SAMLSourceViewPage.ts index 744f02d60d46..8588500690ea 100644 --- a/web/src/admin/sources/saml/SAMLSourceViewPage.ts +++ b/web/src/admin/sources/saml/SAMLSourceViewPage.ts @@ -1,6 +1,7 @@ import "@goauthentik/admin/policies/BoundPoliciesList"; import "@goauthentik/admin/rbac/ObjectPermissionsPage"; import "@goauthentik/admin/sources/saml/SAMLSourceForm"; +import { sourceBindingTypeNotices } from "@goauthentik/admin/sources/utils"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import "@goauthentik/components/events/ObjectChangelog"; @@ -207,7 +208,10 @@ export class SAMLSourceViewPage extends AKElement { )}
- +
diff --git a/web/src/admin/sources/utils.ts b/web/src/admin/sources/utils.ts index 83ff0b967c07..1ec5ec57e572 100644 --- a/web/src/admin/sources/utils.ts +++ b/web/src/admin/sources/utils.ts @@ -1,3 +1,6 @@ +import { PolicyBindingCheckTarget } from "@goauthentik/admin/policies/utils"; + +import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; export function renderSourceIcon(name: string, iconUrl: string | undefined | null): TemplateResult { @@ -11,3 +14,20 @@ export function renderSourceIcon(name: string, iconUrl: string | undefined | nul } return icon; } + +export function sourceBindingTypeNotices() { + return [ + { + type: PolicyBindingCheckTarget.group, + notice: msg( + "Group mappings can only be checked if a user is already logged in when trying to access this source.", + ), + }, + { + type: PolicyBindingCheckTarget.user, + notice: msg( + "User mappings can only be checked if a user is already logged in when trying to access this source.", + ), + }, + ]; +}