Skip to content
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

Move User Permission Conditions #2293

Merged
merged 2 commits into from
Sep 13, 2024
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
6 changes: 1 addition & 5 deletions src/packages/core/extension-registry/conditions/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { CollectionAliasConditionConfig } from '../../collection/collection-alias.manifest.js';
import type { CollectionBulkActionPermissionConditionConfig } from '../../collection/collection-bulk-action-permission.manifest.js';
import type { UmbSectionUserPermissionConditionConfig } from '../../section/conditions/index.js';
import type { SectionAliasConditionConfig } from './section-alias.condition.js';
import type { SwitchConditionConfig } from './switch.condition.js';
import type { UmbMultipleAppLanguageConditionConfig } from './multiple-app-languages.condition.js';
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';
import type { UmbDocumentUserPermissionConditionConfig } from '@umbraco-cms/backoffice/document';

// temp location to avoid circular dependencies
export type BlockWorkspaceHasSettingsConditionConfig =
Expand All @@ -21,10 +19,8 @@ export type ConditionTypes =
| CollectionBulkActionPermissionConditionConfig
| SectionAliasConditionConfig
| SwitchConditionConfig
| UmbConditionConfigBase
| UmbDocumentUserPermissionConditionConfig
| UmbMultipleAppLanguageConditionConfig
| UmbSectionUserPermissionConditionConfig;
| UmbConditionConfigBase;

type UnionOfProperties<T> = T extends object ? T[keyof T] : never;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { UmbSectionUserPermissionConditionConfig } from './types.js';
import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type {
UmbConditionConfigBase,
UmbConditionControllerArguments,
UmbExtensionCondition,
} from '@umbraco-cms/backoffice/extension-api';
import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';

export class UmbSectionUserPermissionCondition extends UmbControllerBase implements UmbExtensionCondition {
Expand All @@ -31,12 +28,9 @@ export class UmbSectionUserPermissionCondition extends UmbControllerBase impleme
}
}

