Skip to content

Commit

Permalink
fix: clear permission point when dispose unit
Browse files Browse the repository at this point in the history
  • Loading branch information
ybzky committed Jun 15, 2024
1 parent f88d0dc commit f9a6163
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit f9a6163

Please sign in to comment.