Files
authentik/web/src/admin/groups/RelatedGroupList.ts
Ken Sternberg dd625d57df Merge branch 'main' into web/add-htmltagmaps-to-activate-lit-analyzer
* main: (213 commits)
  website/docs: configuration: fix typo in kubectl command (#10492)
  website/integrations: fix typo in minio instructions (#10500)
  web: bump @typescript-eslint/eslint-plugin from 7.5.0 to 7.16.0 in /tests/wdio (#10496)
  website: bump prettier from 3.3.2 to 3.3.3 in /website (#10493)
  core: bump ruff from 0.5.1 to 0.5.2 (#10494)
  web: bump @typescript-eslint/parser from 7.5.0 to 7.16.0 in /tests/wdio (#10495)
  web: bump eslint-plugin-sonarjs from 0.25.1 to 1.0.3 in /tests/wdio (#10498)
  web: bump prettier from 3.3.2 to 3.3.3 in /tests/wdio (#10497)
  web: bump pseudolocale from 2.0.0 to 2.1.0 in /web (#10499)
  core: bump goauthentik.io/api/v3 from 3.2024061.1 to 3.2024061.2 (#10491)
  web: bump API Client version (#10488)
  flows: remove stage challenge type (#10476)
  core: bump github.com/redis/go-redis/v9 from 9.5.3 to 9.5.4 (#10469)
  core: bump goauthentik.io/api/v3 from 3.2024060.6 to 3.2024061.1 (#10470)
  web: bump the babel group across 1 directory with 2 updates (#10471)
  web: bump the storybook group across 1 directory with 7 updates (#10472)
  core: bump coverage from 7.5.4 to 7.6.0 (#10473)
  website/docs: air gapped: clarify .env usage at the top for Kubernetes installations (#10447)
  website/docs: air gapped: update "see configuration" wording (#10448)
  website/docs: Add Kubernetes Bootstrap Instructions (#9541)
  ...
2024-07-15 08:07:38 -07:00

193 lines
7.2 KiB
TypeScript

import "@goauthentik/admin/groups/GroupForm";
import "@goauthentik/admin/groups/GroupForm";
import "@goauthentik/admin/users/GroupSelectModal";
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import "@goauthentik/components/ak-status-label";
import "@goauthentik/elements/buttons/SpinnerButton";
import "@goauthentik/elements/forms/DeleteBulkForm";
import { Form } from "@goauthentik/elements/forms/Form";
import "@goauthentik/elements/forms/HorizontalFormElement";
import "@goauthentik/elements/forms/ModalForm";
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
import { msg, str } from "@lit/localize";
import { TemplateResult, html } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { CoreApi, Group, User } from "@goauthentik/api";
@customElement("ak-group-related-add")
export class RelatedGroupAdd extends Form<{ groups: string[] }> {
@property({ attribute: false })
user?: User;
@state()
groupsToAdd: Group[] = [];
getSuccessMessage(): string {
return msg("Successfully added user to group(s).");
}
async send(data: { groups: string[] }): Promise<unknown> {
await Promise.all(
data.groups.map((group) => {
return new CoreApi(DEFAULT_CONFIG).coreGroupsAddUserCreate({
groupUuid: group,
userAccountRequest: {
pk: this.user?.pk || 0,
},
});
}),
);
return data;
}
renderForm(): TemplateResult {
return html`<ak-form-element-horizontal label=${msg("Groups to add")} name="groups">
<div class="pf-c-input-group">
<ak-user-group-select-table
.confirm=${(items: Group[]) => {
this.groupsToAdd = items;
this.requestUpdate();
return Promise.resolve();
}}
>
<button slot="trigger" class="pf-c-button pf-m-control" type="button">
<pf-tooltip position="top" content=${msg("Add group")}>
<i class="fas fa-plus" aria-hidden="true"></i>
</pf-tooltip>
</button>
</ak-user-group-select-table>
<div class="pf-c-form-control">
<ak-chip-group>
${this.groupsToAdd.map((group) => {
return html`<ak-chip
.removable=${true}
value=${ifDefined(group.pk)}
@remove=${() => {
const idx = this.groupsToAdd.indexOf(group);
this.groupsToAdd.splice(idx, 1);
this.requestUpdate();
}}
>
${group.name}
</ak-chip>`;
})}
</ak-chip-group>
</div>
</div>
</ak-form-element-horizontal>`;
}
}
@customElement("ak-group-related-list")
export class RelatedGroupList extends Table<Group> {
checkbox = true;
clearOnRefresh = true;
searchEnabled(): boolean {
return true;
}
@property()
order = "name";
@property({ attribute: false })
targetUser?: User;
async apiEndpoint(): Promise<PaginatedResponse<Group>> {
return new CoreApi(DEFAULT_CONFIG).coreGroupsList({
...(await this.defaultEndpointConfig()),
membersByPk: this.targetUser ? [this.targetUser.pk] : [],
includeUsers: false,
});
}
columns(): TableColumn[] {
return [
new TableColumn(msg("Name"), "name"),
new TableColumn(msg("Parent"), "parent"),
new TableColumn(msg("Superuser privileges?")),
new TableColumn(msg("Actions")),
];
}
renderToolbarSelected(): TemplateResult {
const disabled = this.selectedElements.length < 1;
return html`<ak-forms-delete-bulk
objectLabel=${msg("Group(s)")}
actionLabel=${msg("Remove from Group(s)")}
actionSubtext=${msg(
str`Are you sure you want to remove user ${this.targetUser?.username} from the following groups?`,
)}
buttonLabel=${msg("Remove")}
.objects=${this.selectedElements}
.delete=${(item: Group) => {
if (!this.targetUser) return;
return new CoreApi(DEFAULT_CONFIG).coreGroupsRemoveUserCreate({
groupUuid: item.pk,
userAccountRequest: {
pk: this.targetUser?.pk || 0,
},
});
}}
>
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
${msg("Remove")}
</button>
</ak-forms-delete-bulk>`;
}
row(item: Group): TemplateResult[] {
return [
html`<a href="#/identity/groups/${item.pk}">${item.name}</a>`,
html`${item.parentName || msg("-")}`,
html`<ak-label type="info" ?good=${item.isSuperuser}></ak-label>`,
html` <ak-forms-modal>
<span slot="submit"> ${msg("Update")} </span>
<span slot="header"> ${msg("Update Group")} </span>
<ak-group-form slot="form" .instancePk=${item.pk}> </ak-group-form>
<button slot="trigger" class="pf-c-button pf-m-plain">
<pf-tooltip position="top" content=${msg("Edit")}>
<i class="fas fa-edit"></i>
</pf-tooltip>
</button>
</ak-forms-modal>`,
];
}
renderToolbar(): TemplateResult {
return html`
${this.targetUser
? html`<ak-forms-modal>
<span slot="submit"> ${msg("Add")} </span>
<span slot="header"> ${msg("Add Group")} </span>
<ak-group-related-add .user=${this.targetUser} slot="form">
</ak-group-related-add>
<button slot="trigger" class="pf-c-button pf-m-primary">
${msg("Add to existing group")}
</button>
</ak-forms-modal>`
: html``}
<ak-forms-modal>
<span slot="submit"> ${msg("Create")} </span>
<span slot="header"> ${msg("Create Group")} </span>
<ak-group-form slot="form"> </ak-group-form>
<button slot="trigger" class="pf-c-button pf-m-secondary">
${msg("Add new group")}
</button>
</ak-forms-modal>
${super.renderToolbar()}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"ak-group-related-list": RelatedGroupList;
"ak-group-related-add": RelatedGroupAdd;
}
}