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.

fix: sheet protection not work (#6137)

WEI ZHANGd58a9d351a30
diff --git a/packages/sheets/src/commands/commands/add-worksheet-protection.command.ts b/packages/sheets/src/commands/commands/add-worksheet-protection.command.ts
index 29f7fc20a9..a594868207 100644
--- a/packages/sheets/src/commands/commands/add-worksheet-protection.command.ts
+++ b/packages/sheets/src/commands/commands/add-worksheet-protection.command.ts
@@ -19,6 +19,7 @@ import type { IWorksheetProtectionRule } from '../../services/permission/type';
import { CommandType, ICommandService, IUndoRedoService } from '@univerjs/core';
import { AddWorksheetProtectionMutation } from '../mutations/add-worksheet-protection.mutation';
import { DeleteWorksheetProtectionMutation } from '../mutations/delete-worksheet-protection.mutation';
+import { SetWorksheetPermissionPointsMutation } from '../mutations/set-worksheet-permission-points.mutation';
export interface IAddWorksheetProtectionParams {
unitId: string;
@@ -37,6 +38,17 @@ export const AddWorksheetProtectionCommand: ICommand<IAddWorksheetProtectionPara
const { rule, unitId } = params;
const subUnitId = rule.subUnitId;
+ // Add the permission point rule first
+ await commandService.executeCommand(SetWorksheetPermissionPointsMutation.id, {
+ rule: {
+ unitId,
+ subUnitId,
+ permissionId: rule.permissionId,
+ },
+ unitId,
+ subUnitId,
+ });
+
const result = await commandService.executeCommand(AddWorksheetProtectionMutation.id, {
unitId,
rule,
@@ -44,7 +56,10 @@ export const AddWorksheetProtectionCommand: ICommand<IAddWorksheetProtectionPara
});
if (result) {
- const redoMutations = [{ id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId: rule.subUnitId } }];
+ const redoMutations = [
+ { id: SetWorksheetPermissionPointsMutation.id, params: { rule: { unitId, subUnitId, permissionId: rule.permissionId }, unitId, subUnitId } },
+ { id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId: rule.subUnitId } },
+ ];
const undoMutations = [{ id: DeleteWorksheetProtectionMutation.id, params: { unitId, subUnitId } }];
undoRedoService.pushUndoRedo({
unitID: unitId,
diff --git a/packages/sheets/src/commands/commands/delete-worksheet-protection.command.ts b/packages/sheets/src/commands/commands/delete-worksheet-protection.command.ts
index d1f75d6e57..b8fd06b674 100644
--- a/packages/sheets/src/commands/commands/delete-worksheet-protection.command.ts
+++ b/packages/sheets/src/commands/commands/delete-worksheet-protection.command.ts
@@ -19,6 +19,7 @@ import type { IWorksheetProtectionRule } from '../../services/permission/type';
import { CommandType, ICommandService, IUndoRedoService } from '@univerjs/core';
import { AddWorksheetProtectionMutation } from '../mutations/add-worksheet-protection.mutation';
import { DeleteWorksheetProtectionMutation } from '../mutations/delete-worksheet-protection.mutation';
+import { SetWorksheetPermissionPointsMutation } from '../mutations/set-worksheet-permission-points.mutation';
export interface IDeleteWorksheetProtectionParams {
unitId: string;
@@ -43,7 +44,10 @@ export const DeleteWorksheetProtectionCommand: ICommand<IDeleteWorksheetProtecti
});
const redoMutations = [{ id: DeleteWorksheetProtectionMutation.id, params: { unitId, subUnitId } }];
- const undoMutations = [{ id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId } }];
+ const undoMutations = [
+ { id: AddWorksheetProtectionMutation.id, params: { unitId, rule, subUnitId } },
+ { id: SetWorksheetPermissionPointsMutation.id, params: { rule: { unitId, subUnitId, permissionId: rule.permissionId }, unitId, subUnitId } },
+ ];
undoRedoService.pushUndoRedo({
unitID: unitId,
redoMutations,
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..fcd86234dc 100644
--- a/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts
+++ b/packages/sheets/src/commands/mutations/delete-worksheet-protection.mutation.ts
@@ -17,6 +17,7 @@
import type { IMutation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
import { SheetPermissionInitController } from '../../controllers/permission/sheet-permission-init.controller';
+import { WorksheetProtectionPointModel } from '../../services/permission/worksheet-permission/worksheet-permission-point.model';
import { WorksheetProtectionRuleModel } from '../../services/permission/worksheet-permission/worksheet-permission-rule.model';
export interface IDeleteWorksheetProtectionParams {
@@ -29,6 +30,7 @@ export const DeleteWorksheetProtectionMutation: IMutation<IDeleteWorksheetProtec
type: CommandType.MUTATION,
handler: (accessor, params) => {
const worksheetProtectionRuleModel = accessor.get(WorksheetProtectionRuleModel);
+ const worksheetProtectionPointModel = accessor.get(WorksheetProtectionPointModel);
const sheetPermissionInitController = accessor.get(SheetPermissionInitController);
if (!sheetPermissionInitController.getIsPermissionInitFinish()) {
sheetPermissionInitController.addCmdToBufferList({
@@ -40,6 +42,7 @@ export const DeleteWorksheetProtectionMutation: IMutation<IDeleteWorksheetProtec
const { unitId, subUnitId } = params;
worksheetProtectionRuleModel.deleteRule(unitId, subUnitId);
+ worksheetProtectionPointModel.deleteRule(unitId, subUnitId);
return true;
},
};