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
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
ext.component.classList.add('umb-block-grid__block--view');
ext.component.setAttribute('part', 'component');
}
if (this._exposed) {
if (this._exposed || this._isReadOnly) {
return ext.component;
} else {
return html`
Expand Down Expand Up @@ -582,6 +582,7 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
}

#renderEditAction() {
if (this._isReadOnly) return nothing;
return html`
${when(
this._showContentEdit && this._workspaceEditContentPath,
Expand Down Expand Up @@ -615,6 +616,7 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
}

#renderEditSettingsAction() {
if (this._isReadOnly) return nothing;
return html`
${this._hasSettings && this._workspaceEditSettingsPath
? html`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper

#extensionSlotRenderMethod = (ext: UmbExtensionElementInitializer<ManifestBlockEditorCustomView>) => {
ext.component?.setAttribute('part', 'component');
if (this._exposed) {
if (this._exposed || this._isReadOnly) {
return ext.component;
} else {
return html`<div style="min-height: var(--uui-size-16);">
Expand Down Expand Up @@ -455,6 +455,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
}

#renderEditContentAction() {
if (this._isReadOnly) return nothing;
return this._showContentEdit && this._workspaceEditContentPath
? html`<uui-button
label="edit"
Expand All @@ -478,6 +479,7 @@ export class UmbBlockListEntryElement extends UmbLitElement implements UmbProper
}

#renderEditSettingsAction() {
if (this._isReadOnly) return nothing;
return html`
${this._hasSettings && this._workspaceEditSettingsPath
? html`<uui-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
@state()
private _contentTypeName?: string;

@state()
private _isReadOnly = false;

@state()
private _blockViewProps: UmbBlockEditorCustomViewProperties<UmbBlockRteLayoutModel> = {
contentKey: undefined!,
Expand Down Expand Up @@ -226,6 +229,11 @@
},
null,
);
this.observe(
this.#context.readOnlyGuard.permitted,
(isReadOnly) => (this._isReadOnly = isReadOnly),
'umbReadOnlyObserver',
);

Check warning on line 236 in src/Umbraco.Web.UI.Client/src/packages/block/block-rte/components/block-rte-entry/block-rte-entry.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Large Method

UmbBlockRteEntryElement.constructor increases from 118 to 123 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
}

async #observeData() {
Expand Down Expand Up @@ -301,7 +309,7 @@

#extensionSlotRenderMethod = (ext: UmbExtensionElementInitializer<ManifestBlockEditorCustomView>) => {
ext.component?.setAttribute('part', 'component');
if (this._exposed) {
if (this._exposed || this._isReadOnly) {
return ext.component;
} else {
return html`<div>
Expand Down Expand Up @@ -363,6 +371,7 @@
}

#renderEditAction() {
if (this._isReadOnly) return nothing;
return this._showContentEdit && this._workspaceEditContentPath
? html`<uui-button
label="edit"
Expand All @@ -385,6 +394,7 @@
}

#renderEditSettingsAction() {
if (this._isReadOnly) return nothing;
return html`
${this._hasSettings && this._workspaceEditSettingsPath
? html`<uui-button
Expand Down Expand Up @@ -414,6 +424,7 @@
}

#renderDeleteAction() {
if (this._isReadOnly) return nothing;
return html`
<uui-button label="delete" look="secondary" @click=${() => this.#context.requestDelete()}>
<uui-icon name="icon-remove"></uui-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class UmbBlockSingleEntryElement extends UmbLitElement implements UmbProp

#extensionSlotRenderMethod = (ext: UmbExtensionElementInitializer<ManifestBlockEditorCustomView>) => {
ext.component?.setAttribute('part', 'component');
if (this._exposed) {
if (this._exposed || this._isReadOnly) {
return ext.component;
} else {
return html`<div style="min-height: var(--uui-size-16);">
Expand Down Expand Up @@ -441,6 +441,7 @@ export class UmbBlockSingleEntryElement extends UmbLitElement implements UmbProp
}

#renderEditContentAction() {
if (this._isReadOnly) return nothing;
return this._showContentEdit && this._workspaceEditContentPath
? html`<uui-button
label="edit"
Expand All @@ -463,6 +464,7 @@ export class UmbBlockSingleEntryElement extends UmbLitElement implements UmbProp
}

#renderEditSettingsAction() {
if (this._isReadOnly) return nothing;
return html`
${this._hasSettings && this._workspaceEditSettingsPath
? html`<uui-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class UmbRefSingleBlockElement extends UmbLitElement {
override render() {
const blockValue = { ...this.content, $settings: this.settings };
return html`
<uui-ref-node standalone href=${(this.config?.showContentEdit ? this.config?.editContentPath : undefined) ?? ''}>
<uui-ref-node
standalone
.readonly=${!(this.config?.showContentEdit ?? false)}
.href=${this.config?.showContentEdit ? this.config?.editContentPath : undefined}>
<umb-icon slot="icon" .name=${this.icon}></umb-icon>
<umb-ufm-render slot="name" inline .markdown=${this.label} .value=${blockValue}></umb-ufm-render>
${when(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { UMB_BLOCK_WORKSPACE_CONTEXT } from '../index.js';
import type { BlockWorkspaceIsReadOnlyConditionConfig } from './types.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';

export class UmbBlockWorkspaceIsReadOnlyCondition
extends UmbConditionBase<BlockWorkspaceIsReadOnlyConditionConfig>
implements UmbExtensionCondition
{
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<BlockWorkspaceIsReadOnlyConditionConfig>) {
super(host, args);

this.consumeContext(UMB_BLOCK_WORKSPACE_CONTEXT, (context) => {
this.observe(
context?.readOnlyGuard.permitted,
(isReadOnly) => {
if (isReadOnly !== undefined) {
this.permitted = isReadOnly === (this.config.match !== undefined ? this.config.match : true);
}
},
'observeIsReadOnly',
);
});
}
}

export default UmbBlockWorkspaceIsReadOnlyCondition;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UmbBlockEntryShowContentEditCondition from './block-entry-show-content-edit.condition.js';
import UmbBlockWorkspaceHasSettingsCondition from './block-workspace-has-settings.condition.js';
import UmbBlockEntryIsExposedCondition from './block-workspace-is-exposed.condition.js';
import UmbBlockWorkspaceIsReadOnlyCondition from './block-workspace-is-readonly.condition.js';
import type { ManifestCondition } from '@umbraco-cms/backoffice/extension-api';

export const manifests: Array<ManifestCondition> = [
Expand All @@ -22,4 +23,10 @@ export const manifests: Array<ManifestCondition> = [
alias: 'Umb.Condition.BlockWorkspaceIsExposed',
api: UmbBlockEntryIsExposedCondition,
},
{
type: 'condition',
name: 'Block Workspace Is ReadOnly Condition',
alias: 'Umb.Condition.BlockWorkspaceIsReadOnly',
api: UmbBlockWorkspaceIsReadOnlyCondition,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ export interface BlockEntryIsExposedConditionConfig
match?: boolean;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export interface BlockWorkspaceIsReadOnlyConditionConfig
extends UmbConditionConfigBase<'Umb.Condition.BlockWorkspaceIsReadOnly'> {
match?: boolean;
}

declare global {
interface UmbExtensionConditionConfigMap {
umbBlock:
| BlockEntryShowContentEditConditionConfig
| BlockWorkspaceHasSettingsConditionConfig
| BlockEntryIsExposedConditionConfig;
| BlockEntryIsExposedConditionConfig
| BlockWorkspaceIsReadOnlyConditionConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@
};

this.readOnlyGuard?.addRule(rule);
this.content.propertyWriteGuard.addRule({ unique, permitted: false });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can´t just inherit the state. That would not work for Block Level Variants if the user does not have access to edit Invariant Fields but has access to edit fields of a particular Culture.
In that case the user needs to navigate via the invariant property to edit culture specific fields.

this.settings.propertyWriteGuard.addRule({ unique, permitted: false });
} else {
this.readOnlyGuard?.removeRule(unique);
this.content.propertyWriteGuard.removeRule(unique);
this.settings.propertyWriteGuard.removeRule(unique);

Check warning on line 220 in src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/block-workspace.context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

UmbBlockWorkspaceContext.gotManager already has high cyclomatic complexity, and now it increases in Lines of Code from 82 to 86. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}
},
'observeIsReadOnly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const manifests: Array<UmbExtensionManifest> = [
alias: 'Umb.Condition.BlockWorkspaceIsExposed',
match: false,
},
{
alias: 'Umb.Condition.BlockWorkspaceIsReadOnly',
match: false,
},
],
},
{
Expand All @@ -47,6 +51,10 @@ export const manifests: Array<UmbExtensionManifest> = [
{
alias: 'Umb.Condition.BlockWorkspaceIsExposed',
},
{
alias: 'Umb.Condition.BlockWorkspaceIsReadOnly',
match: false,
},
],
},
{
Expand Down
Loading