export type UmbSectionUserPermissionConditionConfig = UmbConditionConfigBase<'Umb.Condition.SectionUserPermission'> & {
/**
*
*
* @example
* "Umb.Section.Content"
*/
match: string;
export const manifest = {
type: 'condition',
name: 'Section User Permission Condition',
alias: 'Umb.Condition.SectionUserPermission',
api: UmbSectionUserPermissionCondition,
};
17 changes: 17 additions & 0 deletions src/packages/core/section/conditions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';

export type UmbSectionUserPermissionConditionConfig = UmbConditionConfigBase<'Umb.Condition.SectionUserPermission'> & {
/**
*
*
* @example
* "Umb.Section.Content"
*/
match: string;
};

declare global {
interface UmbExtensionConditionMap {
UmbSectionUserPermissionConditionConfig: UmbSectionUserPermissionConditionConfig;
}
}
1 change: 1 addition & 0 deletions src/packages/core/section/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './section-sidebar-menu-with-entity-actions/index.js';
export * from './section-sidebar-menu/index.js';
export * from './section-sidebar/index.js';
export * from './section.context.js';
export type * from './types.js';
12 changes: 3 additions & 9 deletions src/packages/core/section/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { UmbSectionUserPermissionCondition } from './conditions/section-user-permission.condition.js';
import { manifest as sectionUserPermissionConditionManifest } from './conditions/section-user-permission.condition.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

export const manifests: Array<ManifestTypes> = [
export const manifests: Array<UmbExtensionManifest> = [
{
type: 'modal',
alias: 'Umb.Modal.SectionPicker',
name: 'Section Picker Modal',
element: () => import('./section-picker-modal/section-picker-modal.element.js'),
},
{
type: 'condition',
name: 'Section User Permission Condition',
alias: 'Umb.Condition.SectionUserPermission',
api: UmbSectionUserPermissionCondition,
},
sectionUserPermissionConditionManifest,
...repositoryManifests,
];
1 change: 1 addition & 0 deletions src/packages/core/section/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from './conditions/types.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UMB_SECTION_CONTEXT, UMB_SECTION_SIDEBAR_CONTEXT } from '@umbraco-cms/backoffice/section';
import type { UmbSectionContext, UmbSectionSidebarContext } from '@umbraco-cms/backoffice/section';
import type { ManifestTreeItem } from '@umbraco-cms/backoffice/extension-registry';
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
import { UMB_ACTION_EVENT_CONTEXT, type UmbActionEventContext } from '@umbraco-cms/backoffice/action';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
import {
UmbRequestReloadChildrenOfEntityEvent,
UmbRequestReloadStructureForEntityEvent,
Expand Down Expand Up @@ -69,9 +68,9 @@ export abstract class UmbTreeItemContextBase<
readonly foldersOnly = this.#foldersOnly.asObservable();

treeContext?: UmbDefaultTreeContext<TreeItemType, TreeRootType>;
#sectionContext?: UmbSectionContext;
#sectionSidebarContext?: UmbSectionSidebarContext;
#actionEventContext?: UmbActionEventContext;
#sectionContext?: typeof UMB_SECTION_CONTEXT.TYPE;
#sectionSidebarContext?: typeof UMB_SECTION_SIDEBAR_CONTEXT.TYPE;
#actionEventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE;

// TODO: get this from the tree context
#paging = {
Expand Down
1 change: 0 additions & 1 deletion src/packages/documents/documents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { UmbVariantModel, UmbVariantOptionModel, UmbVariantPublishModel } f
import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';
import { DocumentVariantStateModel as UmbDocumentVariantState } from '@umbraco-cms/backoffice/external/backend-api';
export { UmbDocumentVariantState };
export type { UmbDocumentUserPermissionConditionConfig } from './user-permissions/condition/document-user-permission.condition.js';

export interface UmbDocumentDetailModel {
documentType: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { isDocumentUserPermission } from '../utils.js';
import type { UmbDocumentUserPermissionConditionConfig } from './types.js';
import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user';
import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity';
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
import type {
UmbConditionConfigBase,
UmbConditionControllerArguments,
UmbExtensionCondition,
} from '@umbraco-cms/backoffice/extension-api';
import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { DocumentPermissionPresentationModel } from '@umbraco-cms/backoffice/external/backend-api';

Expand Down Expand Up @@ -109,21 +106,4 @@ export class UmbDocumentUserPermissionCondition
}
}

export type UmbDocumentUserPermissionConditionConfig =
UmbConditionConfigBase<'Umb.Condition.UserPermission.Document'> & {
/**
* The user must have all of the permissions in this array for the condition to be met.
* @example
* ["Umb.Document.Save", "Umb.Document.Publish"]
*/
allOf?: Array<string>;

/**
* The user must have at least one of the permissions in this array for the condition to be met.
* @example
* ["Umb.Document.Save", "Umb.Document.Publish"]
*/
oneOf?: Array<string>;
};

export { UmbDocumentUserPermissionCondition as api };
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';

export type UmbDocumentUserPermissionConditionConfig =
UmbConditionConfigBase<'Umb.Condition.UserPermission.Document'> & {
/**
* The user must have all of the permissions in this array for the condition to be met.
* @example
* ["Umb.Document.Save", "Umb.Document.Publish"]
*/
allOf?: Array<string>;

/**
* The user must have at least one of the permissions in this array for the condition to be met.
* @example
* ["Umb.Document.Save", "Umb.Document.Publish"]
*/
oneOf?: Array<string>;
};

declare global {
interface UmbExtensionConditionMap {
UmbDocumentUserPermissionConditionConfig: UmbDocumentUserPermissionConditionConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
UMB_USER_PERMISSION_DOCUMENT_ROLLBACK,
} from './constants.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import { manifests as conditionManifests } from './condition/manifests.js';
import { manifests as conditionManifests } from './conditions/manifests.js';
import type {
ManifestGranularUserPermission,
ManifestEntityUserPermission,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/documents/documents/user-permissions/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UmbUserPermissionModel } from '@umbraco-cms/backoffice/user-permission';

export type * from './conditions/types.js';
export interface UmbDocumentUserPermissionModel extends UmbUserPermissionModel {
// TODO: this should be unique instead of an id, but we currently have now way to map a mixed server response.
document: { id: string };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/condition/document-user-permission.condition.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/conditions/document-user-permission.condition.js';
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../document-workspace.context-token.js';
import { UMB_USER_PERMISSION_DOCUMENT_UPDATE } from '../../user-permissions/index.js';
import { UmbWorkspaceActionBase } from '@umbraco-cms/backoffice/workspace';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
UMB_USER_PERMISSION_DOCUMENT_PUBLISH,
UMB_USER_PERMISSION_DOCUMENT_UPDATE,
} from '../../user-permissions/constants.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/condition/document-user-permission.condition.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/conditions/document-user-permission.condition.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbWorkspaceActionBase } from '@umbraco-cms/backoffice/workspace';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
UMB_USER_PERMISSION_DOCUMENT_CREATE,
UMB_USER_PERMISSION_DOCUMENT_UPDATE,
} from '../../user-permissions/constants.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/condition/document-user-permission.condition.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/conditions/document-user-permission.condition.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbSubmitWorkspaceAction } from '@umbraco-cms/backoffice/workspace';

Expand Down
Loading