Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix some permission bugs #2522

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: fix some permission bugs
  • Loading branch information
ybzky committed Jun 14, 2024
commit 7abd631d2287e529a8355117a748f302ddd5681e
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import { DisposableCollection, IPermissionService, IUniverInstanceService, Lifec
import { getSheetCommandTarget, RangeProtectionRuleModel, SelectionManagerService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetColumnStylePermission, WorksheetSetRowStylePermission } from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
import { IDialogService } from '@univerjs/ui';
import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
import type { IRenderContext, IRenderModule, Scene, SpreadsheetSkeleton } from '@univerjs/engine-render';

import { UnitAction } from '@univerjs/protocol';
import { HeaderMoveRenderController } from '../render-controllers/header-move.render-controller';
import { HeaderResizeRenderController } from '../render-controllers/header-resize.render-controller';
import { ISelectionRenderService } from '../../services/selection/selection-render.service';
import { HeaderFreezeRenderController } from '../render-controllers/freeze.render-controller';
import { getTransformCoord } from '../utils/component-tools';

type ICellPermission = Record<UnitAction, boolean> & { ruleId?: string; ranges?: IRange[] };

Expand Down Expand Up @@ -65,8 +66,8 @@ export class SheetPermissionInterceptorCanvasRenderController extends RxDisposab
}
const { worksheet, unitId, subUnitId } = target;

const workSheetEditPermission = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)?.value ?? false;
if (!workSheetEditPermission) {
const worksheetEditPermission = this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value);
if (!worksheetEditPermission) {
return false;
}

Expand Down Expand Up @@ -109,8 +110,8 @@ export class SheetPermissionInterceptorCanvasRenderController extends RxDisposab
}
const { worksheet, unitId, subUnitId } = target;

const workSheetEditPermission = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)?.value ?? false;
if (!workSheetEditPermission) {
const worksheetEditPermission = this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value);
if (!worksheetEditPermission) {
return false;
}

