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: change permission collaborator #2528

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"nanoid": "5.0.7",
"numeral": "^2.0.6",
"ot-json1": "^1.0.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
},
"dependencies": {
"@univerjs/icons": "^0.1.56",
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"dependencies": {
"@univerjs/icons": "^0.1.56",
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-find-replace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-hyper-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"devDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@wendellhu/redi": "^0.15.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
},
"dependencies": {
"@univerjs/icons": "^0.1.56",
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SheetPermissionOpenPanelOperation: ICommand<IPermissionOpenPanelPar
showDetail,
fromSheetBar,
},
width: 320,
width: 330,
footer: {
label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER,
showDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ describe('test menu items', () => {
disposableCollection.add(menuItem.activated$!.subscribe((v: boolean) => (activated = v)));
disposableCollection.add(menuItem.disabled$!.subscribe((v: boolean) => (disabled = v)));
expect(activated).toBeFalsy();
expect(disabled).toBeFalsy();

select({ startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 });
expect(await commandService.executeCommand(SetBoldCommand.id)).toBeTruthy();
expect(activated).toBe(true);
expect(disabled).toBeFalsy();
});
});
85 changes: 44 additions & 41 deletions packages/sheets-ui/src/controllers/menu/menu-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,62 +51,65 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
const selectionManagerService = accessor.get(SelectionManagerService);
const rangeProtectionRuleModel = accessor.get(RangeProtectionRuleModel);
const worksheetRuleModel = accessor.get(WorksheetProtectionRuleModel);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const workbook$ = univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);
const userManagerService = accessor.get(UserManagerService);
const contextService = accessor.get(IContextService);
const focusedOnDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false));
if (!workbook) {
return of(true);
}

