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

Feat remove management permission mode in acl permission #195

Conversation

wanglam
Copy link
Collaborator

@wanglam wanglam commented Sep 22, 2023

Description

1.Remove management permission mode
2.Update workspaces permission check use LibraryRead / LibraryWrite
3.Update ACL permission check use Read / Write
4.Change workspace permission form use below options
- Read: LibraryRead + Read
- Read+Write: LibraryWrite + Write
- Admin: LibraryWrite + Write

Issues Resolved

Screenshot

Testing the changes

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

…on mode usage

Signed-off-by: Lin Wang <wonglam@amazon.com>
@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2023

Codecov Report

Merging #195 (d8aa1d1) into workspace (a2abcf2) will increase coverage by 0.02%.
Report is 3 commits behind head on workspace.
The diff coverage is n/a.

@@              Coverage Diff              @@
##           workspace     #195      +/-   ##
=============================================
+ Coverage      66.09%   66.12%   +0.02%     
=============================================
  Files           3420     3420              
  Lines          65752    65753       +1     
  Branches       10589    10590       +1     
=============================================
+ Hits           43461    43480      +19     
+ Misses         19650    19633      -17     
+ Partials        2641     2640       -1     
Flag Coverage Δ
Linux_1 30.42% <ø> (+<0.01%) ⬆️
Linux_2 55.12% <ø> (+0.06%) ⬆️
Linux_3 42.76% <ø> (+0.01%) ⬆️
Linux_4 34.52% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/core/utils/constants.ts 100.00% <ø> (ø)

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@wanglam wanglam marked this pull request as ready for review September 22, 2023 03:38
@@ -28,42 +28,55 @@ export type WorkspacePermissionSetting = (
modes: Array<
| WorkspacePermissionMode.LibraryRead
| WorkspacePermissionMode.LibraryWrite
| WorkspacePermissionMode.Management
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should WorkspacePermissionSetting just be

export type WorkspacePermissionSetting =
  | { type: 'user'; userId: string; modes: Array<WorkspacePermissionMode> }
  | { type: 'group'; group: string; modes: Array<WorkspacePermissionMode> };

@@ -227,63 +239,89 @@ export const WorkspacePermissionSettingPanel = ({
onChange,
firstRowDeletable,
}: WorkspacePermissionSettingPanelProps) => {
const valueRef = useRef(value);
valueRef.current = value;
const transferredValue = useMemo(() => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean transformed?

Comment on lines 247 to 267
for (let i = 0; i < value.length; i++) {
const valueItem = value[i];
if (
!valueItem.modes ||
!valueItem.type ||
(valueItem.type === 'user' && !valueItem.userId) ||
(valueItem.type === 'group' && !valueItem.group)
) {
result.push(valueItem);
continue;
}
for (const key in optionIdToWorkspacePermissionModesMap) {
if (!Object.prototype.hasOwnProperty.call(optionIdToWorkspacePermissionModesMap, key)) {
continue;
}
const modesForCertainPermissionId = optionIdToWorkspacePermissionModesMap[key];
if (modesForCertainPermissionId.every((mode) => valueItem.modes?.includes(mode))) {
result.push({ ...valueItem, modes: modesForCertainPermissionId });
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me to understand this piece of code? from L247-L267

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passed permission records were based user & group level. One user or group will contains multi permission modes. Since each permission mode in the UI was single select, we can't display multi permission option in one row. So we need to separate these permission modes into multi rows. Will add some annotation to clarify the logic.

@@ -33,7 +33,8 @@ type WorkspaceRoutePermissionItem = {
modes: Array<
| WorkspacePermissionMode.LibraryRead
| WorkspacePermissionMode.LibraryWrite
| WorkspacePermissionMode.Management
| WorkspacePermissionMode.Read
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be like this?

modes: WorkspacePermissionMode[]

@@ -286,8 +280,8 @@ export class WorkspaceSavedObjectsClientWrapper {
!(await this.validateWorkspacesAndSavedObjectsPermissions(
await wrapperOptions.client.get(type, options.id),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question on this line, it's not related to this PR. What if options.id doesn't exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will throw an error about document doesn't exists.

@@ -383,7 +357,12 @@ export class WorkspaceSavedObjectsClientWrapper {
perPage: 999,
ACLSearchParams: {
principals,
permissionModes: workspaceInnerPermissionModes,
permissionModes: options.ACLSearchParams.permissionModes
? intersection(options.ACLSearchParams.permissionModes, [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to leave a comment on why intersection is needed

Signed-off-by: Lin Wang <wonglam@amazon.com>
@wanglam wanglam requested a review from ruanyl September 25, 2023 07:50
@wanglam wanglam merged commit 29ccc20 into ruanyl:workspace Sep 25, 2023
21 checks passed
opensearch-workspace-development bot pushed a commit that referenced this pull request Sep 25, 2023
* feat: remove management permission mode and clearify library permission mode usage

Signed-off-by: Lin Wang <wonglam@amazon.com>

* address PR comments and add annotations

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
(cherry picked from commit 29ccc20)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants