Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export interface ManifestUserPermission extends ManifestBase {
}

export interface MetaUserPermission {
label: string;
entityType: string;
label?: string;
labelKey?: string;
description?: string;
descriptionKey?: string;
group?: string;
}
64 changes: 32 additions & 32 deletions src/packages/documents/documents/user-permissions/manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Read Document User Permission',
meta: {
entityType: 'document',
label: 'Read',
description: 'Allow access to browse documents',
labelKey: 'actions_browse',
descriptionKey: 'actionDescriptions_browse',
},
},
{
Expand All @@ -37,8 +37,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Create Document Blueprint User Permission',
meta: {
entityType: 'document',
label: 'Create Content Template',
description: 'Allow access to create a Content Template',
labelKey: 'actions_createblueprint',
descriptionKey: 'actionDescriptions_createblueprint',
},
},
{
Expand All @@ -47,8 +47,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Delete Document User Permission',
meta: {
entityType: 'document',
label: 'Delete',
description: 'Allow access to delete a document',
labelKey: 'actions_delete',
descriptionKey: 'actionDescriptions_delete',
},
},
{
Expand All @@ -57,8 +57,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Create Document User Permission',
meta: {
entityType: 'document',
label: 'Create',
description: 'Allow access to create a document',
labelKey: 'actions_create',
descriptionKey: 'actionDescriptions_create',
},
},
{
Expand All @@ -67,8 +67,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Document Notifications User Permission',
meta: {
entityType: 'document',
label: 'Notifications',
description: 'Allow access to setup notifications for documents',
labelKey: 'actions_notify',
descriptionKey: 'actionDescriptions_notify',
},
},
{
Expand All @@ -77,8 +77,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Publish Document User Permission',
meta: {
entityType: 'document',
label: 'Publish',
description: 'Allow access to publish a document',
labelKey: 'actions_publish',
descriptionKey: 'actionDescriptions_publish',
},
},
{
Expand All @@ -87,8 +87,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Document Permissions User Permission',
meta: {
entityType: 'document',
label: 'Permissions',
description: 'Allow access to change permissions for a document',
labelKey: 'actions_setPermissions',
descriptionKey: 'actionDescriptions_rights',
},
},
{
Expand All @@ -97,8 +97,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Send Document For Approval User Permission',
meta: {
entityType: 'document',
label: 'Send For Approval',
description: 'Allow access to send a document for approval before publishing',
labelKey: 'actions_sendtopublish',
descriptionKey: 'actionDescriptions_sendtopublish',
},
},
{
Expand All @@ -107,8 +107,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Unpublish Document User Permission',
meta: {
entityType: 'document',
label: 'Unpublish',
description: 'Allow access to unpublish a document',
labelKey: 'actions_unpublish',
descriptionKey: 'actionDescriptions_unpublish',
},
},
{
Expand All @@ -117,8 +117,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Update Document User Permission',
meta: {
entityType: 'document',
label: 'Update',
description: 'Allow access to save a document',
labelKey: 'actions_update',
descriptionKey: 'actionDescriptions_update',
},
},
{
Expand All @@ -127,8 +127,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Copy Document User Permission',
meta: {
entityType: 'document',
label: 'Copy',
description: 'Allow access to copy a document',
labelKey: 'actions_copy',
descriptionKey: 'actionDescriptions_copy',
group: 'structure',
},
},
Expand All @@ -138,8 +138,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Move Document User Permission',
meta: {
entityType: 'document',
label: 'Move',
description: 'Allow access to move a document',
labelKey: 'actions_move',
descriptionKey: 'actionDescriptions_move',
group: 'structure',
},
},
Expand All @@ -149,8 +149,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Sort Document User Permission',
meta: {
entityType: 'document',
label: 'Sort',
description: 'Allow access to sort documents',
labelKey: 'actions_sort',
descriptionKey: 'actionDescriptions_sort',
group: 'structure',
},
},
Expand All @@ -160,8 +160,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Document Culture And Hostnames User Permission',
meta: {
entityType: 'document',
label: 'Culture And Hostnames',
description: 'Allow access to set culture and hostnames for documents',
labelKey: 'actions_assigndomain',
descriptionKey: 'actionDescriptions_assignDomain',
group: 'administration',
},
},
Expand All @@ -171,8 +171,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Document Public Access User Permission',
meta: {
entityType: 'document',
label: 'Public Access',
description: 'Allow access to set and change access restrictions for a document',
labelKey: 'actions_protect',
descriptionKey: 'actionDescriptions_protect',
group: 'administration',
},
},
Expand All @@ -182,8 +182,8 @@ const permissions: Array<ManifestUserPermission> = [
name: 'Document Rollback User Permission',
meta: {
entityType: 'document',
label: 'Rollback',
description: 'Allow access to roll back a document to a previous state',
labelKey: 'actions_rollback',
descriptionKey: 'actionDescriptions_rollback',
group: 'administration',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UMB_USER_GROUP_WORKSPACE_CONTEXT } from '../user-group-workspace.context.js';
import { html, customElement, state, ifDefined } from '@umbraco-cms/backoffice/external/lit';
import { html, customElement, state, ifDefined, nothing } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
import { UserGroupResponseModel } from '@umbraco-cms/backoffice/backend-api';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { ManifestUserPermission, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
import { groupBy } from '@umbraco-cms/backoffice/external/lodash';
import { UmbChangeEvent } from '@umbraco-cms/backoffice/events';
import { type UmbUserPermissionSettingElement } from '@umbraco-cms/backoffice/users';
import { groupBy } from '@umbraco-cms/backoffice/external/lodash';

@customElement('umb-user-group-default-permission-list')
export class UmbUserGroupDefaultPermissionListElement extends UmbLitElement {
Expand Down Expand Up @@ -47,26 +47,43 @@ export class UmbUserGroupDefaultPermissionListElement extends UmbLitElement {
: this.#userGroupWorkspaceContext?.removePermission(userPermissionManifest.alias);
}

#isAllowed(userPermissionManifest: ManifestUserPermission) {
return this._userGroup?.permissions?.includes(userPermissionManifest.alias);
#isAllowed(permissionAlias: string) {
return this._userGroup?.permissions?.includes(permissionAlias);
}

render() {
return html` ${this._entityTypes.map((entityType) => this.#renderPermissionsForEntityType(entityType))} `;
return html` ${this._entityTypes.map((entityType) => this.#renderPermissionsByEntityType(entityType))} `;
}

#renderPermissionsByEntityType(entityType: string) {
const permissionsForEntityType = this._manifests.filter((manifest) => manifest.meta.entityType === entityType);
return html`
<h4><umb-localize .key=${`user_permissionsEntityGroup_${entityType}`}>${entityType}</umb-localize></h4>
${this.#renderGroupedPermissions(permissionsForEntityType)}
`;
}

#renderPermissionsForEntityType(entityType: string) {
return html` <h4><umb-localize .key=${`user_permissionsEntityGroup_${entityType}`}>${entityType}</umb-localize></h4>
${this._manifests
.filter((manifest) => manifest.meta.entityType === entityType)
.map((manifest) => this.#renderPermission(manifest))}`;
#renderGroupedPermissions(permissions: Array<ManifestUserPermission>) {
const groupedPermissions = groupBy(permissions, (manifest) => manifest.meta.group);
return html`
${Object.entries(groupedPermissions).map(
([group, manifests]) => html`
${group !== 'undefined'
? html` <h5><umb-localize .key=${`actionCategories_${group}`}>${group}</umb-localize></h5> `
: nothing}
${manifests.map((manifest) => html` ${this.#renderPermission(manifest)} `)}
`,
)}
`;
}

#renderPermission(manifest: ManifestUserPermission) {
return html` <umb-user-permission-setting
label=${manifest.meta.label}
description=${ifDefined(manifest.meta.description)}
?allowed=${this.#isAllowed(manifest)}
label=${ifDefined(manifest.meta.labelKey ? this.localize.term(manifest.meta.labelKey) : manifest.meta.label)}
description=${ifDefined(
manifest.meta.descriptionKey ? this.localize.term(manifest.meta.descriptionKey) : manifest.meta.description,
)}
?allowed=${this.#isAllowed(manifest.alias)}
@change=${(event: UmbChangeEvent) =>
this.#onChangeUserPermission(event, manifest)}></umb-user-permission-setting>`;
}
Expand Down