disable readonly languages when publishing

This commit is contained in:
Mads Rasmussen
2024-10-22 10:10:21 +02:00
parent bd16e017b6
commit 2f9068ed09

View File

@@ -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<never> {
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
@@ -25,8 +26,16 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
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<UmbDocumentVariantOptionModel> = documentData.variants.map<UmbDocumentVariantOptionModel>(
(variant) => ({
@@ -76,6 +85,11 @@ export class UmbPublishDocumentEntityAction extends UmbEntityActionBase<never> {
.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 },
})