-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Global Elements: Adds "Element or Element Folder" User Permission Condition #23051
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
Merged
AndyButland
merged 5 commits into
main
from
v18/feature/element-joint-item-folder-conditon
Jul 13, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a761b1
feat(elements): add UmbElementOrElementFolderUserPermissionCondition
leekelleher bf25415
fix(elements): gate element recycle bin on element OR folder read per…
leekelleher 103afff
feat(elements): gate element create modal on element-create permission
leekelleher e87638a
refactor(elements): apply pr review suggestions to element-or-element…
leekelleher 8adfeba
fix(elements): address bot review feedback on element-or-folder permi…
leekelleher 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
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
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
2 changes: 2 additions & 0 deletions
2
src/Umbraco.Web.UI.Client/src/packages/elements/user-permissions/conditions/constants.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 +1,3 @@ | ||
| export const UMB_ELEMENT_USER_PERMISSION_CONDITION_ALIAS = 'Umb.Condition.UserPermission.Element'; | ||
| export const UMB_ELEMENT_OR_ELEMENT_FOLDER_USER_PERMISSION_CONDITION_ALIAS = | ||
| 'Umb.Condition.UserPermission.ElementOrElementFolder'; |
142 changes: 142 additions & 0 deletions
142
...s/user-permissions/conditions/element-or-element-folder-user-permission.condition.test.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,142 @@ | ||
| import { expect } from '@open-wc/testing'; | ||
| import { customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api'; | ||
| import { UmbCurrentUserContext, UmbCurrentUserStore } from '@umbraco-cms/backoffice/current-user'; | ||
| import { UmbNotificationContext } from '@umbraco-cms/backoffice/notification'; | ||
| import { UmbAncestorsEntityContext, UmbEntityContext, type UmbEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
| import { useMockSet } from '@umbraco-cms/internal/mock-manager'; | ||
| import { UmbElementOrElementFolderUserPermissionCondition } from './element-or-element-folder-user-permission.condition.js'; | ||
| import { UMB_ELEMENT_OR_ELEMENT_FOLDER_USER_PERMISSION_CONDITION_ALIAS } from './constants.js'; | ||
| import { UMB_USER_PERMISSION_ELEMENT_READ } from '../constants.js'; | ||
| import { UMB_USER_PERMISSION_ELEMENT_FOLDER_READ } from '../../folder/user-permissions/constants.js'; | ||
| import { UMB_ELEMENT_ENTITY_TYPE } from '../../entity.js'; | ||
|
|
||
| @customElement('test-controller-host-combined-permission') | ||
| class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) { | ||
| currentUserContext = new UmbCurrentUserContext(this); | ||
| entityContext = new UmbEntityContext(this); | ||
| ancestorsContext = new UmbAncestorsEntityContext(this); | ||
|
|
||
| constructor() { | ||
| super(); | ||
| new UmbNotificationContext(this); | ||
| new UmbCurrentUserStore(this); | ||
| } | ||
|
|
||
| async init() { | ||
| await this.currentUserContext.load(); | ||
| } | ||
|
|
||
| setEntity(entity: UmbEntityModel) { | ||
| this.entityContext.setUnique(entity.unique); | ||
| this.entityContext.setEntityType(entity.entityType); | ||
| } | ||
|
|
||
| setEntityAncestors(ancestors: Array<UmbEntityModel>) { | ||
| this.ancestorsContext.setAncestors(ancestors); | ||
| } | ||
| } | ||
|
|
||
| const CONDITION_CONFIG = { | ||
| alias: UMB_ELEMENT_OR_ELEMENT_FOLDER_USER_PERMISSION_CONDITION_ALIAS, | ||
| element: { allOf: [UMB_USER_PERMISSION_ELEMENT_READ] }, | ||
| folder: { allOf: [UMB_USER_PERMISSION_ELEMENT_FOLDER_READ] }, | ||
| }; | ||
|
|
||
| describe('UmbElementOrElementFolderUserPermissionCondition', () => { | ||
| let hostElement: UmbTestControllerHostElement; | ||
| let condition: UmbElementOrElementFolderUserPermissionCondition; | ||
|
|
||
| before(async () => { | ||
| await useMockSet('userPermissions'); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| hostElement = new UmbTestControllerHostElement(); | ||
| document.body.appendChild(hostElement); | ||
| await hostElement.init(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| describe('Element read only', () => { | ||
| it('should be permitted when user has element read but not folder read', (done) => { | ||
| hostElement.setEntity({ unique: 'permissions-element-read-only-id', entityType: UMB_ELEMENT_ENTITY_TYPE }); | ||
| hostElement.setEntityAncestors([]); | ||
|
|
||
| condition = new UmbElementOrElementFolderUserPermissionCondition(hostElement, { | ||
| host: hostElement, | ||
| config: CONDITION_CONFIG, | ||
| onChange: () => { | ||
| expect(condition.permitted).to.be.true; | ||
| condition.hostDisconnected(); | ||
| done(); | ||
| }, | ||
| }); | ||
| }); | ||
|
Check warning on line 78 in src/Umbraco.Web.UI.Client/src/packages/elements/user-permissions/conditions/element-or-element-folder-user-permission.condition.test.ts
|
||
| }); | ||
|
|
||
| describe('Folder read only', () => { | ||
| it('should be permitted when user has folder read but not element read', (done) => { | ||
| hostElement.setEntity({ unique: 'permissions-folder-read-only-id', entityType: UMB_ELEMENT_ENTITY_TYPE }); | ||
| hostElement.setEntityAncestors([]); | ||
|
|
||
| condition = new UmbElementOrElementFolderUserPermissionCondition(hostElement, { | ||
| host: hostElement, | ||
| config: CONDITION_CONFIG, | ||
| onChange: () => { | ||
| expect(condition.permitted).to.be.true; | ||
| condition.hostDisconnected(); | ||
| done(); | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Both read', () => { | ||
| it('should be permitted when user has both element read and folder read', (done) => { | ||
| hostElement.setEntity({ unique: 'permissions-both-read-id', entityType: UMB_ELEMENT_ENTITY_TYPE }); | ||
| hostElement.setEntityAncestors([]); | ||
|
|
||
| condition = new UmbElementOrElementFolderUserPermissionCondition(hostElement, { | ||
| host: hostElement, | ||
| config: CONDITION_CONFIG, | ||
| onChange: () => { | ||
| expect(condition.permitted).to.be.true; | ||
| condition.hostDisconnected(); | ||
| done(); | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Neither read', () => { | ||
| it('should not be permitted when user has neither element read nor folder read', (done) => { | ||
| hostElement.setEntity({ unique: 'permissions-neither-read-id', entityType: UMB_ELEMENT_ENTITY_TYPE }); | ||
| hostElement.setEntityAncestors([]); | ||
|
|
||
| condition = new UmbElementOrElementFolderUserPermissionCondition(hostElement, { | ||
| host: hostElement, | ||
| config: CONDITION_CONFIG, | ||
| onChange: () => { | ||
| // onChange fires only when permitted transitions; if it ever transitions to true that is a failure | ||
| if (condition.permitted) { | ||
| condition.hostDisconnected(); | ||
| done(new Error('Expected condition to remain not permitted')); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| // Safe to assert after 200ms: mock contexts resolve synchronously, so both | ||
| // sub-conditions have evaluated well within this window. The initial default | ||
| // is also false, so a pass here confirms the condition never became true. | ||
| setTimeout(() => { | ||
| expect(condition.permitted).to.be.false; | ||
| condition.hostDisconnected(); | ||
| done(); | ||
|
leekelleher marked this conversation as resolved.
|
||
| }, 200); | ||
| }); | ||
| }); | ||
| }); | ||
46 changes: 46 additions & 0 deletions
46
...ements/user-permissions/conditions/element-or-element-folder-user-permission.condition.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,46 @@ | ||
| import type { UmbElementOrElementFolderUserPermissionConditionConfig } from './types.js'; | ||
| import { UMB_ELEMENT_USER_PERMISSION_CONDITION_ALIAS } from './constants.js'; | ||
| import { UmbElementUserPermissionCondition } from './element-user-permission.condition.js'; | ||
| import { UmbElementFolderUserPermissionCondition } from '../../folder/user-permissions/conditions/element-folder-user-permission.condition.js'; | ||
| import { UMB_ELEMENT_FOLDER_USER_PERMISSION_CONDITION_ALIAS } from '../../folder/user-permissions/conditions/constants.js'; | ||
| import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry'; | ||
| import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
|
|
||
| /** Permits when the user has the configured element OR element folder (container) permissions. */ | ||
| export class UmbElementOrElementFolderUserPermissionCondition | ||
| extends UmbConditionBase<UmbElementOrElementFolderUserPermissionConditionConfig> | ||
| implements UmbExtensionCondition | ||
| { | ||
| #elementCondition: UmbElementUserPermissionCondition | undefined; | ||
| #folderCondition: UmbElementFolderUserPermissionCondition | undefined; | ||
|
|
||
| constructor( | ||
| host: UmbControllerHost, | ||
| args: UmbConditionControllerArguments<UmbElementOrElementFolderUserPermissionConditionConfig>, | ||
| ) { | ||
| super(host, args); | ||
|
|
||
| if (this.config.element) { | ||
| this.#elementCondition = new UmbElementUserPermissionCondition(this, { | ||
| host: this, | ||
| config: { alias: UMB_ELEMENT_USER_PERMISSION_CONDITION_ALIAS, ...this.config.element }, | ||
| onChange: () => this.#evaluate(), | ||
| }); | ||
| } | ||
|
|
||
| if (this.config.folder) { | ||
| this.#folderCondition = new UmbElementFolderUserPermissionCondition(this, { | ||
| host: this, | ||
| config: { alias: UMB_ELEMENT_FOLDER_USER_PERMISSION_CONDITION_ALIAS, ...this.config.folder }, | ||
| onChange: () => this.#evaluate(), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #evaluate() { | ||
| this.permitted = (this.#elementCondition?.permitted ?? false) || (this.#folderCondition?.permitted ?? false); | ||
| } | ||
|
leekelleher marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export { UmbElementOrElementFolderUserPermissionCondition as api }; | ||
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/elements/user-permissions/conditions/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 +1,2 @@ | ||
| export { UmbElementOrElementFolderUserPermissionCondition } from './element-or-element-folder-user-permission.condition.js'; | ||
| export { UmbElementUserPermissionCondition } from './element-user-permission.condition.js'; |
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.