From 77c39fd34a0acc417dd0992cb08f725d3b23fc7a Mon Sep 17 00:00:00 2001 From: ybzky Date: Mon, 23 Sep 2024 18:10:56 +0800 Subject: [PATCH 1/3] chore: permission check use compose points --- ...-permission-interceptor-base.controller.ts | 52 ++++++------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts index 2bddb1b69c7..d0734e54cfe 100644 --- a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts +++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts @@ -462,50 +462,28 @@ export class SheetPermissionInterceptorBaseController extends Disposable { } const { workbookTypes, worksheetTypes, rangeTypes } = permissionTypes; + const permissionIds = []; if (workbookTypes) { - const workbookDisable = workbookTypes.some((F) => { - const instance = new F(unitId); - const permission = this._permissionService.getPermissionPoint(instance.id)?.value ?? false; - return permission === false; - }); - if (workbookDisable === true) { - return false; - } + permissionIds.push(...workbookTypes.map((F) => new F(unitId).id)); } if (worksheetTypes) { - const worksheetDisable = worksheetTypes.some((F) => { - const instance = new F(unitId, subUnitId); - const permission = this._permissionService.getPermissionPoint(instance.id)?.value ?? false; - return permission === false; - }); - if (worksheetDisable === true) { - return false; - } + permissionIds.push(...worksheetTypes.map((F) => new F(unitId, subUnitId).id)); } if (rangeTypes) { - const hasPermission = ranges?.every((range) => { - return rangeTypes.every((F) => { - for (let row = range.startRow; row <= range.endRow; row++) { - for (let col = range.startColumn; col <= range.endColumn; col++) { - const cellInfo = (worksheet.getCell(row, col) as (ICellDataForSheetInterceptor & { selectionProtection: ICellPermission[] }))?.selectionProtection?.[0]; - if (!cellInfo?.ruleId) { - continue; - } - const permissionId = this._rangeProtectionRuleModel.getRule(unitId, subUnitId, cellInfo.ruleId)?.permissionId; - if (!permissionId) { - continue; - } - const instance = new F(unitId, subUnitId, permissionId); - const permission = this._permissionService.getPermissionPoint(instance.id)?.value ?? false; - if (permission === false) { - return false; - } - } - } - return true; + this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).forEach((rule) => { + const overlap = ranges.some((range) => { + return rule.ranges.some((r) => { + return Rectangle.intersects(r, range); + }); }); + if (overlap) { + permissionIds.push(...rangeTypes.map((F) => new F(unitId, subUnitId, rule.permissionId).id)); + } }); - return hasPermission; + } + + if (permissionIds.length) { + return this._permissionService.composePermission(permissionIds).every((permission) => permission.value); } return true; From 7dec741d8512288a983f150f6e3244994df5dbf6 Mon Sep 17 00:00:00 2001 From: ybzky Date: Tue, 24 Sep 2024 14:38:40 +0800 Subject: [PATCH 2/3] chore: add menu util debounce --- packages/sheets-ui/src/controllers/menu/menu-util.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/sheets-ui/src/controllers/menu/menu-util.ts b/packages/sheets-ui/src/controllers/menu/menu-util.ts index 73167417f8c..b3dcc792f57 100644 --- a/packages/sheets-ui/src/controllers/menu/menu-util.ts +++ b/packages/sheets-ui/src/controllers/menu/menu-util.ts @@ -16,7 +16,7 @@ import { FOCUSING_COMMON_DRAWINGS, IContextService, IPermissionService, IUniverInstanceService, Rectangle, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core'; import { IExclusiveRangeService, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorkbookManageCollaboratorPermission, WorksheetEditPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets'; -import { combineLatest, map, merge, of, startWith, switchMap } from 'rxjs'; +import { combineLatest, debounceTime, map, merge, of, startWith, switchMap } from 'rxjs'; import type { IAccessor, IPermissionTypes, IRange, Nullable, Workbook, WorkbookPermissionPointConstructor, Worksheet } from '@univerjs/core'; import type { Observable } from 'rxjs'; @@ -181,7 +181,7 @@ export function getBaseRangeMenuHidden$(accessor: IAccessor) { const rangeProtectionRuleModel = accessor.get(RangeProtectionRuleModel); const permissionService = accessor.get(IPermissionService); - return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$).pipe( + return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$.pipe(debounceTime(100))).pipe( map(() => { const range = selectionManagerService.getCurrentLastSelection()?.range; if (!range) return true; @@ -215,7 +215,7 @@ export function getInsertAfterMenuHidden$(accessor: IAccessor, type: 'row' | 'co const rangeProtectionRuleModel = accessor.get(RangeProtectionRuleModel); const permissionService = accessor.get(IPermissionService); - return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$).pipe( + return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$.pipe(debounceTime(100))).pipe( map(() => { const range = selectionManagerService.getCurrentLastSelection()?.range; if (!range) return true; @@ -257,7 +257,7 @@ export function getInsertBeforeMenuHidden$(accessor: IAccessor, type: 'row' | 'c const rangeProtectionRuleModel = accessor.get(RangeProtectionRuleModel); const permissionService = accessor.get(IPermissionService); - return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$).pipe( + return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$.pipe(debounceTime(100))).pipe( map(() => { const range = selectionManagerService.getCurrentLastSelection()?.range; if (!range) return true; @@ -300,7 +300,7 @@ export function getDeleteMenuHidden$(accessor: IAccessor, type: 'row' | 'col') { const permissionService = accessor.get(IPermissionService); - return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$).pipe( + return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$.pipe(debounceTime(100))).pipe( map(() => { const range = selectionManagerService.getCurrentLastSelection()?.range; if (!range) return true; @@ -345,7 +345,7 @@ export function getCellMenuHidden$(accessor: IAccessor, type: 'row' | 'col') { const permissionService = accessor.get(IPermissionService); - return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$).pipe( + return merge(selectionManagerService.selectionMoveEnd$, permissionService.permissionPointUpdate$.pipe(debounceTime(100))).pipe( map(() => { const range = selectionManagerService.getCurrentLastSelection()?.range; if (!range) return true; From 0f3220972858505ccbef075d62bf43e5e79cd6f4 Mon Sep 17 00:00:00 2001 From: zw Date: Tue, 24 Sep 2024 19:59:39 +0800 Subject: [PATCH 3/3] fix: error on sheet removed --- .../src/controllers/popup.controller.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts index 14a9f3f1361..8ffeacbc764 100644 --- a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts +++ b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CustomRangeType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, ICommandService, Inject, IPermissionService, IUniverInstanceService, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core'; +import { CustomRangeType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, ICommandService, Inject, IPermissionService, IUniverInstanceService, LifecycleStages, OnLifecycle, Rectangle, UniverInstanceType } from '@univerjs/core'; import { DocSelectionManagerService } from '@univerjs/docs'; import { DocEventManagerService } from '@univerjs/docs-ui'; import { IRenderManagerService } from '@univerjs/engine-render'; @@ -35,7 +35,7 @@ import { import { HoverManagerService, HoverRenderController, IEditorBridgeService, SheetPermissionInterceptorBaseController, SheetSkeletonManagerService } from '@univerjs/sheets-ui'; import { IZenZoneService } from '@univerjs/ui'; import { debounceTime, map, mergeMap, Observable } from 'rxjs'; -import type { Nullable } from '@univerjs/core'; +import type { Nullable, Workbook } from '@univerjs/core'; import type { ISheetLocationBase } from '@univerjs/sheets'; import type { Subscription } from 'rxjs'; import { SheetsHyperLinkPopupService } from '../services/popup.service'; @@ -66,6 +66,16 @@ export class SheetsHyperLinkPopupController extends Disposable { private _getLinkPermission(location: ISheetLocationBase) { const { unitId, subUnitId, row: currentRow, col: currentCol } = location; + const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET); + const worksheet = workbook?.getSheetBySheetId(subUnitId); + if (!worksheet) { + return { + viewPermission: false, + editPermission: false, + copyPermission: false, + }; + } + const viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({ workbookTypes: [WorkbookViewPermission], worksheetTypes: [WorksheetViewPermission],