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.

chore: add permission id return (#3147)

ybzky1182a9e934dc
diff --git a/packages/facade/src/apis/sheets/f-permission.ts b/packages/facade/src/apis/sheets/f-permission.ts
index 69a8172712..fa8947d59c 100644
--- a/packages/facade/src/apis/sheets/f-permission.ts
+++ b/packages/facade/src/apis/sheets/f-permission.ts
@@ -16,7 +16,7 @@
import type { IRange, RangePermissionPointConstructor, WorkbookPermissionPointConstructor, WorkSheetPermissionPointConstructor } from '@univerjs/core';
import { generateRandomId, IAuthzIoService, ICommandService, Inject, Injector, IPermissionService, Rectangle } from '@univerjs/core';
-import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, RangeProtectionRuleModel, SetRangeProtectionMutation, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
+import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, RangeProtectionRuleModel, SetRangeProtectionMutation, SetWorksheetPermissionPointsMutation, UnitObject, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets';
import { SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
export class FPermission {
@@ -74,13 +74,13 @@ export class FPermission {
if (hasRangeProtection) {
throw new Error('sheet protection cannot intersect with range protection');
}
- const permissionId = await this._authzIoService.create({ objectType: 2 });
+ const permissionId = await this._authzIoService.create({ objectType: UnitObject.Worksheet });
const res = this._commandService.syncExecuteCommand(AddWorksheetProtectionMutation.id, {
unitId,
subUnitId,
rule: {
permissionId,
- unitType: 2,
+ unitType: UnitObject.Worksheet,
unitId,
subUnitId,
},
@@ -133,6 +133,14 @@ export class FPermission {
} else {
permissionId = hasBasePermission.permissionId;
}
+ } else {
+ const rule = this._worksheetProtectionPointRuleModel.getRule(unitId, subUnitId);
+ if (!rule) {
+ permissionId = await this._authzIoService.create({ objectType: UnitObject.Worksheet });
+ this._commandService.executeCommand(SetWorksheetPermissionPointsMutation.id, { unitId, subUnitId, permissionId });
+ } else {
+ permissionId = rule.permissionId;
+ }
}
const instance = new FPointClass(unitId, subUnitId);
@@ -157,7 +165,7 @@ export class FPermission {
ruleId: string;
} | undefined> {
// The permission ID generation here only provides the most basic permission type. If need collaborators later, need to expand this
- const permissionId = await this._authzIoService.create({ objectType: 3 });
+ const permissionId = await this._authzIoService.create({ objectType: UnitObject.SelectRange });
const ruleId = `ruleId_${generateRandomId(6)}`;
const worksheetProtection = this._worksheetProtectionRuleModel.getRule(unitId, subUnitId);
if (worksheetProtection) {
@@ -179,7 +187,7 @@ export class FPermission {
subUnitId,
rules: [{
permissionId,
- unitType: 3,
+ unitType: UnitObject.SelectRange,
unitId,
subUnitId,
ranges,
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 6586a21cf6..42127d6287 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -147,6 +147,7 @@ export {
WorkbookViewHistoryPermission,
WorkbookRecoverHistoryPermission,
} from './services/permission/permission-point';
+export { UnitObject } from '@univerjs/protocol';
export { checkRangesEditablePermission } from './services/permission/util';
// range-protection