return combineLatest([userManagerService.currentUser$, workbook.activeSheet$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe(
switchMap(([_, __, selection, focusOnDrawings]) => {
if (focusOnDrawings) {
return combineLatest([userManagerService.currentUser$, workbook$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe(
switchMap(([_, workbook, selection, focusOnDrawings]) => {
if (focusOnDrawings || !workbook) {
return of(true);
}

const worksheet = workbook.getActiveSheet();
const unitId = workbook.getUnitId();
const subUnitId = worksheet.getSheetId();

const permissionService = accessor.get(IPermissionService);
return workbook.activeSheet$.pipe(
switchMap((worksheet) => {
if (!worksheet) {
return of(true);
}
const unitId = workbook.getUnitId();
const subUnitId = worksheet.getSheetId();

const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes;
const permissionService = accessor.get(IPermissionService);

const permissionIds: string[] = [];
const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes;

workbookTypes?.forEach((F) => {
permissionIds.push(new F(unitId).id);
});
const permissionIds: string[] = [];

worksheetTypes?.forEach((F) => {
permissionIds.push(new F(unitId, subUnitId).id);
});
workbookTypes?.forEach((F) => {
permissionIds.push(new F(unitId).id);
});

const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);
worksheetTypes?.forEach((F) => {
permissionIds.push(new F(unitId, subUnitId).id);
});

if (worksheetRule) {
return permissionService.composePermission$(permissionIds).pipe(map((list) => {
return list.some((item) => item.value === false);
}));
}

const selectionRanges = selection?.map((selection) => selection.range);
const rules = rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).filter((rule) => {
return selectionRanges?.some((range) => {
return rule.ranges.some((ruleRange) => Rectangle.intersects(range, ruleRange));
});
});
const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);

rangeTypes?.forEach((F) => {
rules.forEach((rule) => {
permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id);
});
});
if (worksheetRule) {
return permissionService.composePermission$(permissionIds).pipe(map((list) => {
return list.some((item) => item.value === false);
}));
}

return permissionService.composePermission$(permissionIds).pipe(map((list) => {
return list.some((item) => item.value === false);
}));
const selectionRanges = selection?.map((selection) => selection.range);
const rules = rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).filter((rule) => {
return selectionRanges?.some((range) => {
return rule.ranges.some((ruleRange) => Rectangle.intersects(range, ruleRange));
});
});

rangeTypes?.forEach((F) => {
rules.forEach((rule) => {
permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id);
});
});

return permissionService.composePermission$(permissionIds).pipe(map((list) => {
return list.some((item) => item.value === false);
}));
})
);
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useDependency } from '@wendellhu/redi/react-bindings';
import React from 'react';
import { ISidebarService, useObservable } from '@univerjs/ui';
import { IAuthzIoService, ICommandService, LocaleService } from '@univerjs/core';
import { UnitAction, UnitObject, UnitRole } from '@univerjs/protocol';
import { CreateRequest_WorkSheetObjectScope, UnitAction, UnitObject, UnitRole } from '@univerjs/protocol';
import { AddRangeProtectionCommand } from '@univerjs/sheets';
import { SheetPermissionPanelModel, viewState } from '../../../services/permission/sheet-permission-panel.model';
import { SheetPermissionUserManagerService } from '../../../services/permission/sheet-permission-user-list.service';
Expand Down Expand Up @@ -79,6 +79,7 @@ export const SheetPermissionPanelDetailFooter = () => {
unitID: activeRule.unitId,
name: activeRule.name,
strategies: [{ role: UnitRole.Editor, action: UnitAction.Edit }, { role: UnitRole.Reader, action: UnitAction.View }],
scope: CreateRequest_WorkSheetObjectScope.SomeCollaborator,
},
objectType: UnitObject.Worksheet,
});
Expand Down Expand Up @@ -109,10 +110,11 @@ export const SheetPermissionPanelDetailFooter = () => {
unitID: activeRule.unitId,
name: activeRule.name,
strategies: [{ role: UnitRole.Editor, action: UnitAction.Edit }, { role: UnitRole.Reader, action: UnitAction.View }],
scope: CreateRequest_WorkSheetObjectScope.SomeCollaborator,
},
objectType: UnitObject.Worksheet,
});
const { ranges = [], ...sheetRule } = activeRule;
const { ranges: _range = [], ...sheetRule } = activeRule;
sheetRule.permissionId = permissionId;
commandService.executeCommand(AddWorksheetProtectionCommand.id, {
rule: sheetRule,
Expand Down Expand Up @@ -141,7 +143,7 @@ export const SheetPermissionPanelDetailFooter = () => {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: false,
},
width: 320,
width: 330,
footer: {
label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER,
showDetail: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SheetPermissionPanelAddFooter = () => {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: true,
},
width: 320,
width: 330,
footer: {
label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER,
showDetail: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const SheetPermissionPanelList = () => {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: true,
},
width: 320,
width: 330,
footer: {
label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER,
showDetail: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IAuthzIoService, ICommandService, IPermissionService, IUniverInstanceSe
import { IDialogService } from '@univerjs/ui';
import { getAllWorksheetPermissionPoint, SetWorksheetPermissionPointsCommand, WorksheetProtectionPointModel } from '@univerjs/sheets';
import type { ICollaborator, UnitAction } from '@univerjs/protocol';
import { UnitObject, UnitRole } from '@univerjs/protocol';
import { CreateRequest_WorkSheetObjectScope, UnitObject, UnitRole } from '@univerjs/protocol';
import Spin from '../spin';
import { defaultWorksheetUnitActionList, subUnitPermissionTypeMap, UNIVER_SHEET_PERMISSION_DIALOG_ID } from '../../../basics/const/permission';
import styles from './index.module.less';
Expand Down Expand Up @@ -129,6 +129,7 @@ export const SheetPermissionDialog = () => {
collaborators,
name: '',
strategies: actions,
scope: CreateRequest_WorkSheetObjectScope.AllCollaborator,
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sheets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/thread-comment-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"dependencies": {
"@univerjs/icons": "^0.1.56",
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"@univerjs/thread-comment": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/thread-comment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3"
"@univerjs/protocol": "0.1.38-alpha.4"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/umd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@univerjs/facade": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/uniscript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "0.1.38-alpha.3",
"@univerjs/protocol": "0.1.38-alpha.4",
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
Expand Down
Loading
Loading