diff --git a/src/packages/documents/documents/entity-actions/publish.action.ts b/src/packages/documents/documents/entity-actions/publish.action.ts index 1175fd3361..845f47e73d 100644 --- a/src/packages/documents/documents/entity-actions/publish.action.ts +++ b/src/packages/documents/documents/entity-actions/publish.action.ts @@ -8,6 +8,7 @@ import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; +import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'; export class UmbPublishDocumentEntityAction extends UmbEntityActionBase { constructor(host: UmbControllerHost, args: UmbEntityActionArgs) { @@ -25,8 +26,16 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase { if (!documentData) throw new Error('The document was not found'); - const context = await this.getContext(UMB_APP_LANGUAGE_CONTEXT); - const appCulture = context.getAppCulture(); + const appLanguageContext = await this.getContext(UMB_APP_LANGUAGE_CONTEXT); + const appCulture = appLanguageContext.getAppCulture(); + + const currentUserContext = await this.getContext(UMB_CURRENT_USER_CONTEXT); + const currentUserAllowedLanguages = currentUserContext.getLanguages(); + const currentUserHasAccessToAllLanguages = currentUserContext.getHasAccessToAllLanguages(); + + if (currentUserAllowedLanguages === undefined) throw new Error('The current user languages are missing'); + if (currentUserHasAccessToAllLanguages === undefined) + throw new Error('The current user access to all languages is missing'); const options: Array = documentData.variants.map( (variant) => ({ @@ -76,6 +85,11 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase { .open(this, UMB_DOCUMENT_PUBLISH_MODAL, { data: { options, + pickableFilter: (option) => { + if (!option.culture) return false; + if (currentUserHasAccessToAllLanguages) return true; + return currentUserAllowedLanguages.includes(option.culture); + }, }, value: { selection }, }) diff --git a/src/packages/documents/documents/entity-actions/unpublish.action.ts b/src/packages/documents/documents/entity-actions/unpublish.action.ts index ff9d645a17..d0f47c9878 100644 --- a/src/packages/documents/documents/entity-actions/unpublish.action.ts +++ b/src/packages/documents/documents/entity-actions/unpublish.action.ts @@ -11,6 +11,7 @@ import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; +import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'; export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase { constructor(host: UmbControllerHost, args: UmbEntityActionArgs) { @@ -28,8 +29,16 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase if (!documentData) throw new Error('The document was not found'); - const context = await this.getContext(UMB_APP_LANGUAGE_CONTEXT); - const appCulture = context.getAppCulture(); + const appLanguageContext = await this.getContext(UMB_APP_LANGUAGE_CONTEXT); + const appCulture = appLanguageContext.getAppCulture(); + + const currentUserContext = await this.getContext(UMB_CURRENT_USER_CONTEXT); + const currentUserAllowedLanguages = currentUserContext.getLanguages(); + const currentUserHasAccessToAllLanguages = currentUserContext.getHasAccessToAllLanguages(); + + if (currentUserAllowedLanguages === undefined) throw new Error('The current user languages are missing'); + if (currentUserHasAccessToAllLanguages === undefined) + throw new Error('The current user access to all languages is missing'); const options: Array = documentData.variants.map( (variant) => ({ @@ -65,6 +74,11 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase data: { documentUnique: this.args.unique, options, + pickableFilter: (option) => { + if (!option.culture) return false; + if (currentUserHasAccessToAllLanguages) return true; + return currentUserAllowedLanguages.includes(option.culture); + }, }, value: { selection }, }) @@ -89,4 +103,5 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase } } } + export default UmbUnpublishDocumentEntityAction; diff --git a/src/packages/user/current-user/current-user.context.ts b/src/packages/user/current-user/current-user.context.ts index b6836e70b7..d31467cce3 100644 --- a/src/packages/user/current-user/current-user.context.ts +++ b/src/packages/user/current-user/current-user.context.ts @@ -11,6 +11,7 @@ import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registr import { UMB_SECTION_PATH_PATTERN } from '@umbraco-cms/backoffice/section'; import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app'; import { ensurePathEndsWithSlash } from '@umbraco-cms/backoffice/utils'; +import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models'; export class UmbCurrentUserContext extends UmbContextBase { #currentUser = new UmbObjectState(undefined); @@ -83,6 +84,142 @@ export class UmbCurrentUserContext extends UmbContextBase return currentUser?.isAdmin ?? false; } + /** + * Get the allowed sections for the current user + * @returns {Array | undefined} The allowed sections for the current user + */ + getAllowedSection(): Array | undefined { + return this.#currentUser.getValue()?.allowedSections; + } + + /** + * Get the avatar urls for the current user + * @returns {Array | undefined} The avatar urls for the current user + */ + getAvatarUrls(): Array | undefined { + return this.#currentUser.getValue()?.avatarUrls; + } + + /** + * Get the document start node uniques for the current user + * @returns {Array | undefined} The document start node uniques for the current user + */ + getDocumentStartNodeUniques(): Array | undefined { + return this.#currentUser.getValue()?.documentStartNodeUniques; + } + + /** + * Get the email for the current user + * @returns {string | undefined} The email for the current user + */ + getEmail(): string | undefined { + return this.#currentUser.getValue()?.email; + } + + /** + * Get the fallback permissions for the current user + * @returns {Array | undefined} The fallback permissions for the current user + */ + getFallbackPermissions(): Array | undefined { + return this.#currentUser.getValue()?.fallbackPermissions; + } + + /** + * Get if the current user has access to all languages + * @returns {boolean | undefined} True if the current user has access to all languages, otherwise false + */ + getHasAccessToAllLanguages(): boolean | undefined { + return this.#currentUser.getValue()?.hasAccessToAllLanguages; + } + + /** + * Get if the current user has access to sensitive data + * @returns {boolean | undefined} True if the current user has access to sensitive data, otherwise false + */ + getHasAccessToSensitiveData(): boolean | undefined { + return this.#currentUser.getValue()?.hasAccessToSensitiveData; + } + + /** + * Get if the current user has document root access + * @returns {boolean | undefined} True if the current user has document root access, otherwise false + */ + getHasDocumentRootAccess(): boolean | undefined { + return this.#currentUser.getValue()?.hasDocumentRootAccess; + } + + /** + * Get if the current user has media root access + * @returns {boolean | undefined} True if the current user has media root access, otherwise false + */ + getHasMediaRootAccess(): boolean | undefined { + return this.#currentUser.getValue()?.hasMediaRootAccess; + } + + /** + * Get if the current user is an admin + * @returns {boolean | undefined} True if the current user is an admin, otherwise false + */ + getIsAdmin(): boolean | undefined { + return this.#currentUser.getValue()?.isAdmin; + } + + /** + * Get the language iso code for the current user + * @returns {string | undefined} The language iso code for the current user + */ + getLanguageIsoCode(): string | undefined { + return this.#currentUser.getValue()?.languageIsoCode; + } + + /** + * Get the languages for the current user + * @returns {Array | undefined} The languages for the current user + */ + getLanguages(): Array | undefined { + return this.#currentUser.getValue()?.languages; + } + + /** + * Get the media start node uniques for the current user + * @returns {Array | undefined} The media start node uniques for the current user + */ + getMediaStartNodeUniques(): Array | undefined { + return this.#currentUser.getValue()?.mediaStartNodeUniques; + } + + /** + * Get the name for the current user + * @returns {string | undefined} The name for the current user + */ + getName(): string | undefined { + return this.#currentUser.getValue()?.name; + } + + /** + * Get the permissions for the current user + * @returns {Array | undefined} The permissions for the current user + */ + getPermissions() { + return this.#currentUser.getValue()?.permissions; + } + + /** + * Get the unique for the current user + * @returns {string | undefined} The unique for the current user + */ + getUnique(): string | undefined { + return this.#currentUser.getValue()?.unique; + } + + /** + * Get the user name for the current user + * @returns {string | undefined} The user name for the current user + */ + getUserName(): string | undefined { + return this.#currentUser.getValue()?.userName; + } + #observeIsAuthorized() { if (!this.#authContext) return; this.observe(this.#authContext.isAuthorized, (isAuthorized) => {