Expand Down Expand Up @@ -176,15 +177,15 @@ export class SheetPermissionInterceptorCanvasRenderController extends RxDisposab
private _initRangeFillPermissionInterceptor() {
this.disposeWithMe(
this._selectionRenderService.interceptor.intercept(this._selectionRenderService.interceptor.getInterceptPoints().RANGE_FILL_PERMISSION_CHECK, {
handler: (_: Nullable<boolean>, position: { x: number; y: number; skeleton: SpreadsheetSkeleton }) => {
handler: (_: Nullable<boolean>, position: { x: number; y: number; skeleton: SpreadsheetSkeleton; scene: Scene }) => {
const target = getSheetCommandTarget(this._univerInstanceService);
if (!target) {
return false;
}
const { worksheet, unitId, subUnitId } = target;

const workSheetEditPermission = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)?.value ?? false;
if (!workSheetEditPermission) {
const worksheetEditPermission = this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value);
if (!worksheetEditPermission) {
return false;
}

Expand All @@ -193,9 +194,10 @@ export class SheetPermissionInterceptorCanvasRenderController extends RxDisposab
});

const selectionRange = ranges?.find((range) => {
const transformCoord = getTransformCoord(position.x, position.y, position.scene, position.skeleton);
const cellPosition = position.skeleton.getCellByIndex(range.endRow, range.endColumn);
const missX = Math.abs(cellPosition.endX - position.x);
const missY = Math.abs(cellPosition.endY - position.y);
const missX = Math.abs(cellPosition.endX - transformCoord.x);
const missY = Math.abs(cellPosition.endY - transformCoord.y);
return missX <= 5 && missY <= 5;
});

Expand Down Expand Up @@ -229,8 +231,8 @@ export class SheetPermissionInterceptorCanvasRenderController extends RxDisposab
}
const { worksheet, unitId, subUnitId } = target;

const workSheetEditPermission = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)?.value ?? false;
if (!workSheetEditPermission) {
const worksheetEditPermission = this._permissionService.composePermission([new WorkbookEditablePermission(unitId).id, new WorksheetEditPermission(unitId, subUnitId).id]).every((permission) => permission.value);
if (!worksheetEditPermission) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface ISelectionRenderService {

interceptor: InterceptorManager<{
RANGE_MOVE_PERMISSION_CHECK: IInterceptor<boolean, null>;
RANGE_FILL_PERMISSION_CHECK: IInterceptor<boolean, { x: number; y: number; skeleton: SpreadsheetSkeleton }>;
RANGE_FILL_PERMISSION_CHECK: IInterceptor<boolean, { x: number; y: number; skeleton: SpreadsheetSkeleton; scene: Scene }>;
}>;

enableHeaderHighlight(): void;
Expand Down Expand Up @@ -122,7 +122,7 @@ export interface ISelectionRenderService {
*/

export const RANGE_MOVE_PERMISSION_CHECK = createInterceptorKey<boolean, null>('rangeMovePermissionCheck');
export const RANGE_FILL_PERMISSION_CHECK = createInterceptorKey<boolean, { x: number; y: number; skeleton: SpreadsheetSkeleton }>('rangeFillPermissionCheck');
export const RANGE_FILL_PERMISSION_CHECK = createInterceptorKey<boolean, { x: number; y: number; skeleton: SpreadsheetSkeleton; scene: Scene }>('rangeFillPermissionCheck');

export class SelectionRenderService implements ISelectionRenderService {
hasSelection: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export class SelectionShapeExtension {
const { fillControl } = this._control;

fillControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
const permissionCheck = this._injector.get(ISelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, { x: evt.offsetX, y: evt.offsetY, skeleton: this._skeleton });
const permissionCheck = this._injector.get(ISelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, { x: evt.offsetX, y: evt.offsetY, skeleton: this._skeleton, scene: this._scene });

if (!permissionCheck) {
return;
Expand Down Expand Up @@ -824,7 +824,7 @@ export class SelectionShapeExtension {
const { offsetX: moveOffsetX, offsetY: moveOffsetY } = moveEvt;
const currentViewport = scene.getActiveViewportByCoord(Vector2.FromArray([moveOffsetX, moveOffsetY]));

const permissionCheck = this._injector.get(ISelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, { x: evt.offsetX, y: evt.offsetY, skeleton: this._skeleton });
const permissionCheck = this._injector.get(ISelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, { x: evt.offsetX, y: evt.offsetY, skeleton: this._skeleton, scene: this._scene });

if (!permissionCheck) {
return;
Expand Down
5 changes: 3 additions & 2 deletions packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useDependency } from '@wendellhu/redi/react-bindings';
import clsx from 'clsx';
import React, { useEffect, useLayoutEffect, useState } from 'react';

import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SelectionManagerService, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SelectionManagerService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { merge } from 'rxjs';
import { IFormulaEditorManagerService } from '../../services/editor/formula-editor-manager.service';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
Expand Down Expand Up @@ -63,10 +63,11 @@ export function FormulaBar() {
const subUnitId = worksheet.getSheetId();
const range = selectionManager.getLast()?.range;
if (!range) return;
const workbookEditPermission = permissionService.getPermissionPoint(new WorkbookEditablePermission(unitId).id)?.value;
const worksheetSetCellValuePermission = permissionService.getPermissionPoint(new WorksheetSetCellValuePermission(unitId, subUnitId).id)?.value;
const worksheetEditPermission = permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)?.value;

if (!worksheetSetCellValuePermission || !worksheetEditPermission) {
if (!workbookEditPermission || !worksheetSetCellValuePermission || !worksheetEditPermission) {
setDisable(true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}

&-select {
width: 83px;
width: 90px;
cursor: pointer;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ export class WorksheetPermissionService extends RxDisposable {
this._worksheetProtectionRuleModel.ruleChange$.subscribe((info) => {
switch (info.type) {
case 'add': {
getAllWorksheetPermissionPoint().forEach((F) => {
const instance = new F(info.unitId, info.subUnitId);
this._permissionService.addPermissionPoint(instance);
});
break;
}
case 'delete': {
Expand Down
Loading