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(sheet): suppot the base permission of controll (#359)
Gpound.liu3835cacbdf03
diff --git a/docs/permission.tldr b/docs/permission.tldrnew file mode 100644index 0000000000..4d4fcb8c17--- /dev/null+++ b/docs/permission.tldr@@ -0,0 +1,721 @@+{+ "tldrawFileFormatVersion": 1,+ "schema": {+ "schemaVersion": 1,+ "storeVersion": 4,+ "recordVersions": {+ "asset": {+ "version": 1,+ "subTypeKey": "type",+ "subTypeVersions": {+ "image": 2,+ "video": 2,+ "bookmark": 0+ }+ },+ "camera": {+ "version": 1+ },+ "document": {+ "version": 2+ },+ "instance": {+ "version": 22+ },+ "instance_page_state": {+ "version": 5+ },+ "page": {+ "version": 1+ },+ "shape": {+ "version": 3,+ "subTypeKey": "type",+ "subTypeVersions": {+ "group": 0,+ "text": 1,+ "bookmark": 1,+ "draw": 1,+ "geo": 7,+ "note": 4,+ "line": 1,+ "frame": 0,+ "arrow": 1,+ "highlight": 0,+ "embed": 4,+ "image": 2,+ "video": 1+ }+ },+ "instance_presence": {+ "version": 5+ },+ "pointer": {+ "version": 1+ }+ }+ },+ "records": [+ {+ "gridSize": 10,+ "name": "",+ "meta": {},+ "id": "document:document",+ "typeName": "document"+ },+ {+ "id": "pointer:pointer",+ "typeName": "pointer",+ "x": 555.6905537601147,+ "y": 593.7329937919792,+ "lastActivityTimestamp": 1699425334591,+ "meta": {}+ },+ {+ "meta": {},+ "id": "page:page",+ "name": "Page 1",+ "index": "a1",+ "typeName": "page"+ },+ {+ "x": 630.4706550337846,+ "y": 232.30022366844838,+ "z": 0.6502462475435885,+ "meta": {},+ "id": "camera:page:page",+ "typeName": "camera"+ },+ {+ "editingShapeId": null,+ "croppingShapeId": null,+ "selectedShapeIds": [],+ "hoveredShapeId": null,+ "erasingShapeIds": [],+ "hintingShapeIds": [],+ "focusedGroupId": null,+ "meta": {},+ "id": "instance_page_state:page:page",+ "pageId": "page:page",+ "typeName": "instance_page_state"+ },+ {+ "followingUserId": null,+ "opacityForNextShape": 1,+ "stylesForNextShape": {+ "tldraw:dash": "solid",+ "tldraw:geo": "rectangle",+ "tldraw:size": "s",+ "tldraw:arrowheadStart": "none",+ "tldraw:fill": "none"+ },+ "brush": null,+ "scribbles": [],+ "cursor": {+ "type": "default",+ "rotation": 0+ },+ "isFocusMode": false,+ "exportBackground": true,+ "isDebugMode": false,+ "isToolLocked": false,+ "screenBounds": {+ "x": 0,+ "y": 0,+ "w": 1477,+ "h": 710+ },+ "zoomBrush": null,+ "isGridMode": false,+ "isPenMode": false,+ "chatMessage": "",+ "isChatting": false,+ "highlightedUserIds": [],+ "canMoveCamera": true,+ "isFocused": false,+ "devicePixelRatio": 2,+ "isCoarsePointer": false,+ "isHoveringCanvas": true,+ "openMenus": [],+ "isChangingStyle": false,+ "isReadonly": false,+ "meta": {},+ "id": "instance:instance",+ "currentPageId": "page:page",+ "typeName": "instance"+ },+ {+ "x": 509.609375,+ "y": 302.52734375,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:cfWgelQMptas1YBaHORr-",+ "type": "text",+ "props": {+ "color": "black",+ "size": "m",+ "w": 16,+ "text": "",+ "font": "draw",+ "align": "middle",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "a1",+ "typeName": "shape"+ },+ {+ "x": 435.71875,+ "y": 463.671875,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:mS-l4AW89fjxR4YSq58MM",+ "type": "geo",+ "props": {+ "w": 258.3125,+ "h": 61.6953125,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "draw",+ "size": "m",+ "font": "draw",+ "text": "network",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "a2",+ "typeName": "shape"+ },+ {+ "x": 426.8203125,+ "y": 349.5546875,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:JAtrXXL1duBdbmVP24_cA",+ "type": "geo",+ "props": {+ "w": 267.9375,+ "h": 71.5625,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "draw",+ "size": "s",+ "font": "draw",+ "text": "permission.service",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "a4",+ "typeName": "shape"+ },+ {+ "x": 147.21875,+ "y": 228.2578125,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:0ZsG_62TV_6OY9RQz3O1e",+ "type": "geo",+ "props": {+ "w": 342.53125,+ "h": 89.94921875,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "draw",+ "size": "s",+ "font": "draw",+ "text": "univer.permission.serivce",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "a6",+ "typeName": "shape"+ },+ {+ "x": 520.5390625,+ "y": 227.78515625,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:rf-LoZkUy6vpGYVSrvzAC",+ "type": "geo",+ "props": {+ "w": 342.53125,+ "h": 89.94921875,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "draw",+ "size": "s",+ "font": "draw",+ "text": "sheet.permission.serivce",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "a7",+ "typeName": "shape"+ },+ {+ "x": 884.97265625,+ "y": 226.28125,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:271jSCWLcOj0KUA3vQFOR",+ "type": "geo",+ "props": {+ "w": 342.53125,+ "h": 89.94921875,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "draw",+ "size": "s",+ "font": "draw",+ "text": "other.permission.serivce",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "a8",+ "typeName": "shape"+ },+ {+ "x": -209.8046875,+ "y": 236.83984375,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:Gn_sdtXFDgdTRD0pBZJ8-",+ "type": "text",+ "props": {+ "color": "black",+ "size": "s",+ "w": 408,+ "text": "业务权限服务,用来增删改查或者组合\npermissionPoint,派发业务权限。",+ "font": "draw",+ "align": "start",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "aB",+ "typeName": "shape"+ },+ {+ "x": -38.609375,+ "y": 450.36328125,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:5OhscMwh5sOypD0hQAGwe",+ "type": "arrow",+ "parentId": "page:page",+ "index": "aA",+ "props": {+ "dash": "draw",+ "size": "s",+ "fill": "none",+ "color": "black",+ "labelColor": "black",+ "bend": 0,+ "start": {+ "type": "point",+ "x": -210.5551014993154,+ "y": -5.752767876852317+ },+ "end": {+ "type": "point",+ "x": 1312.44921875,+ "y": -8.44921875+ },+ "arrowheadStart": "none",+ "arrowheadEnd": "arrow",+ "text": "",+ "font": "draw"+ },+ "typeName": "shape"+ },+ {+ "x": -35.625,+ "y": 331.99609375,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:Z80Ep4Gyg9yjGpdn8EL7j",+ "type": "arrow",+ "parentId": "page:page",+ "index": "a8V",+ "props": {+ "dash": "draw",+ "size": "s",+ "fill": "none",+ "color": "black",+ "labelColor": "black",+ "bend": 0,+ "start": {+ "type": "point",+ "x": -227.70898195058965,+ "y": -1.3669943469748205+ },+ "end": {+ "type": "point",+ "x": 1303.2730187768332,+ "y": -7.600694848512887+ },+ "arrowheadStart": "none",+ "arrowheadEnd": "arrow",+ "text": "",+ "font": "draw"+ },+ "typeName": "shape"+ },+ {+ "x": -195.99526675112614,+ "y": 368.0168606494899,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:o9uNCq750TtxJGcGN5BJW",+ "type": "text",+ "props": {+ "color": "black",+ "size": "s",+ "w": 360,+ "text": "基础权限服务,用来管理权限点位\n点位注册/权限更新/权限拉取",+ "font": "draw",+ "align": "start",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "aD",+ "typeName": "shape"+ },+ {+ "x": 965.7276264912375,+ "y": 524.211600551246,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:j0cBZpJO_sLqJhpvuyjj4",+ "type": "text",+ "props": {+ "color": "black",+ "size": "s",+ "w": 8,+ "text": "",+ "font": "draw",+ "align": "middle",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "aE",+ "typeName": "shape"+ },+ {+ "x": 115.68236232448254,+ "y": 177.31517561179118,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:gnp2CdFhkLoLhv5_PAdTM",+ "type": "arrow",+ "parentId": "page:page",+ "index": "aF",+ "props": {+ "dash": "draw",+ "size": "s",+ "fill": "none",+ "color": "black",+ "labelColor": "black",+ "bend": 0,+ "start": {+ "type": "point",+ "x": -1.2343578209806765,+ "y": -212.76689691126637+ },+ "end": {+ "type": "point",+ "x": 4.737015132919737,+ "y": 485.4301349286854+ },+ "arrowheadStart": "none",+ "arrowheadEnd": "arrow",+ "text": "",+ "font": "draw"+ },+ "typeName": "shape"+ },+ {+ "x": -263.0733406577134,+ "y": 204.43071626492787,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:S-rM8hP_9bPI7bHcM6fA9",+ "type": "arrow",+ "parentId": "page:page",+ "index": "aG",+ "props": {+ "dash": "draw",+ "size": "s",+ "fill": "pattern",+ "color": "black",+ "labelColor": "black",+ "bend": 0,+ "start": {+ "type": "point",+ "x": 0,+ "y": 0+ },+ "end": {+ "type": "point",+ "x": 1533.590296124883,+ "y": 2.581030230742101+ },+ "arrowheadStart": "none",+ "arrowheadEnd": "arrow",+ "text": "",+ "font": "draw"+ },+ "typeName": "shape"+ },+ {+ "x": -211.76143028276476,+ "y": 144.89631076376548,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:7Yp2VISNRq-4yzyDUbRo_",+ "type": "draw",+ "props": {+ "segments": [+ {+ "type": "free",+ "points": [+ {+ "x": 0,+ "y": 0,+ "z": 0.5+ }+ ]+ }+ ],+ "color": "black",+ "fill": "pattern",+ "dash": "draw",+ "size": "s",+ "isComplete": true,+ "isClosed": false,+ "isPen": false+ },+ "parentId": "page:page",+ "index": "aH",+ "typeName": "shape"+ },+ {+ "x": -228.6405644241911,+ "y": 127.71208677498385,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:dD9zx-_XXfigp0ztk-xUw",+ "type": "text",+ "props": {+ "color": "black",+ "size": "s",+ "w": 109,+ "text": "业务使用场景",+ "font": "draw",+ "align": "middle",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "aI",+ "typeName": "shape"+ },+ {+ "x": 200.3234851905786,+ "y": 101.54960228248558,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:c8f27NxMCcl_eEd1cDvDM",+ "type": "text",+ "props": {+ "color": "black",+ "size": "s",+ "w": 8,+ "text": "",+ "font": "draw",+ "align": "middle",+ "autoSize": true,+ "scale": 1+ },+ "parentId": "page:page",+ "index": "aJ",+ "typeName": "shape"+ },+ {+ "x": 234.14930682731426,+ "y": 75.35780666653568,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:V6KdGcs_HpXX_IrhaYduT",+ "type": "geo",+ "props": {+ "w": 184,+ "h": 80.59375,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "solid",+ "size": "s",+ "font": "draw",+ "text": "commands.service",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "aK",+ "typeName": "shape"+ },+ {+ "x": 463.87023129492707,+ "y": 76.20967138313347,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:K9h1YmhEJr16gyltlgcyY",+ "type": "geo",+ "props": {+ "w": 133.56201804325144,+ "h": 79.71615563961296,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "solid",+ "size": "s",+ "font": "draw",+ "text": "ui.render",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "aL",+ "typeName": "shape"+ },+ {+ "x": 644.5816371143542,+ "y": 74.68981447702538,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:kn8L8FqA2nnXEX5okAEm5",+ "type": "geo",+ "props": {+ "w": 212,+ "h": 80.59375,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "solid",+ "size": "s",+ "font": "draw",+ "text": "sheet.interceptor.service",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "aLV",+ "typeName": "shape"+ },+ {+ "x": 908.0503020268611,+ "y": 76.72630258441922,+ "rotation": 0,+ "isLocked": false,+ "opacity": 1,+ "meta": {},+ "id": "shape:Z90g80OBLaEosBphyD8n_",+ "type": "geo",+ "props": {+ "w": 212,+ "h": 80.59375,+ "geo": "rectangle",+ "color": "black",+ "labelColor": "black",+ "fill": "none",+ "dash": "solid",+ "size": "s",+ "font": "draw",+ "text": "other...",+ "align": "middle",+ "verticalAlign": "middle",+ "growY": 0,+ "url": ""+ },+ "parentId": "page:page",+ "index": "aLl",+ "typeName": "shape"+ }+ ]+}\ No newline at end of filediff --git a/packages/base-sheets/src/base-sheets-plugin.ts b/packages/base-sheets/src/base-sheets-plugin.tsindex 171ef1620b..e0a6a6385d 100644--- a/packages/base-sheets/src/base-sheets-plugin.ts+++ b/packages/base-sheets/src/base-sheets-plugin.ts@@ -5,6 +5,7 @@ import { BasicWorksheetController } from './controllers/basic-worksheet.controllimport { MergeCellController } from './controllers/merge-cell.controller';import { enUS } from './locale';import { BorderStyleManagerService } from './services/border-style-manager.service';+import { SheetPermissionService } from './services/permission';import { RefRangeService } from './services/ref-range.service';import { SelectionManagerService } from './services/selection-manager.service';@@ -37,7 +38,7 @@ export class SheetPlugin extends Plugin {[BorderStyleManagerService],[SelectionManagerService],[RefRangeService],-+ [SheetPermissionService],// controllers[BasicWorksheetController],[MergeCellController],diff --git a/packages/base-sheets/src/commands/commands/set-range-values.command.ts b/packages/base-sheets/src/commands/commands/set-range-values.command.tsindex cdf1cdd171..95a2cfdb13 100644--- a/packages/base-sheets/src/commands/commands/set-range-values.command.ts+++ b/packages/base-sheets/src/commands/commands/set-range-values.command.ts@@ -46,18 +46,13 @@ export const SetRangeValuesCommand: ICommand = {const undoRedoService = accessor.get(IUndoRedoService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetInterceptorService = accessor.get(SheetInterceptorService);const {value,range,workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),- worksheetId = univerInstanceService- .getCurrentUniverSheetInstance()-- .getActiveSheet()- .getSheetId(),+ worksheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),} = params;-const currentSelections = range ? [range] : selectionManagerService.getSelectionRanges();if (!currentSelections || !currentSelections.length) {return false;@@ -97,12 +92,21 @@ export const SetRangeValuesCommand: ICommand = {setRangeValuesMutationParams);+ if (+ !sheetInterceptorService.onCommandPermissionCheck({+ id: SetRangeValuesCommand.id,+ params: setRangeValuesMutationParams,+ })+ ) {+ return false;+ }+const setValueMutationResult = commandService.syncExecuteCommand(SetRangeValuesMutation.id,setRangeValuesMutationParams);- const { undos, redos } = accessor.get(SheetInterceptorService).onCommandExecute({+ const { undos, redos } = sheetInterceptorService.onCommandExecute({id: SetRangeValuesCommand.id,params: setRangeValuesMutationParams,});diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.tsindex d030ac88e1..39a5838d2b 100644--- a/packages/base-sheets/src/index.ts+++ b/packages/base-sheets/src/index.ts@@ -193,4 +193,5 @@ export {} from './commands/mutations/set-worksheet-row-height.mutation';export { type ISetSelectionsOperationParams, SetSelectionsOperation } from './commands/operations/selection.operation';export { type ISheetCommandSharedParams } from './commands/utils/interface';+export { SheetEditablePermission, SheetPermissionService } from './services/permission';export { RefRangeService } from './services/ref-range.service';diff --git a/packages/base-sheets/src/services/__tests__/sheet-permission.spec.ts b/packages/base-sheets/src/services/__tests__/sheet-permission.spec.tsnew file mode 100644index 0000000000..b84754f738--- /dev/null+++ b/packages/base-sheets/src/services/__tests__/sheet-permission.spec.ts@@ -0,0 +1,64 @@+import { ICommandService, IUniverInstanceService, Univer, UniverPermissionService } from '@univerjs/core';+import { Injector } from '@wendellhu/redi';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++import { SetRangeValuesCommand } from '../../commands/commands/set-range-values.command';+import { SheetEditablePermission, SheetPermissionService } from '../permission';+import { createTestBase, TEST_WORKBOOK_DATA_DEMO } from './util';++describe('test sheet permission service', () => {+ let univer: Univer;+ let commandService: ICommandService;+ let get: Injector['get'];+ beforeEach(() => {+ const testBed = createTestBase(TEST_WORKBOOK_DATA_DEMO, [[SheetPermissionService]]);+ get = testBed.get;+ univer = testBed.univer;+ commandService = testBed.get(ICommandService);+ commandService.registerCommand(SetRangeValuesCommand);+ });+ afterEach(() => {+ univer.dispose();+ });++ it('test set univer editable', () => {+ const initPermission = new SheetEditablePermission('1', '1');+ const univerInstanceService = get(IUniverInstanceService);+ const univerPermissionService = get(UniverPermissionService);++ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const sheet = workbook.getActiveSheet();+ const sheetPermissionService = get(SheetPermissionService);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(+ initPermission.value+ );+ univerPermissionService.setEditable(false);+ expect(univerPermissionService.getEditable()).toBe(false);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(false);++ univerPermissionService.setEditable(true);+ expect(univerPermissionService.getEditable()).toBe(true);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(true);+ });++ it('test set sheet editable', () => {+ const initPermission = new SheetEditablePermission('1', '1');+ const univerInstanceService = get(IUniverInstanceService);+ const univerPermissionService = get(UniverPermissionService);++ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const sheet = workbook.getActiveSheet();+ const sheetPermissionService = get(SheetPermissionService);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(+ initPermission.value+ );++ sheetPermissionService.setSheetEditable(false);+ expect(univerPermissionService.getEditable()).toBe(true);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(false);++ sheetPermissionService.setSheetEditable(true);+ expect(univerPermissionService.getEditable()).toBe(true);+ expect(sheetPermissionService.getSheetEditable(workbook.getUnitId(), sheet.getSheetId())).toBe(true);+ });+});diff --git a/packages/base-sheets/src/services/__tests__/util.ts b/packages/base-sheets/src/services/__tests__/util.tsnew file mode 100644index 0000000000..62aec5dd78--- /dev/null+++ b/packages/base-sheets/src/services/__tests__/util.ts@@ -0,0 +1,90 @@+import {+ ILogService,+ IUniverInstanceService,+ IWorkbookConfig,+ LocaleType,+ Plugin,+ PluginType,+ Univer,+} from '@univerjs/core';+import { Dependency, Inject, Injector } from '@wendellhu/redi';++export const TEST_WORKBOOK_DATA_DEMO: IWorkbookConfig = {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ cellData: {+ '0': {+ '0': {+ v: 'A1',+ },+ '1': {+ v: 'A2',+ },+ },+ },+ },+ },+ createdTime: '',+ creator: '',+ extensions: [],+ lastModifiedBy: '',+ locale: LocaleType.EN_US,+ modifiedTime: '',+ name: '',+ sheetOrder: [],+ styles: {},+ timeZone: '',+};++export function createTestBase(workbookConfig?: IWorkbookConfig, dependencies?: Dependency[]) {+ const univer = new Univer();++ let get: Injector['get'] | undefined;++ /**+ * This plugin hooks into Sheet's DI system to expose API to test scripts+ */+ class TestSpyPlugin extends Plugin {+ static override type = PluginType.Sheet;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super('test-plugin');++ this._injector = _injector;+ get = this._injector.get.bind(this._injector);+ }++ override onStarting(injector: Injector): void {+ dependencies?.forEach((d) => injector.add(d));+ }++ override onDestroy(): void {+ get = undefined;+ }+ }++ univer.registerPlugin(TestSpyPlugin);+ const sheet = univer.createUniverSheet(workbookConfig || TEST_WORKBOOK_DATA_DEMO);++ if (get === undefined) {+ throw new Error('[TestPlugin]: not hooked on!');+ }++ const univerInstanceService = get(IUniverInstanceService);+ univerInstanceService.focusUniverInstance('test');++ const logService = get(ILogService);+ logService.toggleLogEnabled(false); // change this to `true` to debug tests via logs++ return {+ univer,+ get,+ sheet,+ };+}diff --git a/packages/base-sheets/src/services/permission/index.ts b/packages/base-sheets/src/services/permission/index.tsnew file mode 100644index 0000000000..d37520e610--- /dev/null+++ b/packages/base-sheets/src/services/permission/index.ts@@ -0,0 +1,2 @@+export { SheetEditablePermission } from './permission-point';+export { SheetPermissionService } from './sheet-permission.service';diff --git a/packages/base-sheets/src/services/permission/permission-point.ts b/packages/base-sheets/src/services/permission/permission-point.tsnew file mode 100644index 0000000000..85d22cceb2--- /dev/null+++ b/packages/base-sheets/src/services/permission/permission-point.ts@@ -0,0 +1,15 @@+import { PermissionPoint } from '@univerjs/core';++const SheetEditablePermissionPoint = 'univer.sheet.editable';++export class SheetEditablePermission extends PermissionPoint<boolean> {+ id = SheetEditablePermissionPoint;+ value = true;+ constructor(+ private _workbookId: string,+ private _worksheetId: string+ ) {+ super();+ this.id = `${SheetEditablePermissionPoint}_${_workbookId}_${_worksheetId}`;+ }+}diff --git a/packages/base-sheets/src/services/permission/sheet-permission.service.ts b/packages/base-sheets/src/services/permission/sheet-permission.service.tsnew file mode 100644index 0000000000..b0f3e1035b--- /dev/null+++ b/packages/base-sheets/src/services/permission/sheet-permission.service.ts@@ -0,0 +1,115 @@+import {+ Disposable,+ getTypeFromPermissionItemList,+ IPermissionService,+ IUniverInstanceService,+ LifecycleStages,+ OnLifecycle,+ PermissionService,+ SheetInterceptorService,+ toDisposable,+ UniverEditablePermissionPoint,+} from '@univerjs/core';+import { Inject } from '@wendellhu/redi';+import { map } from 'rxjs/operators';++import { SetRangeValuesCommand } from '../../commands/commands/set-range-values.command';+import { SheetEditablePermission } from './permission-point';++@OnLifecycle(LifecycleStages.Ready, SheetPermissionService)+export class SheetPermissionService extends Disposable {+ constructor(+ @Inject(IPermissionService) private _permissionService: PermissionService,+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,+ @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService+ ) {+ super();+ this._init();+ this._interceptCommandPermission();+ }++ private _init() {+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();+ const unitId = workbook.getUnitId();+ workbook.getSheets().forEach((worksheet) => {+ const subComponentId = worksheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(unitId, subComponentId);+ this._permissionService.addPermissionPoint(sheetPermission);+ });+ this.disposeWithMe(+ toDisposable(+ workbook.sheetCreated$.subscribe((worksheet) => {+ const subComponentId = worksheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(unitId, subComponentId);+ this._permissionService.addPermissionPoint(sheetPermission);+ })+ )+ );+ this.disposeWithMe(+ toDisposable(+ workbook.sheetDisposed$.subscribe((worksheet) => {+ const subComponentId = worksheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(unitId, subComponentId);+ this._permissionService.deletePermissionPoint(sheetPermission.id);+ })+ )+ );+ }++ private _interceptCommandPermission() {+ this.disposeWithMe(+ this._sheetInterceptorService.interceptCommandPermission({+ checkPermission: (commandInfo) => {+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();+ const sheet = workbook?.getActiveSheet();+ const workbookId = workbook?.getUnitId();+ const sheetId = sheet?.getSheetId();+ if (!workbookId || !sheetId) {+ return false;+ }+ switch (commandInfo.id) {+ case SetRangeValuesCommand.id: {+ return this.getSheetEditable(workbookId, sheetId);+ }+ }+ return true;+ },+ })+ );+ }++ getEditable$(workbookId?: string, sheetId?: string) {+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();+ const _workbookId = workbookId || workbook.getUnitId();+ const sheet = workbook.getActiveSheet();+ const _sheetId = sheetId || sheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(_workbookId, _sheetId);+ return this._permissionService.composePermission$([UniverEditablePermissionPoint, sheetPermission.id]).pipe(+ map(([univerEditable, sheetEditable]) => {+ const editable = univerEditable.value && sheetEditable.value;+ const status = getTypeFromPermissionItemList([univerEditable, sheetEditable]);+ return { value: editable, status };+ })+ );+ }++ getSheetEditable(workbookId?: string, sheetId?: string) {+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();+ const _workbookId = workbookId || workbook.getUnitId();+ const sheet = workbook.getActiveSheet();+ const _sheetId = sheetId || sheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(_workbookId, _sheetId);+ return this._permissionService+ .composePermission([UniverEditablePermissionPoint, sheetPermission.id])+ .every((item) => item.value);+ }++ setSheetEditable(v: boolean, workbookId?: string, sheetId?: string) {+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();+ const _workbookId = workbookId || workbook.getUnitId();+ const sheet = workbook.getActiveSheet();+ const _sheetId = sheetId || sheet.getSheetId();+ const sheetPermission = new SheetEditablePermission(_workbookId, _sheetId);+ this._permissionService.updatePermissionPoint(sheetPermission.id, v);+ }+}diff --git a/packages/base-sheets/src/services/ref-range.service.ts b/packages/base-sheets/src/services/ref-range.service.tsindex 414b1f7e54..e1c3e52879 100644--- a/packages/base-sheets/src/services/ref-range.service.ts+++ b/packages/base-sheets/src/services/ref-range.service.ts@@ -92,7 +92,7 @@ export class RefRangeService extends Disposable {);}case InsertRowCommand.id: {- const params = command as unknown as ICommandInfo<IInsertRowCommandParams>;+ const params = command as ICommandInfo<IInsertRowCommandParams>;const rowStart = params.params!.range.startRow;const range: IRange = {startRow: rowStart,@@ -103,7 +103,7 @@ export class RefRangeService extends Disposable {return this._checkRange([range], workbookId, worksheetId);}case InsertColCommand.id: {- const params = command as unknown as ICommandInfo<IInsertColCommandParams>;+ const params = command as ICommandInfo<IInsertColCommandParams>;const colStart = params.params!.range.startColumn;const range: IRange = {startRow: 0,@@ -114,7 +114,7 @@ export class RefRangeService extends Disposable {return this._checkRange([range], workbookId, worksheetId);}case RemoveRowCommand.id: {- const params = command as unknown as ICommandInfo<RemoveRowColCommandParams>;+ const params = command as ICommandInfo<RemoveRowColCommandParams>;const ranges = params.params?.ranges || [];const rowStart = Math.min(...ranges.map((range) => range.startRow));const range: IRange = {@@ -139,7 +139,7 @@ export class RefRangeService extends Disposable {}case DeleteRangeMoveUpCommand.id:case InsertRangeMoveDownCommand.id: {- const params = command as unknown as ICommandInfo<InsertRangeMoveDownCommandParams>;+ const params = command as ICommandInfo<InsertRangeMoveDownCommandParams>;const ranges = params.params!.ranges || getSelectionRanges(this._selectionManagerService);const effectRanges = ranges.map((range) => ({startRow: range.startRow,@@ -151,7 +151,7 @@ export class RefRangeService extends Disposable {}case DeleteRangeMoveLeftCommand.id:case InsertRangeMoveRightCommand.id: {- const params = command as unknown as ICommandInfo<InsertRangeMoveRightCommandParams>;+ const params = command as ICommandInfo<InsertRangeMoveRightCommandParams>;const ranges = params.params!.ranges || getSelectionRanges(this._selectionManagerService);const effectRanges = ranges.map((range) => ({startRow: range.startRow,diff --git a/packages/core/src/basics/univer.ts b/packages/core/src/basics/univer.tsindex e4eb38df0b..d54c305e07 100644--- a/packages/core/src/basics/univer.ts+++ b/packages/core/src/basics/univer.ts@@ -16,7 +16,8 @@ import { LifecycleStages } from '../services/lifecycle/lifecycle';import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';import { LocaleService } from '../services/locale/locale.service';import { DesktopLogService, ILogService } from '../services/log/log.service';-import { DesktopPermissionService, IPermissionService } from '../services/permission/permission.service';+import { IPermissionService, PermissionService } from '../services/permission/permission.service';+import { UniverPermissionService } from '../services/permission/univer.permission.service';import { ThemeService } from '../services/theme/theme.service';import { IUndoRedoService, LocalUndoRedoService } from '../services/undoredo/undoredo.service';import { GenName } from '../shared/gen-name';@@ -184,10 +185,11 @@ export class Univer {[GenName],[LifecycleService],[LifecycleInitializerService],+ [IPermissionService, { useClass: PermissionService }],+ [UniverPermissionService],[ILogService, { useClass: DesktopLogService, lazy: true }],[ICommandService, { useClass: CommandService, lazy: true }],[IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],- [IPermissionService, { useClass: DesktopPermissionService }],[IConfigService, { useClass: ConfigService }],[IContextService, { useClass: ContextService }],[IFloatingObjectManagerService, { useClass: FloatingObjectManagerService, lazy: true }],diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 39ad49a33b..5d4d9a4736 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -28,7 +28,13 @@ export { LifecycleService } from './services/lifecycle/lifecycle.service';export { ILocalStorageService } from './services/local-storage/local-storage.service';export { LocaleService } from './services/locale/locale.service';export { DesktopLogService, ILogService } from './services/log/log.service';-export { DesktopPermissionService, IPermissionService } from './services/permission/permission.service';+export {+ IPermissionService,+ PermissionService,+ UniverEditablePermission,+ UniverEditablePermissionPoint,+ UniverPermissionService,+} from './services/permission';export {type ICellInterceptor,type ISheetLocation,@@ -48,8 +54,6 @@ export {// #endregionexport * from './shared';-export { Disposable, DisposableCollection, fromObservable, RxDisposable, toDisposable } from './shared/lifecycle';-export { createRowColIter, type IRowColIter } from './shared/row-col-iter';// #region sheetdiff --git a/packages/core/src/services/permission/index.ts b/packages/core/src/services/permission/index.tsnew file mode 100644index 0000000000..d72350e726--- /dev/null+++ b/packages/core/src/services/permission/index.ts@@ -0,0 +1,3 @@+export { IPermissionService, PermissionService } from './permission.service';+export { UniverEditablePermission, UniverEditablePermissionPoint } from './permission-point';+export { UniverPermissionService } from './univer.permission.service';diff --git a/packages/core/src/services/permission/permission-point.ts b/packages/core/src/services/permission/permission-point.tsnew file mode 100644index 0000000000..f990927d62--- /dev/null+++ b/packages/core/src/services/permission/permission-point.ts@@ -0,0 +1,7 @@+import { PermissionPoint } from '../../shared';++export const UniverEditablePermissionPoint = 'univer.editable';+export class UniverEditablePermission extends PermissionPoint<boolean> {+ id = UniverEditablePermissionPoint;+ value = true;+}diff --git a/packages/core/src/services/permission/permission.service.ts b/packages/core/src/services/permission/permission.service.tsindex e8deec666f..44c775ec86 100644--- a/packages/core/src/services/permission/permission.service.ts+++ b/packages/core/src/services/permission/permission.service.ts@@ -1,29 +1,92 @@import { createIdentifier } from '@wendellhu/redi';-import { BehaviorSubject, Observable } from 'rxjs';+import { BehaviorSubject, combineLatest, Observable } from 'rxjs';+import { map } from 'rxjs/operators';-import { Disposable } from '../../shared/lifecycle';+import { Disposable, PermissionPoint, PermissionStatus } from '../../shared';+import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';export interface IPermissionService {- readonly editable$: Observable<boolean>;-- setEditable(editable: boolean): void;+ deletePermissionPoint(id: string): void;+ addPermissionPoint(item: PermissionPoint): boolean;+ updatePermissionPoint(id: string, value: any): void;+ getPermissionPoint(id: string): PermissionPoint;+ composePermission$(permissionIdList: string[]): Observable<PermissionPoint[]>;+ composePermission(permissionIdList: string[]): PermissionPoint[];}-export const IPermissionService = createIdentifier<IPermissionService>('univer.permission-service');-export class DesktopPermissionService extends Disposable implements IPermissionService {- readonly editable$: Observable<boolean>;+@OnLifecycle(LifecycleStages.Starting, PermissionService)+export class PermissionService extends Disposable implements IPermissionService {+ constructor(initPermissionConfig: PermissionPoint[] = []) {+ super();+ initPermissionConfig.forEach((item) => {+ this.permissionPointMap.set(item.id, new BehaviorSubject<PermissionPoint>(item));+ });+ }++ private permissionPointMap: Map<string, BehaviorSubject<PermissionPoint>> = new Map();- private readonly _editable$: BehaviorSubject<boolean>;+ deletePermissionPoint = (id: string) => {+ const subject = this.permissionPointMap.get(id);+ if (subject) {+ subject.complete();+ this.permissionPointMap.delete(id);+ }+ };- constructor() {- super();+ addPermissionPoint = (item: PermissionPoint) => {+ if (!this.permissionPointMap.has(item.id)) {+ this.permissionPointMap.set(item.id, new BehaviorSubject(item));+ return true;+ }+ return false;+ };++ updatePermissionPoint = (permissionId: string, value: any) => {+ const permissionSubject = this.permissionPointMap.get(permissionId);+ if (permissionSubject) {+ const subject = permissionSubject.getValue() as PermissionPoint;+ subject.value = value;+ subject.status = PermissionStatus.DONE;+ permissionSubject.next(subject);+ }+ };++ getPermissionPoint = (permissionId: string) => {+ const item = this.permissionPointMap.get(permissionId);+ if (item) {+ return item.getValue();+ }+ throw new Error(`${permissionId} permissionPoint does not exist`);+ };- this._editable$ = new BehaviorSubject(true);- this.editable$ = this._editable$.asObservable();+ composePermission$(permissionIdList: string[]) {+ const subjectList = permissionIdList.map((id) => {+ const subject = this.permissionPointMap.get(id);+ if (!subject) {+ throw new Error(`${id} permissionPoint is not exist`);+ }+ return subject.asObservable();+ });+ return combineLatest(subjectList).pipe(+ // Check that all permissions exist+ map((list) => {+ if (list.every((item) => this.permissionPointMap.get(item.id))) {+ return list;+ }+ return list;+ })+ );}- setEditable(editable: boolean): void {- this._editable$.next(editable);+ composePermission(permissionIdList: string[]) {+ const valueList = permissionIdList.map((id) => {+ const subject = this.permissionPointMap.get(id);+ if (!subject) {+ throw new Error(`${id} permissionPoint is not exist`);+ }+ return subject.getValue();+ });+ return valueList;}}diff --git a/packages/core/src/services/permission/univer.permission.service.ts b/packages/core/src/services/permission/univer.permission.service.tsnew file mode 100644index 0000000000..b0f7d53965--- /dev/null+++ b/packages/core/src/services/permission/univer.permission.service.ts@@ -0,0 +1,34 @@+import { Inject } from '@wendellhu/redi';++import { Disposable } from '../../shared';+import { IUniverInstanceService } from '../instance/instance.service';+import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';+import { IPermissionService } from './permission.service';+import { UniverEditablePermission } from './permission-point';++@OnLifecycle(LifecycleStages.Starting, UniverPermissionService)+export class UniverPermissionService extends Disposable {+ constructor(+ @Inject(IPermissionService) private _permissionService: IPermissionService,+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService+ ) {+ super();+ this._init();+ }++ private _init() {+ const univerEditablePermission = new UniverEditablePermission();+ this._permissionService.addPermissionPoint(univerEditablePermission);+ }++ getEditable() {+ const univerEditablePermission = new UniverEditablePermission();+ const permission = this._permissionService.getPermissionPoint(univerEditablePermission.id);+ return permission.value;+ }++ setEditable(v: boolean) {+ const univerEditablePermission = new UniverEditablePermission();+ this._permissionService.updatePermissionPoint(univerEditablePermission.id, v);+ }+}diff --git a/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts b/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.tsindex cd0a19ee69..1659a44231 100644--- a/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts+++ b/packages/core/src/services/sheet-interceptor/sheet-interceptor.service.ts@@ -62,6 +62,13 @@ export interface ICommandInterceptor {getMutations(command: ICommandInfo): IUndoRedoCommandInfos;}+export interface ICommandPermissionInterceptor {+ /**+ * This function maybe have side effects ,a pop-up/alert/confirm may be required when the return value is false+ */+ checkPermission(command: ICommandInfo): boolean;+}+/*** This class expose methods for sheet features to inject code to sheet underlying logic.*@@ -71,6 +78,7 @@ export interface ICommandInterceptor {export class SheetInterceptorService extends Disposable {private _cellInterceptors: ICellInterceptor[] = [];private _commandInterceptors: ICommandInterceptor[] = [];+ private _commandPermissionInterceptor: ICommandPermissionInterceptor[] = [];private readonly _workbookDisposables = new Map<string, IDisposable>();private readonly _worksheetDisposables = new Map<string, IDisposable>();@@ -139,6 +147,14 @@ export class SheetInterceptorService extends Disposable {return this.disposeWithMe(toDisposable(() => remove(this._commandInterceptors, interceptor)));}+ interceptCommandPermission(interceptor: ICommandPermissionInterceptor): IDisposable {+ if (this._commandPermissionInterceptor.includes(interceptor)) {+ throw new Error('[SheetInterceptorService]: Interceptor already exists!');+ }+ this._commandPermissionInterceptor.push(interceptor);+ return this.disposeWithMe(toDisposable(() => remove(this._commandPermissionInterceptor, interceptor)));+ }+/*** When command is executing, call this method to gether undo redo mutations from upper features.* @param command@@ -153,6 +169,15 @@ export class SheetInterceptorService extends Disposable {};}+ /**+ * Check the permissions of the user when commands will be executed.+ * If one of the return values is false, the command is not executed.+ */+ onCommandPermissionCheck(command: ICommandInfo): boolean {+ const result = this._commandPermissionInterceptor.some((handler) => !handler.checkPermission(command));+ return !result;+ }+private _interceptWorkbook(workbook: Workbook): void {const disposables = new DisposableCollection();const workbookId = workbook.getUnitId();diff --git a/packages/core/src/shared/index.ts b/packages/core/src/shared/index.tsindex b8ef3e49e6..9e551a7f36 100644--- a/packages/core/src/shared/index.ts+++ b/packages/core/src/shared/index.ts@@ -13,15 +13,18 @@ export * from './group-model';export * from './hash-algorithm';export * from './io-http';export * from './io-socket';+export * from './lifecycle';export * from './locale';export * from './logger';export * from './lru/index';export * from './migrate/index';export * from './object-array';export * from './object-matrix';+export * from './permission';export * from './random';export * from './rectangle';export * from './reference';+export * from './row-col-iter';export * from './sequence';export * from './serialize/index';export * from './sort-rules';diff --git a/packages/core/src/shared/permission/index.ts b/packages/core/src/shared/permission/index.tsnew file mode 100644index 0000000000..1e62fcb014--- /dev/null+++ b/packages/core/src/shared/permission/index.ts@@ -0,0 +1,17 @@+export enum PermissionStatus {+ INIT = 'init',+ FETCHING = 'fetching',+ DONE = 'done',+}+export abstract class PermissionPoint<T = any> {+ abstract id: string; // permission+ abstract value: T;+ status = PermissionStatus.INIT;+}++export const getTypeFromPermissionItemList = (list: PermissionPoint[]) =>+ list.some((item) => item.status === PermissionStatus.INIT)+ ? PermissionStatus.INIT+ : list.some((item) => item.status === PermissionStatus.FETCHING)+ ? PermissionStatus.FETCHING+ : PermissionStatus.DONE;diff --git a/packages/sheets-plugin-debugger/package.json b/packages/sheets-plugin-debugger/package.jsonindex 0da3b7897a..d6c1bc8775 100644--- a/packages/sheets-plugin-debugger/package.json+++ b/packages/sheets-plugin-debugger/package.json@@ -23,6 +23,7 @@"@univerjs/base-ui": "workspace:*","@univerjs/core": "workspace:*","@univerjs/design": "workspace:*",+ "@univerjs/base-sheets": "workspace:*","@wendellhu/redi": "^0.12.10"}-}+}\ No newline at end of filediff --git a/packages/sheets-plugin-debugger/src/commands/operations/set.editable.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/set.editable.operation.tsnew file mode 100644index 0000000000..705f2b972f--- /dev/null+++ b/packages/sheets-plugin-debugger/src/commands/operations/set.editable.operation.ts@@ -0,0 +1,25 @@+// eslint-disable-next-line import/no-extraneous-dependencies+import { SheetPermissionService } from '@univerjs/base-sheets';+import { CommandType, ICommand, UniverPermissionService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++export interface ISetEditableCommandParams {+ value: 'sheet' | 'univer';+}++export const SetEditable: ICommand = {+ id: 'debugger.operation.set.editable',+ type: CommandType.OPERATION,+ handler: async (accessor: IAccessor, params: ISetEditableCommandParams) => {+ if (params.value === 'sheet') {+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const editable = sheetPermissionService.getSheetEditable();+ sheetPermissionService.setSheetEditable(!editable);+ } else {+ const univerPermissionService = accessor.get(UniverPermissionService);+ const editable = univerPermissionService.getEditable();+ univerPermissionService.setEditable(!editable);+ }+ return true;+ },+};diff --git a/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts b/packages/sheets-plugin-debugger/src/controllers/debugger.controller.tsindex 87cbcf0933..7733d4b141 100644--- a/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts+++ b/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts@@ -7,6 +7,7 @@ import { DialogOperation } from '../commands/operations/dialog.operation';import { LocaleOperation } from '../commands/operations/locale.operation';import { MessageOperation } from '../commands/operations/message.operation';import { NotificationOperation } from '../commands/operations/notification.operation';+import { SetEditable } from '../commands/operations/set.editable.operation';import { SidebarOperation } from '../commands/operations/sidebar.operation';import { ThemeOperation } from '../commands/operations/theme.operation';import {@@ -15,6 +16,7 @@ import {LocaleMenuItemFactory,MessageMenuItemFactory,NotificationMenuItemFactory,+ SetEditableMenuItemFactory,SidebarMenuItemFactory,ThemeMenuItemFactory,} from './menu';@@ -36,6 +38,7 @@ export class DebuggerController extends Disposable {ConfirmOperation,MessageOperation,SidebarOperation,+ SetEditable,].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}@@ -49,6 +52,7 @@ export class DebuggerController extends Disposable {DialogMenuItemFactory,ConfirmMenuItemFactory,SidebarMenuItemFactory,+ SetEditableMenuItemFactory,].forEach((factory) => {this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));});diff --git a/packages/sheets-plugin-debugger/src/controllers/menu.ts b/packages/sheets-plugin-debugger/src/controllers/menu.tsindex 2a0f200598..5806fce6b2 100644--- a/packages/sheets-plugin-debugger/src/controllers/menu.ts+++ b/packages/sheets-plugin-debugger/src/controllers/menu.ts@@ -8,6 +8,7 @@ import { DialogOperation } from '../commands/operations/dialog.operation';import { LocaleOperation } from '../commands/operations/locale.operation';import { MessageOperation } from '../commands/operations/message.operation';import { NotificationOperation } from '../commands/operations/notification.operation';+import { SetEditable } from '../commands/operations/set.editable.operation';import { SidebarOperation } from '../commands/operations/sidebar.operation';import { ThemeOperation } from '../commands/operations/theme.operation';@@ -146,3 +147,23 @@ export function SidebarMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {],};}++export function SetEditableMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {+ return {+ id: SetEditable.id,+ title: 'Editable',+ tooltip: 'Editable',+ type: MenuItemType.SELECTOR,+ positions: [MenuPosition.TOOLBAR_OTHERS],+ selections: [+ {+ label: 'univer',+ value: 'univer',+ },+ {+ label: 'sheet',+ value: 'sheet',+ },+ ],+ };+}diff --git a/packages/sheets-plugin-numfmt/src/controllers/menu.ts b/packages/sheets-plugin-numfmt/src/controllers/menu.tsindex c4505b75af..7c75490be4 100644--- a/packages/sheets-plugin-numfmt/src/controllers/menu.ts+++ b/packages/sheets-plugin-numfmt/src/controllers/menu.ts@@ -1,5 +1,5 @@import { IMenuSelectorItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';-import { ICommandService, IPermissionService } from '@univerjs/core';+import { ICommandService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';import { DEFAULT_DATA, MORE_FORMATS_SELECTIONS } from '../basics/const/default-data';@@ -7,7 +7,7 @@ import { SetNumfmtRangeDataCommand } from '../commands/commands/set-numfmt-rangeimport { ShowModalOperation } from '../commands/operations/show-modal.operation';export function NumfmtRangeDataMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);// const selectionManager = accessor.get(ISelectionManager);@@ -57,7 +57,7 @@ export function NumfmtRangeDataMenuItemFactory(accessor: IAccessor): IMenuSelect}export function OpenMoreFormatsModalMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);// const selectionManager = accessor.get(ISelectionManager);return {diff --git a/packages/ui-plugin-sheets/src/controllers/menu/__tests__/create-menu-test-bed.ts b/packages/ui-plugin-sheets/src/controllers/menu/__tests__/create-menu-test-bed.tsindex 4aabf51117..60c7b532a0 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/__tests__/create-menu-test-bed.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/__tests__/create-menu-test-bed.ts@@ -1,4 +1,4 @@-import { SelectionManagerService } from '@univerjs/base-sheets';+import { SelectionManagerService, SheetPermissionService } from '@univerjs/base-sheets';import { DesktopMenuService, DesktopShortcutService, IMenuService, IShortcutService } from '@univerjs/base-ui';import { IWorkbookConfig, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';@@ -54,6 +54,7 @@ export function createMenuTestBed() {injector.add([SelectionManagerService]);injector.add([IShortcutService, { useClass: DesktopShortcutService }]);injector.add([IMenuService, { useClass: DesktopMenuService }]);+ injector.add([SheetPermissionService]);}override onDestroy(): void {diff --git a/packages/ui-plugin-sheets/src/controllers/menu/__tests__/menu.spec.ts b/packages/ui-plugin-sheets/src/controllers/menu/__tests__/menu.spec.tsindex ae2d323307..2528ae236c 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/__tests__/menu.spec.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/__tests__/menu.spec.ts@@ -4,14 +4,15 @@ import {SetBoldCommand,SetRangeValuesMutation,SetStyleCommand,+ SheetPermissionService,} from '@univerjs/base-sheets';import {DisposableCollection,ICommandService,- IPermissionService,RANGE_TYPE,toDisposable,Univer,+ UniverPermissionService,} from '@univerjs/core';import { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';@@ -48,6 +49,8 @@ describe('Test menu items', () => {it('Test bold menu item', async () => {let activated = false;let disabled = false;+ const sheetPermissionService = get(SheetPermissionService);+ const univerPermissionService = get(UniverPermissionService);const menuItem = get(Injector).invoke(BoldMenuItemFactory);disposableCollection.add(toDisposable(menuItem.activated$!.subscribe((v: boolean) => (activated = v))));@@ -81,8 +84,15 @@ describe('Test menu items', () => {expect(await commandService.executeCommand(SetBoldCommand.id)).toBeTruthy();expect(activated).toBe(true);- const permissionService = get(IPermissionService);- permissionService.setEditable(false);- expect(disabled).toBe(true);+ expect(sheetPermissionService.getSheetEditable()).toBe(true);+ sheetPermissionService.setSheetEditable(false);+ expect(sheetPermissionService.getSheetEditable()).toBe(false);+ sheetPermissionService.setSheetEditable(true);+ univerPermissionService.setEditable(false);+ expect(sheetPermissionService.getSheetEditable()).toBe(false);+ expect(univerPermissionService.getEditable()).toBe(false);+ univerPermissionService.setEditable(true);+ expect(univerPermissionService.getEditable()).toBe(true);+ expect(sheetPermissionService.getSheetEditable()).toBe(true);});});diff --git a/packages/ui-plugin-sheets/src/controllers/menu/border.menu.ts b/packages/ui-plugin-sheets/src/controllers/menu/border.menu.tsindex 2410f2c720..048e1f13bb 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/border.menu.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/border.menu.ts@@ -5,7 +5,7 @@ import {SetBorderStyleCommand,} from '@univerjs/base-sheets';import { IMenuSelectorItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';-import { BorderStyleTypes, ICommandService, IPermissionService } from '@univerjs/core';+import { BorderStyleTypes, ICommandService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';import { map } from 'rxjs/operators';@@ -170,7 +170,7 @@ export const BORDER_SIZE_CHILDREN = [];export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const borderStyleManagerService = accessor.get(BorderStyleManagerService);diff --git a/packages/ui-plugin-sheets/src/controllers/menu/menu.ts b/packages/ui-plugin-sheets/src/controllers/menu/menu.tsindex 89e801409e..711ad5d03d 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/menu.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/menu.ts@@ -39,6 +39,7 @@ import {SetWorksheetHideCommand,SetWorksheetRowIsAutoHeightCommand,SetWorksheetShowCommand,+ SheetPermissionService,} from '@univerjs/base-sheets';import {CopyCommand,@@ -54,7 +55,6 @@ import {FontWeight,HorizontalAlign,ICommandService,- IPermissionService,IUniverInstanceService,RANGE_TYPE,VerticalAlign,@@ -122,10 +122,11 @@ export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonItexport function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {const commandService = accessor.get(ICommandService);- const permissionService = accessor.get(IPermissionService);+ const sheetPermissionService = accessor.get(SheetPermissionService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeBoldCommand.id,type: MenuItemType.BUTTON,@@ -134,18 +135,11 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {tooltip: 'toolbar.bold',positions: [MenuPosition.TOOLBAR_START],disabled$: new Observable<boolean>((subscriber) => {- let editable = false;-- // it can hook in other business logic via permissionService and sheet business logic- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- subscriber.next(!editable);+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-- subscriber.next(!editable);-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),activated$: new Observable<boolean>((subscriber) => {@@ -179,11 +173,12 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {}export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {- const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeItalicCommand.id,type: MenuItemType.BUTTON,@@ -192,20 +187,11 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {tooltip: 'toolbar.italic',positions: [MenuPosition.TOOLBAR_START],disabled$: new Observable<boolean>((subscriber) => {- let editable = false;- function update() {- subscriber.next(!editable);- }-- update();-- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- update();+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),activated$: new Observable<boolean>((subscriber) => {@@ -237,11 +223,12 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {}export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {- const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeUnderlineCommand.id,type: MenuItemType.BUTTON,@@ -250,20 +237,11 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {tooltip: 'toolbar.underline',positions: [MenuPosition.TOOLBAR_START],disabled$: new Observable<boolean>((subscriber) => {- let editable = false;- function update() {- subscriber.next(!editable);- }-- update();-- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- update();+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),activated$: new Observable<boolean>((subscriber) => {@@ -295,11 +273,12 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {}export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem {- const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeStrickThroughCommand.id,type: MenuItemType.BUTTON,@@ -308,20 +287,11 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIttooltip: 'toolbar.strikethrough',positions: [MenuPosition.TOOLBAR_START],disabled$: new Observable<boolean>((subscriber) => {- let editable = false;- function update() {- subscriber.next(!editable);- }-- update();-- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- update();+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),activated$: new Observable<boolean>((subscriber) => {@@ -488,11 +458,12 @@ export const FONT_FAMILY_CHILDREN = [];export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeFontFamilyCommand.id,tooltip: 'toolbar.font',@@ -503,20 +474,11 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelpositions: [MenuPosition.TOOLBAR_START],selections: FONT_FAMILY_CHILDREN,disabled$: new Observable((subscriber) => {- let editable = false;- function update() {- subscriber.next(!editable);- }-- update();-- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- update();+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),value$: new Observable((subscriber) => {@@ -550,11 +512,12 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel}export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {- const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);-+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeFontSizeCommand.id,tooltip: 'toolbar.fontSize',@@ -569,20 +532,11 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelecpositions: [MenuPosition.TOOLBAR_START],selections: FONT_SIZE_CHILDREN,disabled$: new Observable<boolean>((subscriber) => {- let editable = false;- function update() {- subscriber.next(!editable);- }-- update();-- const permission$ = permissionService.editable$.subscribe((e) => {- editable = e;- update();+ const permission$ = sheetPermissionService.getEditable$(workbookId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);});-return () => {- permission$.unsubscribe();+ permission$?.unsubscribe();};}),value$: new Observable((subscriber) => {diff --git a/packages/ui-plugin-sheets/src/controllers/menu/merge.menu.ts b/packages/ui-plugin-sheets/src/controllers/menu/merge.menu.tsindex 2cb8e62f5f..69d11ef56e 100644--- a/packages/ui-plugin-sheets/src/controllers/menu/merge.menu.ts+++ b/packages/ui-plugin-sheets/src/controllers/menu/merge.menu.ts@@ -6,11 +6,11 @@ import {RemoveWorksheetMergeCommand,} from '@univerjs/base-sheets';import { IMenuButtonItem, IMenuSelectorItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';-import { ICommandService, IPermissionService } from '@univerjs/core';+import { ICommandService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);return {@@ -23,7 +23,7 @@ export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem};}export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);return {@@ -34,7 +34,7 @@ export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonIte};}export function CellMergeVerticalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);return {@@ -45,7 +45,7 @@ export function CellMergeVerticalMenuItemFactory(accessor: IAccessor): IMenuButt};}export function CellMergeHorizontalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);return {@@ -56,7 +56,7 @@ export function CellMergeHorizontalMenuItemFactory(accessor: IAccessor): IMenuBu};}export function CellMergeCancelMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {- const permissionService = accessor.get(IPermissionService);+ // const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);return {diff --git a/packages/ui-plugin-sheets/src/controllers/move-range.controller.ts b/packages/ui-plugin-sheets/src/controllers/move-range.controller.tsindex 273bdb1b1c..1c9503768c 100644--- a/packages/ui-plugin-sheets/src/controllers/move-range.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/move-range.controller.ts@@ -61,6 +61,10 @@ export class MoveRangeController extends Disposable {return;}+ if (toRange.startRow < 0 || toRange.startColumn < 0) {+ return;+ }+const params: IMoveRangeCommandParams = {fromRange,toRange,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 4c795cd7cc..784dec237a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -826,6 +826,9 @@ importers:packages/sheets-plugin-debugger:dependencies:+ '@univerjs/base-sheets':+ specifier: workspace:*+ version: link:../base-sheets'@univerjs/base-ui':specifier: workspace:*version: link:../base-ui