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 all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export class SheetPermissionInterceptorBaseController extends Disposable {
worksheetTypes: [WorksheetCopyPermission],
});
errorMsg = this._localeService.t('permission.dialog.copyErr');
if (!this._permissionService.getPermissionPoint(new WorkbookCopyPermission(this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId()).id)?.value) {
errorMsg = this._localeService.t('permission.dialog.workbookCopyErr');
}
break;
case DeltaColumnWidthCommand.id:
case SetColWidthCommand.id:
Expand Down
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
1 change: 1 addition & 0 deletions packages/sheets-ui/src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ const locale: typeof zhCN = {
pasteErr: 'The range is protected, and you do not have paste permission. To paste, please contact the creator.',
setStyleErr: 'The range is protected, and you do not have permission to set styles. To set styles, please contact the creator.',
copyErr: 'The range is protected, and you do not have copy permission. To copy, please contact the creator.',
workbookCopyErr: 'The workbook is protected, and you do not have permission to copy. To copy, please contact the creator.',
setRowColStyleErr: 'The range is protected, and you do not have permission to set row and column styles. To set row and column styles, please contact the creator.',
moveRowColErr: 'The range is protected, and you do not have permission to move rows and columns. To move rows and columns, please contact the creator.',
moveRangeErr: 'The range is protected, and you do not have permission to move the selection. To move the selection, please contact the creator.',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-ui/src/locale/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ const locale: typeof zhCN = {
pasteErr: 'Диапазон защищен, и у вас нет разрешения на вставку. Для вставки свяжитесь с создателем.',
setStyleErr: 'Диапазон защищен, и у вас нет разрешения на установку стилей. Для установки стилей свяжитесь с создателем.',
copyErr: 'Диапазон защищен, и у вас нет разрешения на копирование. Для копирования свяжитесь с создателем.',
workbookCopyErr: 'Лист защищен, и у вас нет разрешения на копирование. Для копирования свяжитесь с создателем.',
setRowColStyleErr: 'Диапазон защищен, и у вас нет разрешения на установку стилей строк и столбцов. Для установки стилей строк и столбцов свяжитесь с создателем.',
moveRowColErr: 'Диапазон защищен, и у вас нет разрешения на перемещение строк и столбцов. Для перемещения строк и столбцов свяжитесь с создателем.',
moveRangeErr: 'Диапазон защищен, и у вас нет разрешения на перемещение выделения. Для перемещения выделения свяжитесь с создателем.',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-ui/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ const locale = {
pasteErr: '该范围已被保护,目前无粘贴权限。如需粘贴,请联系创建者。',
setStyleErr: '该范围已被保护,目前无设置样式权限。如需设置样式,请联系创建者。',
copyErr: '该范围已被保护,目前无复制权限。如需复制,请联系创建者。',
workbookCopyErr: '该工作表已被保护,目前无复制权限。如需复制,请联系创建者。',
setRowColStyleErr: '该范围已被保护,目前无设置行列样式权限。如需设置行列样式,请联系创建者。',
moveRowColErr: '该范围已被保护,目前无移动行列权限。如需移动行列,请联系创建者。',
moveRangeErr: '该范围已被保护,目前无移动选区权限。如需移动选区,请联系创建者。',
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 @@ -225,10 +225,10 @@ export const SheetPermissionPanelList = () => {

const hasManagerPermission = manageCollaboratorAction || currentUser.userID === item.creator?.userID;

const worksheet = workbook.getActiveSheet();

let ruleName = '';

const targetSheet = workbook.getSheetBySheetId(rule.subUnitId);
const targetName = targetSheet?.getName();
if (rule.unitType === UnitObject.SelectRange) {
const ranges = (rule as IRangeProtectionRule).ranges;
const rangeStr = ranges?.length
Expand All @@ -237,9 +237,9 @@ export const SheetPermissionPanelList = () => {
return v === 'NaN' ? '' : v;
}).filter((r) => !!r).join(',')
: '';
ruleName = `${worksheet.getName()}(${rangeStr})`;
ruleName = `${targetName}(${rangeStr})`;
} else if (rule.unitType === UnitObject.Worksheet) {
ruleName = worksheet.getName();
ruleName = targetName || '';
}

return (
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