Skip to content

Commit

Permalink
chore: move permission controller to sheets pacakge (#4295)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybzky authored Jan 6, 2025
1 parent 2fbe824 commit 4ca2ed5
Show file tree
Hide file tree
Showing 21 changed files with 400 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function matchFilter(node: HTMLElement, filter: IStyleRule['filter']) {
}

// TODO: get from page width.
const DEFAULT_TABLE_WIDTH = 600;
const DEFAULT_TABLE_WIDTH = 660;

interface ITableCache {
table: ITable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import type { ICommandInfo } from '@univerjs/core';
import type { IAddCfCommandParams } from '../commands/commands/add-cf.command';
import { Disposable, ICommandService, Inject, LocaleService } from '@univerjs/core';
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
import { SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
import { RangeProtectionPermissionEditPoint, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
import { AddCfCommand } from '../commands/commands/add-cf.command';

export class ConditionalFormattingPermissionController extends Disposable {
constructor(
@Inject(LocaleService) private _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController
@Inject(SheetPermissionCheckController) private readonly _sheetPermissionCheckController: SheetPermissionCheckController

) {
super();
Expand All @@ -37,13 +36,13 @@ export class ConditionalFormattingPermissionController extends Disposable {
this.disposeWithMe(
this._commandService.beforeCommandExecuted((command: ICommandInfo) => {
if (command.id === AddCfCommand.id) {
const permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
}, (command.params as IAddCfCommandParams).rule.ranges);
if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.setStyleErr'));
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.setStyleErr'));
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import type { ICommandInfo } from '@univerjs/core';
import type { IUpdateSheetDataValidationRangeCommandParams } from '@univerjs/sheets-data-validation';
import { Disposable, ICommandService, Inject, LocaleService } from '@univerjs/core';
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
import { RangeProtectionPermissionEditPoint, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
import { AddSheetDataValidationCommand, UpdateSheetDataValidationRangeCommand } from '@univerjs/sheets-data-validation';
import { SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';

export class DataValidationPermissionController extends Disposable {
constructor(
@Inject(LocaleService) private _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController
@Inject(SheetPermissionCheckController) private readonly _sheetPermissionCheckController: SheetPermissionCheckController
) {
super();
this._commandExecutedListener();
Expand All @@ -35,23 +34,23 @@ export class DataValidationPermissionController extends Disposable {
this.disposeWithMe(
this._commandService.beforeCommandExecuted((command: ICommandInfo) => {
if (command.id === AddSheetDataValidationCommand.id) {
const permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
});
if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.setStyleErr'));
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.setStyleErr'));
}
}
if (command.id === UpdateSheetDataValidationRangeCommand.id) {
const permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
}, (command.params as IUpdateSheetDataValidationRangeCommandParams).ranges);
if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.setStyleErr'));
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.setStyleErr'));
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { Scrollbar } from '@univerjs/design';
import { RichTextEditingMutation } from '@univerjs/docs';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle } from '@univerjs/icons';
import { RangeProtectionPermissionEditPoint, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
import { RangeProtectionPermissionEditPoint, SetRangeValuesCommand, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
import { deserializeListOptions, getDataValidationCellValue, serializeListOptions, SheetDataValidationModel } from '@univerjs/sheets-data-validation';
import { IEditorBridgeService, SetCellEditVisibleOperation, SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
import { IEditorBridgeService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
import { KeyCode, RectPopup, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
import { debounceTime } from 'rxjs';
Expand Down Expand Up @@ -58,8 +58,8 @@ const SelectList = (props: ISelectListProps) => {
const { row, col, unitId, subUnitId } = location;
const filteredOptions = options.filter((item) => lowerFilter ? item.label.toLowerCase().includes(lowerFilter) : true);
const showEditOnDropdown = configService.getConfig<IUniverSheetsDataValidationUIConfig>(SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY)?.showEditOnDropdown ?? true;
const sheetPermissionInterceptorBaseController = useDependency(SheetPermissionInterceptorBaseController);
const hasPermission = useMemo(() => sheetPermissionInterceptorBaseController.permissionCheckWithRanges(
const sheetPermissionCheckController = useDependency(SheetPermissionCheckController);
const hasPermission = useMemo(() => sheetPermissionCheckController.permissionCheckWithRanges(
{
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
Expand All @@ -68,7 +68,7 @@ const SelectList = (props: ISelectListProps) => {
[{ startColumn: col, startRow: row, endColumn: col, endRow: row }],
unitId,
subUnitId
), [sheetPermissionInterceptorBaseController, col, row, unitId, subUnitId]);
), [sheetPermissionCheckController, col, row, unitId, subUnitId]);

return (
<div className={styles.dvListDropdown} style={style}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import type { MenuConfig } from '@univerjs/ui';

import { Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';

import { expandToContinuousRange, getSheetCommandTarget, RangeProtectionPermissionViewPoint, SheetsSelectionsService, WorksheetFilterPermission, WorksheetViewPermission } from '@univerjs/sheets';
import { expandToContinuousRange, getSheetCommandTarget, RangeProtectionPermissionViewPoint, SheetPermissionCheckController, SheetsSelectionsService, WorksheetFilterPermission, WorksheetViewPermission } from '@univerjs/sheets';
import { SheetsFilterService, SmartToggleSheetsFilterCommand } from '@univerjs/sheets-filter';
import { SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
import { type IOpenFilterPanelOperationParams, OpenFilterPanelOperation } from '../commands/operations/sheets-filter.operation';

export interface IUniverSheetsFilterUIConfig {
Expand All @@ -40,8 +39,8 @@ export class SheetsFilterPermissionController extends Disposable {
@Inject(SheetsFilterService) private _sheetsFilterService: SheetsFilterService,
@Inject(LocaleService) private _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(SheetPermissionInterceptorBaseController)
private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController,
@Inject(SheetPermissionCheckController)
private readonly _sheetPermissionCheckPermission: SheetPermissionCheckController,
@Inject(Injector) private _injector: Injector,
@Inject(SheetsSelectionsService) private _sheetsSelectionService: SheetsSelectionsService
) {
Expand All @@ -61,7 +60,7 @@ export class SheetsFilterPermissionController extends Disposable {
const filterRange = this._sheetsFilterService.getFilterModel(unitId, subUnitId)?.getRange();
let permission;
if (filterRange) {
permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
permission = this._sheetPermissionCheckPermission.permissionCheckWithRanges({
rangeTypes: [RangeProtectionPermissionViewPoint],
worksheetTypes: [WorksheetFilterPermission, WorksheetViewPermission],
}, [filterRange]);
Expand All @@ -71,20 +70,20 @@ export class SheetsFilterPermissionController extends Disposable {
let newRange = { ...range };
const isCellRange = range.startColumn === range.endColumn && range.startRow === range.endRow;
newRange = isCellRange ? expandToContinuousRange(newRange, { left: true, right: true, up: true, down: true }, worksheet) : newRange;
permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
permission = this._sheetPermissionCheckPermission.permissionCheckWithRanges({
rangeTypes: [RangeProtectionPermissionViewPoint],
worksheetTypes: [WorksheetViewPermission, WorksheetFilterPermission],
}, [newRange], unitId, subUnitId);
} else {
permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithoutRange({
permission = this._sheetPermissionCheckPermission.permissionCheckWithoutRange({
rangeTypes: [RangeProtectionPermissionViewPoint],
worksheetTypes: [WorksheetViewPermission, WorksheetFilterPermission],
});
}
}

if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.filterErr'));
this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.filterErr'));
}
}
if (command.id === OpenFilterPanelOperation.id) {
Expand All @@ -95,12 +94,12 @@ export class SheetsFilterPermissionController extends Disposable {
if (colRange) {
colRange.startColumn = params.col;
colRange.endColumn = params.col;
const permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const permission = this._sheetPermissionCheckPermission.permissionCheckWithRanges({
rangeTypes: [RangeProtectionPermissionViewPoint],
worksheetTypes: [WorksheetFilterPermission, WorksheetViewPermission],
}, [colRange]);
if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.filterErr'));
this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.filterErr'));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, Inject, LocaleService } from '@univerjs/core';
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { SheetPermissionInterceptorBaseController } from '@univerjs/sheets-ui';
import { RangeProtectionPermissionEditPoint, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { InsertLinkShortcut } from './menu';

export class SheetsHyperLinkPermissionController extends Disposable {
constructor(
@Inject(LocaleService) private _localeService: LocaleService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController
@Inject(SheetPermissionCheckController) private readonly _sheetPermissionCheckController: SheetPermissionCheckController
) {
super();

Expand All @@ -35,13 +34,13 @@ export class SheetsHyperLinkPermissionController extends Disposable {
this.disposeWithMe(
this._commandService.beforeCommandExecuted((command: ICommandInfo) => {
if (command.id === InsertLinkShortcut.id) {
const permission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookEditablePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission],
});
if (!permission) {
this._sheetPermissionInterceptorBaseController.haveNotPermissionHandle(this._localeService.t('permission.dialog.hyperLinkErr'));
this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('permission.dialog.hyperLinkErr'));
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ClearSelectionFormatCommand,
RangeProtectionPermissionEditPoint,
RangeProtectionPermissionViewPoint,
SheetPermissionCheckController,
WorkbookCopyPermission,
WorkbookEditablePermission,
WorkbookViewPermission,
Expand All @@ -35,7 +36,7 @@ import {
WorksheetInsertHyperlinkPermission,
WorksheetViewPermission,
} from '@univerjs/sheets';
import { HoverManagerService, HoverRenderController, IEditorBridgeService, SheetPermissionInterceptorBaseController, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { HoverManagerService, HoverRenderController, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { IZenZoneService } from '@univerjs/ui';
import { debounceTime, map, Observable, switchMap } from 'rxjs';
import { SheetsHyperLinkPopupService } from '../services/popup.service';
Expand All @@ -47,7 +48,7 @@ export class SheetsHyperLinkPopupController extends Disposable {
@Inject(SheetsHyperLinkPopupService) private readonly _sheetsHyperLinkPopupService: SheetsHyperLinkPopupService,
@Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService,
@Inject(IPermissionService) private readonly _permissionService: IPermissionService,
@Inject(SheetPermissionInterceptorBaseController) private readonly _sheetPermissionInterceptorBaseController: SheetPermissionInterceptorBaseController,
@Inject(SheetPermissionCheckController) private readonly _sheetPermissionCheckController: SheetPermissionCheckController,
@ICommandService private readonly _commandService: ICommandService,
@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
@Inject(DocSelectionManagerService) private readonly _textSelectionManagerService: DocSelectionManagerService,
Expand Down Expand Up @@ -75,13 +76,13 @@ export class SheetsHyperLinkPopupController extends Disposable {
};
}

const viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const viewPermission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookViewPermission],
worksheetTypes: [WorksheetViewPermission],
rangeTypes: [RangeProtectionPermissionViewPoint],
}, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]);

const editPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
const editPermission = this._sheetPermissionCheckController.permissionCheckWithRanges({
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
Expand Down
Loading

0 comments on commit 4ca2ed5

Please sign in to comment.