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

ci: disposing unit should not emit error #2529

Merged
merged 13 commits into from
Jun 15, 2024
Prev Previous commit
Next Next commit
fix: clear permission point when dispose unit
  • Loading branch information
ybzky committed Jun 15, 2024
commit f9a6163279635e74868dde7e2b9adb77eb8c4a40
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import type { Workbook } from '@univerjs/core';
import { Disposable, IPermissionService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';

import { getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel } from '../worksheet-permission/utils';
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
import { RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint } from '../permission-point';
import { getAllWorkbookPermissionPoint } from './util';

@OnLifecycle(LifecycleStages.Starting, WorkbookPermissionService)
export class WorkbookPermissionService extends Disposable {
constructor(
@Inject(IPermissionService) private _permissionService: IPermissionService,
@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService
@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
@Inject(RangeProtectionRuleModel) private _rangeProtectionRuleModel: RangeProtectionRuleModel
) {
super();

Expand Down Expand Up @@ -54,6 +57,14 @@ export class WorkbookPermissionService extends Disposable {
workbook.getSheets().forEach((worksheet) => {
const subUnitId = worksheet.getSheetId();

const rangeRuleList = this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId);
rangeRuleList.forEach((rule) => {
[RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint].forEach((F) => {
const instance = new F(unitId, subUnitId, rule.permissionId);
this._permissionService.deletePermissionPoint(instance.id);
});
});

[...getAllWorksheetPermissionPoint(), ...getAllWorksheetPermissionPointByPointPanel()].forEach((F) => {
const instance = new F(unitId, subUnitId);
this._permissionService.deletePermissionPoint(instance.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { takeUntil } from 'rxjs/operators';
import { UniverType } from '@univerjs/protocol';

import type { IObjectModel, IObjectPointModel } from '../type';
import { RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint } from '../permission-point';
import { RangeProtectionRuleModel } from '../../../model/range-protection-rule.model';
import { WorksheetProtectionRuleModel } from './worksheet-permission-rule.model';
import { getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel } from './utils';
import { WorksheetProtectionPointModel } from './worksheet-permission-point.model';
Expand All @@ -36,7 +38,8 @@ export class WorksheetPermissionService extends RxDisposable {
@Inject(Injector) readonly _injector: Injector,
@Inject(WorksheetProtectionRuleModel) private _worksheetProtectionRuleModel: WorksheetProtectionRuleModel,
@Inject(WorksheetProtectionPointModel) private _worksheetProtectionPointRuleModel: WorksheetProtectionPointModel,
@Inject(IResourceManagerService) private _resourceManagerService: IResourceManagerService
@Inject(IResourceManagerService) private _resourceManagerService: IResourceManagerService,
@Inject(RangeProtectionRuleModel) private _rangeProtectionRuleModel: RangeProtectionRuleModel
) {
super();
this._init();
Expand All @@ -63,6 +66,15 @@ export class WorksheetPermissionService extends RxDisposable {
});
workbook.sheetDisposed$.subscribe((worksheet) => {
const subUnitId = worksheet.getSheetId();

const rangeRuleList = this._rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId);
rangeRuleList.forEach((rule) => {
[RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint].forEach((F) => {
const instance = new F(unitId, subUnitId, rule.permissionId);
this._permissionService.deletePermissionPoint(instance.id);
});
});

[...getAllWorksheetPermissionPoint(), ...getAllWorksheetPermissionPointByPointPanel()].forEach((F) => {
const instance = new F(unitId, subUnitId);
this._permissionService.deletePermissionPoint(instance.id);
Expand Down
Loading