-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add third-party permissions section to user group workspace #19777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nathanwoulfe
wants to merge
6
commits into
main
Choose a base branch
from
feature/extend-group-permissions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+350
−135
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d709eda
adds new third-party permissions section to user group workspace
nathanwoulfe 8b5722c
Merge branch 'main' into feature/extend-group-permissions
nathanwoulfe 23b4421
lint
nathanwoulfe fa17641
Merge branch 'feature/extend-group-permissions' of https://github.com…
nathanwoulfe 9ac7630
lint
nathanwoulfe cc2e43e
Merge branch 'main' into feature/extend-group-permissions
nathanwoulfe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...ser-group/workspace/user-group/components/user-group-extension-permission-list.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { customElement, html, nothing, state } from '@umbraco-cms/backoffice/external/lit'; | ||
import type { | ||
ManifestExtensionPermissions, | ||
ManifestExtensionUserPermission, | ||
} from '@umbraco-cms/backoffice/user-permission'; | ||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api'; | ||
import { UmbUserGroupPermissionsListBaseElement } from './user-group-permission-list-base.element.js'; | ||
|
||
@customElement('umb-user-group-extension-permission-list') | ||
export class UmbUserGroupExtensionPermissionsListElement extends UmbUserGroupPermissionsListBaseElement { | ||
@state() | ||
private _manifests?: ManifestExtensionUserPermission[]; | ||
|
||
@state() | ||
private _extensionElements = new Map<string, HTMLElement>(); | ||
|
||
@state() | ||
private _extensions?: ManifestExtensionPermissions[]; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.#observeExtensionPermissions(); | ||
this.#observeEntityUserPermissions(); | ||
} | ||
|
||
#observeExtensionPermissions() { | ||
this.observe( | ||
umbExtensionsRegistry.byType('extensionPermissions'), | ||
async (manifests) => { | ||
this._extensions = manifests; | ||
|
||
// Pre-create extension elements for each manifest | ||
for (const manifest of manifests) { | ||
if (!manifest.element && !manifest.js) continue; | ||
const element = await createExtensionElement(manifest); | ||
|
||
if (element) { | ||
this._extensionElements.set(manifest.meta.extensionAlias, element); | ||
} | ||
} | ||
this.requestUpdate('_extensionElements'); | ||
}, | ||
'umbExtensionPermissionsObserver', | ||
); | ||
} | ||
|
||
#observeEntityUserPermissions() { | ||
this.observe( | ||
umbExtensionsRegistry.byType('extensionUserPermission'), | ||
(manifests) => (this._manifests = manifests), | ||
'umbExtensionUserPermissionsObserver', | ||
); | ||
} | ||
|
||
#groupPermissionsForExtension(manifests: ManifestExtensionUserPermission[]) { | ||
const entityTypes = [...new Set(manifests.flatMap((manifest) => manifest.forEntityTypes))]; | ||
|
||
return entityTypes | ||
.map((entityType) => ({ | ||
entityType, | ||
headline: this.localize.term(`user_permissionsEntityGroup_${entityType}`), | ||
})) | ||
.sort((a, b) => a.headline.localeCompare(b.headline)); | ||
} | ||
|
||
#renderProperty(manifest: ManifestExtensionPermissions) { | ||
const label = manifest.meta.labelKey ? this.localize.term(manifest.meta.labelKey) : manifest.meta.label; | ||
const description = manifest.meta.descriptionKey | ||
? this.localize.term(manifest.meta.descriptionKey) | ||
: manifest.meta.description; | ||
|
||
const permissions = this._manifests?.filter((x) => x.forExtension === manifest.meta.extensionAlias) || []; | ||
const groupedPermissions = this.#groupPermissionsForExtension(permissions); | ||
|
||
return html` | ||
<umb-property-layout .label=${label || ''} .description=${description || ''}> | ||
<div slot="editor"> | ||
${this._extensionElements.get(manifest.meta.extensionAlias)} | ||
${groupedPermissions.map( | ||
(group) => | ||
html` <h4>${group.headline}</h4> | ||
<umb-input-extension-user-permission | ||
.forExtension=${manifest.meta.extensionAlias} | ||
.entityType=${group.entityType} | ||
.allowedVerbs=${this._fallBackPermissions || []} | ||
@change=${this.onPermissionChange}></umb-input-extension-user-permission>`, | ||
)} | ||
</div> | ||
</umb-property-layout> | ||
`; | ||
} | ||
|
||
override render() { | ||
if (!this._extensions) return nothing; | ||
|
||
return html`${this._extensions.map((extension) => this.#renderProperty(extension))}`; | ||
} | ||
} | ||
|
||
export default UmbUserGroupExtensionPermissionsListElement; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-user-group-extension-permission-list': UmbUserGroupExtensionPermissionsListElement; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ser/user-group/workspace/user-group/components/user-group-permission-list-base.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { html, state } from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
import { UMB_USER_GROUP_WORKSPACE_CONTEXT } from '../user-group-workspace.context-token.js'; | ||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; | ||
import type { UmbSelectionChangeEvent } from '@umbraco-cms/backoffice/event'; | ||
|
||
export abstract class UmbUserGroupPermissionsListBaseElement extends UmbLitElement { | ||
protected userGroupWorkspaceContext?: typeof UMB_USER_GROUP_WORKSPACE_CONTEXT.TYPE; | ||
|
||
@state() | ||
protected _fallBackPermissions?: Array<string>; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.consumeContext(UMB_USER_GROUP_WORKSPACE_CONTEXT, (instance) => { | ||
this.userGroupWorkspaceContext = instance; | ||
this.observe( | ||
this.userGroupWorkspaceContext?.fallbackPermissions, | ||
(fallbackPermissions) => { | ||
this._fallBackPermissions = fallbackPermissions; | ||
}, | ||
'umbUserGroupFallbackPermissionsObserver', | ||
); | ||
}); | ||
} | ||
|
||
protected renderPermissionsForEntityType(group: { entityType: string; headline: string }) { | ||
return html` | ||
<h4>${group.headline}</h4> | ||
<umb-input-entity-user-permission | ||
.entityType=${group.entityType} | ||
.allowedVerbs=${this._fallBackPermissions || []} | ||
@change=${this.onPermissionChange}></umb-input-entity-user-permission> | ||
`; | ||
} | ||
|
||
protected onPermissionChange(event: UmbSelectionChangeEvent) { | ||
event.stopPropagation(); | ||
const target = event.target as any; | ||
const verbs = target.allowedVerbs; | ||
|
||
if (verbs === undefined || verbs === null) throw new Error('The verbs are not defined'); | ||
|
||
this.userGroupWorkspaceContext?.setFallbackPermissions(verbs); | ||
} | ||
|
||
static override styles = [UmbTextStyles]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/Umbraco.Web.UI.Client/src/packages/user/user-permission/components/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import './input-entity-user-permission/input-entity-user-permission.element.js'; | ||
import './input-user-permission-verb/input-user-permission-verb.element.js'; | ||
import './input-extension-user-permission/input-extension-user-permission.element.js'; | ||
import './input-user-permission-base.element.js'; | ||
|
||
export * from './input-entity-user-permission/input-entity-user-permission.element.js'; | ||
export * from './input-user-permission-verb/input-user-permission-verb.element.js'; | ||
export * from './input-extension-user-permission/input-extension-user-permission.element.js'; | ||
export * from './input-user-permission-base.element.js'; |
110 changes: 7 additions & 103 deletions
110
...ermission/components/input-entity-user-permission/input-entity-user-permission.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.