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
18 changes: 16 additions & 2 deletions src/packages/documents/documents/entity-actions/publish.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand All @@ -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) => ({
Expand Down Expand Up @@ -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 },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<never> {
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<never>) {
Expand All @@ -28,8 +29,16 @@ export class UmbUnpublishDocumentEntityAction 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) => ({
Expand Down Expand Up @@ -65,6 +74,11 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase<never>
data: {
documentUnique: this.args.unique,
options,
pickableFilter: (option) => {
if (!option.culture) return false;
if (currentUserHasAccessToAllLanguages) return true;
return currentUserAllowedLanguages.includes(option.culture);
},
},
value: { selection },
})
Expand All @@ -89,4 +103,5 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase<never>
}
}
}

export default UmbUnpublishDocumentEntityAction;
137 changes: 137 additions & 0 deletions src/packages/user/current-user/current-user.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UmbCurrentUserContext> {
#currentUser = new UmbObjectState<UmbCurrentUserModel | undefined>(undefined);
Expand Down Expand Up @@ -83,6 +84,142 @@ export class UmbCurrentUserContext extends UmbContextBase<UmbCurrentUserContext>
return currentUser?.isAdmin ?? false;
}

/**
* Get the allowed sections for the current user
* @returns {Array<string> | undefined} The allowed sections for the current user
*/
getAllowedSection(): Array<string> | undefined {
return this.#currentUser.getValue()?.allowedSections;
}

/**
* Get the avatar urls for the current user
* @returns {Array<string> | undefined} The avatar urls for the current user
*/
getAvatarUrls(): Array<string> | undefined {
return this.#currentUser.getValue()?.avatarUrls;
}

/**
* Get the document start node uniques for the current user
* @returns {Array<UmbReferenceByUnique> | undefined} The document start node uniques for the current user
*/
getDocumentStartNodeUniques(): Array<UmbReferenceByUnique> | 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<string> | undefined} The fallback permissions for the current user
*/
getFallbackPermissions(): Array<string> | 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<string> | undefined} The languages for the current user
*/
getLanguages(): Array<string> | undefined {
return this.#currentUser.getValue()?.languages;
}

/**
* Get the media start node uniques for the current user
* @returns {Array<UmbReferenceByUnique> | undefined} The media start node uniques for the current user
*/
getMediaStartNodeUniques(): Array<UmbReferenceByUnique> | 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<DocumentPermissionPresentationModel | UnknownTypePermissionPresentationModel> | 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) => {
Expand Down
Loading