Skip to content

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.

revert(permission): fix the permission mutation works before init (#6144)

wpxp123456af7d01cd1cd2
diff --git a/packages/sheets/src/commands/mutations/add-worksheet-protection.mutation.ts b/packages/sheets/src/commands/mutations/add-worksheet-protection.mutation.ts
index 8cd46696cc..ec9ce0dd53 100644
--- a/packages/sheets/src/commands/mutations/add-worksheet-protection.mutation.ts
+++ b/packages/sheets/src/commands/mutations/add-worksheet-protection.mutation.ts
@@ -17,7 +17,6 @@
import type { IMutation } from '@univerjs/core';
import type { IWorksheetProtectionRule } from '../../services/permission/type';
import { CommandType } from '@univerjs/core';
-import { SheetPermissionInitController } from '../../controllers/permission/sheet-permission-init.controller';
import { WorksheetProtectionRuleModel } from '../../services/permission/worksheet-permission/worksheet-permission-rule.model';
export interface IAddWorksheetProtectionParams {
@@ -30,15 +29,7 @@ export const AddWorksheetProtectionMutation: IMutation<IAddWorksheetProtectionPa
id: 'sheet.mutation.add-worksheet-protection',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const sheetPermissionInitController = accessor.get(SheetPermissionInitController);
const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);
- if (!sheetPermissionInitController.getIsPermissionInitFinish()) {
- sheetPermissionInitController.addCmdToBufferList({
- id: AddWorksheetProtectionMutation.id,
- params,
- });
- return true;
- }
const { unitId, rule } = params;
worksheetProtectionRuleModel.addRule(unitId, rule);
return true;
diff --git a/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts b/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts
index 8a0ce8594e..fdc538086a 100644
--- a/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts
+++ b/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts
@@ -16,7 +16,6 @@
import type { IMutation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
-import { SheetPermissionInitController } from '../../controllers/permission/sheet-permission-init.controller';
import { WorksheetProtectionRuleModel } from '../../services/permission/worksheet-permission/worksheet-permission-rule.model';
export interface IDeleteWorksheetProtectionParams {
@@ -29,16 +28,7 @@ export const DeleteWorksheetProtectionMutation: IMutation<IDeleteWorksheetProtec
type: CommandType.MUTATION,
handler: (accessor, params) => {
const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);
- const sheetPermissionInitController = accessor.get(SheetPermissionInitController);
- if (!sheetPermissionInitController.getIsPermissionInitFinish()) {
- sheetPermissionInitController.addCmdToBufferList({
- id: DeleteWorksheetProtectionMutation.id,
- params,
- });
- return true;
- }
const { unitId, subUnitId } = params;
-
worksheetProtectionRuleModel.deleteRule(unitId, subUnitId);
return true;
},
diff --git a/packages/sheets/src/controllers/permission/sheet-permission-init.controller.ts b/packages/sheets/src/controllers/permission/sheet-permission-init.controller.ts
index 28a4b45f1e..c41f2d8d84 100644
--- a/packages/sheets/src/controllers/permission/sheet-permission-init.controller.ts
+++ b/packages/sheets/src/controllers/permission/sheet-permission-init.controller.ts
@@ -18,7 +18,6 @@ import type { Workbook } from '@univerjs/core';
import type { UnitAction } from '@univerjs/protocol';
import type { IAddRangeProtectionMutationParams } from '../../commands/mutations/add-range-protection.mutation';
import type { IAddWorksheetProtectionParams } from '../../commands/mutations/add-worksheet-protection.mutation';
-import type { IDeleteWorksheetProtectionParams } from '../../commands/mutations/delete-worksheet-protection.mutation';
import type { ISetWorksheetPermissionPointsMutationParams } from '../../commands/mutations/set-worksheet-permission-points.mutation';
import { Disposable, IAuthzIoService, ICommandService, Inject, IPermissionService, IUndoRedoService, IUniverInstanceService, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { UnitObject } from '@univerjs/protocol';
@@ -33,17 +32,7 @@ import { defaultWorkbookPermissionPoints, getAllWorkbookPermissionPoint } from '
import { WorkbookPermissionService } from '../../services/permission/workbook-permission/workbook-permission.service';
import { WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '../../services/permission/worksheet-permission';
-interface ISheetPermissionCmdBufferListItemType {
- id: string;
- params: IDeleteWorksheetProtectionParams;
-}
-
export class SheetPermissionInitController extends Disposable {
- private _cmdBufferList: ISheetPermissionCmdBufferListItemType[] = [];
- private _isRangePermissionInitFinish: boolean = false;
- private _isWorksheetPermissionInitFinish: boolean = false;
- private _isWorkbookPermissionInitFinish: boolean = false;
-
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IPermissionService private _permissionService: IPermissionService,
@@ -74,25 +63,6 @@ export class SheetPermissionInitController extends Disposable {
this._initRangePermissionFromSnapshot();
}
- public getIsPermissionInitFinish() {
- // console.warn(this._isWorksheetPermissionInitFinish, this._isRangePermissionInitFinish, this._isWorkbookPermissionInitFinish);
- return this._isWorksheetPermissionInitFinish && this._isRangePermissionInitFinish && this._isWorkbookPermissionInitFinish;
- }
-
- public addCmdToBufferList(item: ISheetPermissionCmdBufferListItemType) {
- this._cmdBufferList.push(item);
- }
-
- private _processCmdBufferList() {
- if (!this.getIsPermissionInitFinish() || this._cmdBufferList.length === 0) {
- return;
- }
-
- for (const item of this._cmdBufferList) {
- this._commandService.executeCommand(item.id, item.params, { onlyLocal: true });
- }
- }
-
private async _initRangePermissionFromSnapshot() {
const initRangePermissionFunc = async (workbook: Workbook) => {
const allAllowedParams: {
@@ -119,10 +89,6 @@ export class SheetPermissionInitController extends Disposable {
if (!allAllowedParams.length) {
this._rangeProtectionRuleModel.changeRuleInitState(true);
- this._isRangePermissionInitFinish = true;
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
return;
}
@@ -141,10 +107,6 @@ export class SheetPermissionInitController extends Disposable {
}
});
this._rangeProtectionRuleModel.changeRuleInitState(true);
- this._isRangePermissionInitFinish = true;
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
});
};
@@ -213,10 +175,6 @@ export class SheetPermissionInitController extends Disposable {
this._permissionService.updatePermissionPoint(instance.id, action.allowed);
}
});
- this._isWorkbookPermissionInitFinish = true;
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
});
}
@@ -316,10 +274,6 @@ export class SheetPermissionInitController extends Disposable {
if (!allAllowedParams.length) {
this._worksheetProtectionRuleModel.changeRuleInitState(true);
- this._isWorksheetPermissionInitFinish = true;
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
return;
}
@@ -338,18 +292,11 @@ export class SheetPermissionInitController extends Disposable {
}
});
this._worksheetProtectionRuleModel.changeRuleInitState(true);
- this._isWorksheetPermissionInitFinish = true;
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
});
};
await Promise.all(this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET).map((workbook) => initSheetPermissionFunc(workbook)));
this._worksheetProtectionRuleModel.changeRuleInitState(true);
- if (this.getIsPermissionInitFinish()) {
- this._processCmdBufferList();
- }
}
private _initUserChange() {