Skip to content

Commit

Permalink
feat(permission): change permission point logic (#3826)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybzky authored Oct 24, 2024
1 parent 251186e commit 7e49171
Show file tree
Hide file tree
Showing 43 changed files with 526 additions and 270 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@wendellhu/redi": "0.16.1",
"kdbush": "^4.0.2",
"lodash-es": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.84",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"dayjs": "^1.11.13"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.84",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@univerjs/data-validation": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/icons": "^0.1.84",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"dayjs": "^1.11.13"
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-find-replace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-ui": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-hyper-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"dependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.84",
"@univerjs/protocol": "0.1.39-alpha.30",
"@univerjs/protocol": "0.1.39-alpha.36",
"@univerjs/sheets": "workspace:*",
"@univerjs/telemetry": "workspace:*",
"@univerjs/ui": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

import type { ICommand, Workbook } from '@univerjs/core';
import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, Rectangle, sequenceExecute, UniverInstanceType } from '@univerjs/core';
import type { IRangeProtectionRule } from '@univerjs/sheets';
import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, RangeProtectionRuleModel, SetRangeProtectionMutation, SetWorksheetProtectionMutation, SheetsSelectionsService, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { UnitObject } from '@univerjs/protocol';
import type { IPermissionPanelRule } from '../../services/permission/sheet-permission-panel.model';
import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, Rectangle, sequenceExecute, UniverInstanceType } from '@univerjs/core';
import { UnitObject } from '@univerjs/protocol';
import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, DeleteRangeProtectionMutation, DeleteWorksheetProtectionMutation, RangeProtectionRuleModel, SetRangeProtectionMutation, SetWorksheetProtectionMutation, SheetsSelectionsService, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { SheetPermissionPanelModel } from '../../services/permission/sheet-permission-panel.model';
import { SheetPermissionOpenPanelOperation } from '../operations/sheet-permission-open-panel.operation';
import { DeleteWorksheetProtectionCommand } from './worksheet-protection.command';
Expand Down Expand Up @@ -237,7 +237,7 @@ export const DeleteRangeProtectionFromContextMenuCommand: ICommand = {
const subUnitId = worksheet.getSheetId();
const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);

if (worksheetRule?.permissionId && worksheetRule?.name) {
if (worksheetRule?.permissionId) {
return commandService.executeCommand(DeleteWorksheetProtectionCommand.id, { unitId, subUnitId, rule: worksheetRule });
} else {
const selectRange = selectionManagerService.getCurrentLastSelection()?.range;
Expand Down Expand Up @@ -288,7 +288,7 @@ export const SetRangeProtectionFromContextMenuCommand: ICommand = {
const subUnitId = worksheet.getSheetId();
const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);
const sheetPermissionPanelModel = accessor.get(SheetPermissionPanelModel);
if (worksheetRule?.permissionId && worksheetRule?.name) {
if (worksheetRule?.permissionId) {
const oldRule = {
...worksheetRule,
unitId,
Expand Down
13 changes: 6 additions & 7 deletions packages/sheets-ui/src/controllers/menu/menu-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { IAccessor, IPermissionTypes, IRange, Nullable, Workbook, WorkbookPermissionPointConstructor, Worksheet } from '@univerjs/core';
import type { Observable } from 'rxjs';
import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, IContextService, IPermissionService, IUniverInstanceService, Rectangle, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { IExclusiveRangeService, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorkbookManageCollaboratorPermission, WorksheetEditPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { IExclusiveRangeService, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { combineLatest, debounceTime, map, merge, of, startWith, switchMap } from 'rxjs';
import { IEditorBridgeService } from '../../services/editor-bridge.service';

Expand Down Expand Up @@ -411,19 +411,18 @@ export function getWorkbookPermissionDisable$(accessor: IAccessor, workbookPermi
const workbookPermissionIds: string[] = [];
workbookPermissionTypes.forEach((F) => workbookPermissionIds.push(new F(unitId).id));
const workbookPermission$ = permissionService.composePermission$(workbookPermissionIds).pipe(map((list) => list.every((item) => item.value === true)));
const workbookManageCollaboratorPermission$ = permissionService.getPermissionPoint$(new WorkbookManageCollaboratorPermission(unitId).id)?.pipe(map((permission) => permission.value)) ?? of(false);

return combineLatest([workbookPermission$, workbookManageCollaboratorPermission$]).pipe(
map(([basePermission, manageable]) => {
return workbookPermission$.pipe(
map((basePermission) => {
if (!basePermission) {
return true;
}

const subUnitId = activeSheet.getSheetId();
const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);
const worksheetRuleList = selectionRuleModel.getSubunitRuleList(unitId, subUnitId);
if (worksheetRule || worksheetRuleList.length) {
return !manageable;
const rangeRuleList = selectionRuleModel.getSubunitRuleList(unitId, subUnitId);
if (worksheetRule || rangeRuleList.length) {
return true;
}
return false;
})
Expand Down
Loading

0 comments on commit 7e49171

Please sign in to comment.