Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat: add sheet drawing permission (#2546)
ybzkybc108e55e6de
diff --git a/packages/drawing-ui/src/services/drawing-render.service.ts b/packages/drawing-ui/src/services/drawing-render.service.tsindex 2dd14dd9d0..5b6deee9b0 100644--- a/packages/drawing-ui/src/services/drawing-render.service.ts+++ b/packages/drawing-ui/src/services/drawing-render.service.ts@@ -32,6 +32,10 @@ export class DrawingRenderService {return;}+ if (!this._drawingManagerService.getDrawingVisible()) {+ return;+ }+if (transform == null) {return;}@@ -73,7 +77,14 @@ export class DrawingRenderService {this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());}- scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(image);+ if (!this._drawingManagerService.getDrawingVisible()) {+ return;+ }++ const imageObject = scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX);+ if (this._drawingManagerService.getDrawingEditable()) {+ imageObject.attachTransformerTo(image);+ }groupId && insertGroupObject({ drawingId: groupId, unitId, subUnitId }, image, scene, this._drawingManagerService);diff --git a/packages/drawing/src/services/drawing-manager-impl.service.ts b/packages/drawing/src/services/drawing-manager-impl.service.tsindex 6ac4ce38de..594f6efa63 100644--- a/packages/drawing/src/services/drawing-manager-impl.service.ts+++ b/packages/drawing/src/services/drawing-manager-impl.service.ts@@ -99,6 +99,9 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawingprivate readonly _featurePluginUngroupUpdate$ = new Subject<IDrawingGroupUpdateParam[]>();readonly featurePluginUngroupUpdate$: Observable<IDrawingGroupUpdateParam[]> = this._featurePluginUngroupUpdate$.asObservable();+ private _visible: boolean = true;+ private _editable: boolean = true;+dispose(): void {this._remove$.complete();this._add$.complete();@@ -743,6 +746,22 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawingprivate _getDrawingOrder(unitId: string, subUnitId: string) {return this.drawingManagerData[unitId]?.[subUnitId]?.order || [];}++ getDrawingVisible() {+ return this._visible;+ }++ getDrawingEditable() {+ return this._editable;+ }++ setDrawingVisible(visible: boolean) {+ this._visible = visible;+ }++ setDrawingEditable(editable: boolean) {+ this._editable = editable;+ }}export class DrawingManagerService extends UnitDrawingService<IDrawingParam> {}diff --git a/packages/drawing/src/services/drawing-manager.service.ts b/packages/drawing/src/services/drawing-manager.service.tsindex 776f5600f0..3d82b14a61 100644--- a/packages/drawing/src/services/drawing-manager.service.ts+++ b/packages/drawing/src/services/drawing-manager.service.ts@@ -193,6 +193,10 @@ export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNormagetDrawingOKey(oKey: string): Nullable<T>;applyJson1(unitId: string, subUnitId: string, jsonOp: unknown): void;+ getDrawingEditable(): boolean;+ getDrawingVisible(): boolean;+ setDrawingVisible(visible: boolean): void;+ setDrawingEditable(editable: boolean): void;}export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {}diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.tsnew file mode 100644index 0000000000..5735bea238--- /dev/null+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts@@ -0,0 +1,260 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Workbook } from '@univerjs/core';+import { Disposable, IPermissionService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, UserManagerService } from '@univerjs/core';+import { IDrawingManagerService } from '@univerjs/drawing';+import { IRenderManagerService, RENDER_CLASS_TYPE } from '@univerjs/engine-render';+import { WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission } from '@univerjs/sheets';+import { Inject } from '@wendellhu/redi';+import { combineLatest, distinctUntilChanged, filter, map } from 'rxjs';++@OnLifecycle(LifecycleStages.Rendered, SheetDrawingPermissionController)+export class SheetDrawingPermissionController extends Disposable {+ constructor(+ @IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,+ @IPermissionService private readonly _permissionService: IPermissionService,+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(UserManagerService) private _userManagerService: UserManagerService+ ) {+ super();+ this._initDrawingVisible();+ this._initDrawingEditable();+ this._initViewPermissionChange();+ this._initEditPermissionChange();+ }++ private _initDrawingVisible() {+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);+ this.disposeWithMe(+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {+ if (!workbook) {+ this._drawingManagerService.setDrawingVisible(false);+ return;+ }+ workbook.activeSheet$.subscribe((sheet) => {+ if (!sheet) {+ this._drawingManagerService.setDrawingVisible(false);+ return;+ }+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ const worksheetViewPermission = this._permissionService.composePermission([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).every((permission) => permission.value);+ if (worksheetViewPermission) {+ this._drawingManagerService.setDrawingVisible(true);+ } else {+ this._drawingManagerService.setDrawingVisible(false);+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ const renderObject = this._renderManagerService.getRenderById(unitId);+ const scene = renderObject?.scene;+ if (scene == null) {+ return;+ }+ const objects = scene.getAllObjects();+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.removeObject(object);+ }+ });+ }+ });+ })+ );+ }++ private _initDrawingEditable() {+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);+ this.disposeWithMe(+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {+ if (!workbook) {+ this._drawingManagerService.setDrawingEditable(false);+ return;+ }+ workbook.activeSheet$.subscribe((sheet) => {+ if (!sheet) {+ this._drawingManagerService.setDrawingEditable(false);+ return;+ }+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ const worksheetEditPermission = this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value);+ if (worksheetEditPermission) {+ this._drawingManagerService.setDrawingEditable(true);+ } else {+ this._drawingManagerService.setDrawingEditable(false);+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ const renderObject = this._renderManagerService.getRenderById(unitId);+ const scene = renderObject?.scene;+ if (scene == null) {+ return;+ }+ const objects = scene.getAllObjects();+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.detachTransformerFrom(object);+ }+ });+ }+ });+ })+ );+ }++ private _initViewPermissionChange() {+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);+ this.disposeWithMe(+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {+ if (!workbook) {+ return;+ }+ workbook.activeSheet$.subscribe((sheet) => {+ if (!sheet) {+ return;+ }+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ let initialViewPermission = true;+ const renderObject = this._renderManagerService.getRenderById(unitId);+ const scene = renderObject?.scene;+ if (scene == null) {+ return;+ }+ const transformer = scene.getTransformerByCreate();+ const worksheetViewPermission$ = this._permissionService.composePermission$([new WorkbookViewPermission(unitId).id, new WorksheetViewPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));+ worksheetViewPermission$?.pipe(+ filter((permission) => permission !== initialViewPermission),+ distinctUntilChanged()+ ).subscribe({+ next: (permission) => {+ initialViewPermission = permission;+ this._drawingManagerService.setDrawingVisible(permission);+ const objects = scene.getAllObjects();+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ if (permission) {+ this._drawingManagerService.addNotification(drawingDataValues);+ } else {+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.removeObject(object);+ }+ });+ transformer.clearSelectedObjects();+ }+ },+ });+ this._permissionService.getPermissionPoint$(new WorksheetViewPermission(unitId, subUnitId).id)?.pipe(+ filter((permission) => permission.value !== initialViewPermission),+ distinctUntilChanged()+ ).subscribe({+ complete: () => {+ initialViewPermission = true;+ this._drawingManagerService.setDrawingVisible(true);+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ this._drawingManagerService.addNotification(drawingDataValues);+ },+ });+ });+ })+ );+ }++ private _initEditPermissionChange() {+ const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);+ this.disposeWithMe(+ combineLatest([workbook$, this._userManagerService.currentUser$]).subscribe(([workbook, _]) => {+ if (!workbook) {+ return;+ }+ workbook.activeSheet$.subscribe((sheet) => {+ if (!sheet) {+ return;+ }+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ let initialEditPermission = true;+ const renderObject = this._renderManagerService.getRenderById(unitId);+ const scene = renderObject?.scene;+ if (scene == null) {+ return;+ }+ const transformer = scene.getTransformerByCreate();+ const composeWorksheetEditPermission = this._permissionService.composePermission$([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).pipe(map((permissions) => permissions.every((item) => item.value)));+ composeWorksheetEditPermission?.pipe(+ filter((permission) => permission !== initialEditPermission),+ distinctUntilChanged()+ ).subscribe({+ next: (permission) => {+ initialEditPermission = permission;+ this._drawingManagerService.setDrawingEditable(permission);+ const objects = scene.getAllObjects();+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ if (permission) {+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.attachTransformerTo(object);+ }+ });++ this._drawingManagerService.addNotification(drawingDataValues);+ } else {+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.detachTransformerFrom(object);+ }+ });+ transformer.clearSelectedObjects();+ }+ },+ });+ this._permissionService.getPermissionPoint$(new WorksheetEditPermission(unitId, subUnitId).id)?.pipe(+ filter((permission) => permission.value !== initialEditPermission),+ distinctUntilChanged()+ ).subscribe({+ complete: () => {+ initialEditPermission = true;+ const unitId = workbook.getUnitId();+ const subUnitId = sheet.getSheetId();+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);+ const drawingDataValues = Object.values(drawingData);+ const renderObject = this._renderManagerService.getRenderById(unitId);+ const scene = renderObject?.scene;+ if (scene == null) {+ return;+ }+ this._drawingManagerService.setDrawingEditable(true);+ const objects = scene.getAllObjects();+ objects.forEach((object) => {+ if (object.classType === RENDER_CLASS_TYPE.IMAGE && drawingDataValues.some((item) => object.oKey.includes(item.drawingId))) {+ scene.detachTransformerFrom(object);+ }+ });+ },+ });+ });+ })+ );+ }+}diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.tsindex 6d66e8e958..0b451f6465 100644--- a/packages/sheets-drawing-ui/src/plugin.ts+++ b/packages/sheets-drawing-ui/src/plugin.ts@@ -27,6 +27,7 @@ import { DefaultSheetsDrawingConfig, SheetDrawingUIController } from './controllimport { SheetDrawingTransformAffectedController } from './controllers/sheet-drawing-transform-affected.controller';import { SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';import { SheetDrawingPrintingController } from './controllers/sheet-drawing-printing.controller';+import { SheetDrawingPermissionController } from './controllers/sheet-drawing-permission.controller';const PLUGIN_NAME = 'SHEET_IMAGE_UI_PLUGIN';@@ -68,6 +69,7 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {[DrawingPopupMenuController],[SheetDrawingTransformAffectedController],[SheetDrawingPrintingController],+ [SheetDrawingPermissionController],];diff --git a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.tsindex 7458a53f6f..43a4d73940 100644--- a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts+++ b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts@@ -14,11 +14,12 @@* limitations under the License.*/-import { Disposable, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core';-import { HoverManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import { Disposable, IPermissionService, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core';+import { HoverManagerService, SheetPermissionInterceptorBaseController, SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { Inject } from '@wendellhu/redi';import { debounceTime } from 'rxjs';import { IRenderManagerService } from '@univerjs/engine-render';+import { RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, WorkbookCopyPermission, WorkbookEditablePermission, WorkbookViewPermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetViewPermission } from '@univerjs/sheets';import { SheetsHyperLinkPopupService } from '../services/popup.service';@OnLifecycle(LifecycleStages.Rendered, SheetsHyperLinkPopupController)@@ -26,7 +27,9 @@ export class SheetsHyperLinkPopupController extends Disposable {constructor(@Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,@Inject(SheetsHyperLinkPopupService) private readonly _sheetsHyperLinkPopupService: SheetsHyperLinkPopupService,- @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService+ @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService,+ @Inject(IPermissionService) private readonly _permissionService: IPermissionService,+ @Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController) {super();@@ -60,10 +63,33 @@ export class SheetsHyperLinkPopupController extends Disposable {});}+ const viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({+ workbookTypes: [WorkbookViewPermission],+ worksheetTypes: [WorksheetViewPermission],+ rangeTypes: [RangeProtectionPermissionViewPoint],+ }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]);+ if (!viewPermission) {+ this._sheetsHyperLinkPopupService.hideCurrentPopup();+ return;+ }++ const editPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({+ workbookTypes: [WorkbookEditablePermission],+ worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],+ rangeTypes: [RangeProtectionPermissionEditPoint],+ }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]);++ const unitId = currentCell.location.unitId;+ const subUnitId = currentCell.location.subUnitId;++ const copyPermission = this._permissionService.composePermission([new WorkbookCopyPermission(unitId).id, new WorksheetCopyPermission(unitId, subUnitId).id]).every((permission) => permission.value);+this._sheetsHyperLinkPopupService.showPopup({...currentCell.location,row: targetRow,col: targetCol,+ editPermission,+ copyPermission,});}));diff --git a/packages/sheets-hyper-link-ui/src/services/popup.service.ts b/packages/sheets-hyper-link-ui/src/services/popup.service.tsindex e7c28e19f1..f6814a4442 100644--- a/packages/sheets-hyper-link-ui/src/services/popup.service.ts+++ b/packages/sheets-hyper-link-ui/src/services/popup.service.ts@@ -30,6 +30,8 @@ interface IHyperLinkPopup {disposable?: IDisposable;row: number;col: number;+ editPermission: boolean;+ copyPermission: boolean;}interface IHyperLinkEditing {@@ -74,7 +76,7 @@ export class SheetsHyperLinkPopupService extends Disposable {});}- showPopup(location: ISheetLocationBase) {+ showPopup(location: ISheetLocationBase & { editPermission?: boolean; copyPermission?: boolean }) {if (this._currentPopup && isEqualLink(location, this._currentPopup)) {return;}@@ -100,6 +102,8 @@ export class SheetsHyperLinkPopupService extends Disposable {disposable,row,col,+ editPermission: !!location.editPermission,+ copyPermission: !!location.copyPermission,};this._currentPopup$.next(this._currentPopup);}diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsxindex f7caf6c72b..f2c997253b 100644--- a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx@@ -67,59 +67,65 @@ export const CellLinkPopup = () => {</div></div><div className={styles.cellLinkOperations}>- <div- className={cs(styles.cellLinkOperation, { [styles.cellLinkOperationError]: isError })}- onClick={() => {- if (isError) {- return;- }- if (linkObj.type !== 'outer') {- const url = new URL(window.location.href);- url.hash = linkObj.url.slice(1);- navigator.clipboard.writeText(url.href);- } else {- navigator.clipboard.writeText(linkObj.url);- }- messageService.show({- content: localeService.t('hyperLink.message.coped'),- type: MessageType.Info,- });- }}- >- <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.copy')}>- <CopySingle />- </Tooltip>+ {currentPopup.copyPermission && (+ <div+ className={cs(styles.cellLinkOperation, { [styles.cellLinkOperationError]: isError })}+ onClick={() => {+ if (isError) {+ return;+ }+ if (linkObj.type !== 'outer') {+ const url = new URL(window.location.href);+ url.hash = linkObj.url.slice(1);+ navigator.clipboard.writeText(url.href);+ } else {+ navigator.clipboard.writeText(linkObj.url);+ }+ messageService.show({+ content: localeService.t('hyperLink.message.coped'),+ type: MessageType.Info,+ });+ }}+ >+ <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.copy')}>+ <CopySingle />+ </Tooltip>- </div>- <div- className={styles.cellLinkOperation}- onClick={() => {- commandService.executeCommand(OpenHyperLinkSidebarOperation.id, {- unitId,- subUnitId,- row: link.row,- column: link.column,- });- }}- >- <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.edit')}>- <WriteSingle />- </Tooltip>- </div>- <div- className={styles.cellLinkOperation}- onClick={() => {- commandService.executeCommand(CancelHyperLinkCommand.id, {- unitId,- subUnitId,- id: link.id,- });- }}- >- <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.cancel')}>- <UnlinkSingle />- </Tooltip>- </div>+ </div>+ )}+ {currentPopup.editPermission && (+ <>+ <div+ className={styles.cellLinkOperation}+ onClick={() => {+ commandService.executeCommand(OpenHyperLinkSidebarOperation.id, {+ unitId,+ subUnitId,+ row: link.row,+ column: link.column,+ });+ }}+ >+ <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.edit')}>+ <WriteSingle />+ </Tooltip>+ </div>+ <div+ className={styles.cellLinkOperation}+ onClick={() => {+ commandService.executeCommand(CancelHyperLinkCommand.id, {+ unitId,+ subUnitId,+ id: link.id,+ });+ }}+ >+ <Tooltip placement="bottom" title={localeService.t('hyperLink.popup.cancel')}>+ <UnlinkSingle />+ </Tooltip>+ </div>+ </>+ )}</div></div>);diff --git a/packages/sheets-thread-comment/src/controllers/menu.ts b/packages/sheets-thread-comment/src/controllers/menu.tsindex 745675f98e..c18c840bce 100644--- a/packages/sheets-thread-comment/src/controllers/menu.ts+++ b/packages/sheets-thread-comment/src/controllers/menu.ts@@ -20,7 +20,7 @@ import type { IAccessor } from '@wendellhu/redi';import { ToggleSheetCommentPanelOperation } from '@univerjs/thread-comment-ui';import { UniverInstanceType } from '@univerjs/core';import { getCurrentRangeDisable$, whenSheetEditorFocused } from '@univerjs/sheets-ui';-import { RangeProtectionPermissionEditPoint, WorkbookCommentPermission, WorksheetViewPermission } from '@univerjs/sheets';+import { RangeProtectionPermissionViewPoint, WorkbookCommentPermission, WorksheetViewPermission } from '@univerjs/sheets';import { ShowAddSheetCommentModalOperation } from '../commands/operations/comment.operation';import { COMMENT_SINGLE_ICON } from '../types/const';@@ -35,7 +35,7 @@ export const threadCommentMenuFactory = (accessor: IAccessor) => {disabled$: getCurrentRangeDisable$(accessor, {workbookTypes: [WorkbookCommentPermission],worksheetTypes: [WorksheetViewPermission],- rangeTypes: [RangeProtectionPermissionEditPoint],+ rangeTypes: [RangeProtectionPermissionViewPoint],}),} as IMenuItem;};@@ -51,7 +51,7 @@ export const threadPanelMenuFactory = (accessor: IAccessor) => {disabled$: getCurrentRangeDisable$(accessor, {workbookTypes: [WorkbookCommentPermission],worksheetTypes: [WorksheetViewPermission],- rangeTypes: [RangeProtectionPermissionEditPoint],+ rangeTypes: [RangeProtectionPermissionViewPoint],}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.tsindex 381c9fdf51..e47a5d47a3 100644--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts+++ b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts@@ -15,10 +15,11 @@*/import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';-import { HoverManagerService } from '@univerjs/sheets-ui';+import { HoverManagerService, SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';import { Inject } from '@wendellhu/redi';import { debounceTime } from 'rxjs';import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';+import { RangeProtectionPermissionViewPoint, WorkbookCommentPermission, WorksheetViewPermission } from '@univerjs/sheets';import { SheetsThreadCommentPopupService } from '../services/sheets-thread-comment-popup.service';@OnLifecycle(LifecycleStages.Rendered, SheetsThreadCommentHoverController)@@ -26,7 +27,8 @@ export class SheetsThreadCommentHoverController extends Disposable {constructor(@Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,@Inject(SheetsThreadCommentPopupService) private readonly _sheetsThreadCommentPopupService: SheetsThreadCommentPopupService,- @Inject(SheetsThreadCommentModel) private readonly _sheetsThreadCommentModel: SheetsThreadCommentModel+ @Inject(SheetsThreadCommentModel) private readonly _sheetsThreadCommentModel: SheetsThreadCommentModel,+ @Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController) {super();this._initHoverEvent();@@ -42,6 +44,14 @@ export class SheetsThreadCommentHoverController extends Disposable {const commentId = this._sheetsThreadCommentModel.getByLocation(unitId, subUnitId, row, col);if (commentId) {+ const commentPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({+ workbookTypes: [WorkbookCommentPermission],+ worksheetTypes: [WorksheetViewPermission],+ rangeTypes: [RangeProtectionPermissionViewPoint],+ }, [{ startRow: row, startColumn: col, endRow: row, endColumn: col }]);+ if (!commentPermission) {+ return;+ }const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, commentId);if (comment && !comment.resolved) {this._sheetsThreadCommentPopupService.showPopup({diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.tsindex cf2e7557ab..d02d008d83 100644--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts+++ b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts@@ -22,11 +22,11 @@ import { Inject, Injector } from '@wendellhu/redi';import { CommentSingle } from '@univerjs/icons';import { SetActiveCommentOperation, THREAD_COMMENT_PANEL, ThreadCommentPanelService } from '@univerjs/thread-comment-ui';import type { ISetSelectionsOperationParams } from '@univerjs/sheets';-import { SelectionMoveType, SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';+import { RangeProtectionPermissionViewPoint, SelectionMoveType, SetSelectionsOperation, SetWorksheetActiveOperation, WorkbookCommentPermission, WorksheetViewPermission } from '@univerjs/sheets';import { singleReferenceToGrid } from '@univerjs/engine-formula';import type { IDeleteCommentMutationParams } from '@univerjs/thread-comment';import { DeleteCommentMutation } from '@univerjs/thread-comment';-import { ScrollToRangeOperation } from '@univerjs/sheets-ui';+import { ScrollToRangeOperation, SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';import { SheetsThreadCommentCell } from '../views/sheets-thread-comment-cell';import { COMMENT_SINGLE_ICON, SHEETS_THREAD_COMMENT_MODAL } from '../types/const';@@ -56,7 +56,8 @@ export class SheetsThreadCommentController extends Disposable {@Inject(SheetsThreadCommentModel) private readonly _sheetsThreadCommentModel: SheetsThreadCommentModel,@Inject(ThreadCommentPanelService) private readonly _threadCommentPanelService: ThreadCommentPanelService,@IShortcutService private readonly _shortcutService: IShortcutService,- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController) {super();this._initMenu();@@ -157,6 +158,17 @@ export class SheetsThreadCommentController extends Disposable {}const location = singleReferenceToGrid(comment.ref);++ const { row, column: col } = location;+ const commentPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({+ workbookTypes: [WorkbookCommentPermission],+ worksheetTypes: [WorksheetViewPermission],+ rangeTypes: [RangeProtectionPermissionViewPoint],+ }, [{ startRow: row, startColumn: col, endRow: row, endColumn: col }]);+ if (!commentPermission) {+ return;+ }+const GAP = 5;await this._commandService.executeCommand(ScrollToRangeOperation.id, {range: {diff --git a/packages/sheets-ui/src/commands/commands/worksheet-protection.command.ts b/packages/sheets-ui/src/commands/commands/worksheet-protection.command.tsindex d55d1384f0..f81ef7ec83 100644--- a/packages/sheets-ui/src/commands/commands/worksheet-protection.command.ts+++ b/packages/sheets-ui/src/commands/commands/worksheet-protection.command.ts@@ -88,7 +88,7 @@ export const DeleteWorksheetProtectionCommand: ICommand<IDeleteWorksheetProtecti});const redoMutations = [{ id: DeleteWorksheetProtectionMutation.id, params: { unitId, subUnitId } }];- const undoMutations = [{ id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId: rule.subUnitId } }];+ const undoMutations = [{ id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId } }];undoRedoService.pushUndoRedo({unitID: unitId,redoMutations,diff --git a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts b/packages/sheets-ui/src/controllers/menu/permission-menu-util.tsindex 226ed9b204..044666ad87 100644--- a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts+++ b/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts@@ -152,7 +152,7 @@ export function getPermissionDisableBase$(accessor: IAccessor) {const selectionManagerService = accessor.get(SelectionManagerService);const selectionProtectionRuleModel = accessor.get(RangeProtectionRuleModel);const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);const ruleChange$ = merge(selectionProtectionRuleModel.ruleChange$,worksheetProtectionRuleModel.ruleChange$@@ -206,7 +206,7 @@ export function getAddPermissionDisableBase$(accessor: IAccessor) {const selectionProtectionRuleModel = accessor.get(RangeProtectionRuleModel);const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);const selectionManagerService = accessor.get(SelectionManagerService);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);const ruleChange$ = merge(selectionProtectionRuleModel.ruleChange$,worksheetProtectionRuleModel.ruleChange$@@ -267,7 +267,7 @@ export function getAddPermissionFromSheetBarDisable$(accessor: IAccessor) {const subUnitId = worksheet.getSheetId();const selectionProtectionRuleModel = accessor.get(RangeProtectionRuleModel);const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);const ruleChange$ = merge(selectionProtectionRuleModel.ruleChange$,worksheetProtectionRuleModel.ruleChange$@@ -309,7 +309,7 @@ export function getRemovePermissionFromSheetBarDisable$(accessor: IAccessor) {const unitId = workbook.getUnitId();const subUnitId = worksheet.getSheetId();const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);return combineLatest([permission$, worksheetProtectionRuleModel.ruleChange$.pipe(startWith(null))]).pipe(map(([permission, _]) => {if (!permission) return true;@@ -343,7 +343,7 @@ export function getSetPermissionFromSheetBarDisable$(accessor: IAccessor) {const unitId = workbook.getUnitId();const selectionProtectionRuleModel = accessor.get(RangeProtectionRuleModel);const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);const worksheetRuleChange$ = worksheetProtectionRuleModel.ruleChange$.pipe(startWith(null));const selectionRuleChange$ = selectionProtectionRuleModel.ruleChange$.pipe(startWith(null));return combineLatest([permission$, worksheetRuleChange$, selectionRuleChange$]).pipe(@@ -387,7 +387,7 @@ export function getRemovePermissionDisable$(accessor: IAccessor) {const subUnitId = worksheet.getSheetId();const selectionProtectionRuleModel = accessor.get(RangeProtectionRuleModel);const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);- const permission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((e) => !!e.value)) ?? of(false);+ const permission$ = permissionService.composePermission$([new WorkbookManageCollaboratorPermission(unitId).id, new WorkbookEditablePermission(unitId).id]).pipe(map((permissions) => permissions.every((permission) => permission.value))) ?? of(false);const changes$ = merge(selectionProtectionRuleModel.ruleChange$,diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.tsindex 7cd125b683..6ca80ca4e5 100644--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts@@ -180,7 +180,7 @@ export class SheetPermissionInitController extends Disposable {} else {[...getAllWorksheetPermissionPoint(), ...getAllWorksheetPermissionPointByPointPanel()].forEach((F) => {const instance = new F(info.unitId, info.subUnitId);- this._permissionService.addPermissionPoint(instance);+ this._permissionService.updatePermissionPoint(instance.id, true);});this._worksheetProtectionPointRuleModel.deleteRule(info.unitId, info.subUnitId);}diff --git a/packages/sheets-ui/src/views/permission/panel-detail/index.module.less b/packages/sheets-ui/src/views/permission/panel-detail/index.module.lessindex dfc8260863..e9c547e5a1 100644--- a/packages/sheets-ui/src/views/permission/panel-detail/index.module.less+++ b/packages/sheets-ui/src/views/permission/panel-detail/index.module.less@@ -48,7 +48,7 @@}&-name {- width: 143px;+ width: 130px;color: rgb(var(--color-black));white-space: nowrap;overflow: hidden;diff --git a/packages/sheets/src/services/permission/worksheet-permission/utils.ts b/packages/sheets/src/services/permission/worksheet-permission/utils.tsindex 2a3c8998c0..b2169763d7 100644--- a/packages/sheets/src/services/permission/worksheet-permission/utils.ts+++ b/packages/sheets/src/services/permission/worksheet-permission/utils.ts@@ -18,8 +18,8 @@ import { UnitAction } from '@univerjs/protocol';import { WorksheetCopyPermission, WorksheetDeleteColumnPermission, WorksheetDeleteRowPermission, WorksheetEditExtraObjectPermission, WorksheetEditPermission, WorksheetFilterPermission, WorksheetInsertColumnPermission, WorksheetInsertHyperlinkPermission, WorksheetInsertRowPermission, WorksheetPivotTablePermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission, WorksheetSetRowStylePermission, WorksheetSortPermission, WorksheetViewPermission } from '../permission-point';export const getAllWorksheetPermissionPoint = () => [- WorksheetViewPermission,WorksheetEditPermission,+ WorksheetViewPermission,];// Changes require synchronization of the following arraysdiff --git a/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts b/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.tsindex 07692b27e8..a76ca48170 100644--- a/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts+++ b/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts@@ -110,7 +110,7 @@ export class WorksheetPermissionService extends RxDisposable {case 'delete': {getAllWorksheetPermissionPoint().forEach((F) => {const instance = new F(info.unitId, info.subUnitId);- this._permissionService.deletePermissionPoint(instance.id);+ this._permissionService.updatePermissionPoint(instance.id, true);});break;}