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: setup reserved workspaces when calling list workspaces API #178

Merged
merged 8 commits into from
Sep 20, 2023

Conversation

SuZhou-Joe
Copy link
Collaborator

@SuZhou-Joe SuZhou-Joe commented Sep 18, 2023

Description

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

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2023

Codecov Report

Merging #178 (ec7c21d) into workspace (e296a5d) will increase coverage by 0.48%.
Report is 1 commits behind head on workspace.
The diff coverage is 100.00%.

@@              Coverage Diff              @@
##           workspace     #178      +/-   ##
=============================================
+ Coverage      61.39%   61.87%   +0.48%     
=============================================
  Files           2982     2117     -865     
  Lines          57792    40889   -16903     
  Branches        9360     7470    -1890     
=============================================
- Hits           35481    25300   -10181     
+ Misses         20224    13897    -6327     
+ Partials        2087     1692     -395     
Flag Coverage Δ
Linux_1 ?
Linux_2 55.05% <100.00%> (+<0.01%) ⬆️
Linux_3 44.18% <100.00%> (+<0.01%) ⬆️

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

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

... and 937 files with indirect coverage changes

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

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
@SuZhou-Joe SuZhou-Joe force-pushed the feature/workspace-setup branch from b2e16b5 to 2d913a2 Compare September 18, 2023 23:34
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
@@ -125,6 +227,52 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
type: WORKSPACE_TYPE,
}
);
const scopedClientWithoutPermissionCheck = this.getScopeClientWithoutPermisson(requestDetail);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There has been a PR fixing typos, please change the function name to getScopedClientWithoutPermission.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed and thanks

Comment on lines 124 to 126
const managementWorkspaceACL = new ACL().addPermission([WorkspacePermissionMode.Management], {
users: ['*'],
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

For management workspace, are we going to grant WorkspacePermissionMode.Management to all users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the conclusion is that we will make public and management workspace manageable by anyone, and the first one can change the permission if they want to limit the permission.

Comment on lines 107 to 109
const publicWorkspaceACL = new ACL().addPermission([WorkspacePermissionMode.Management], {
users: ['*'],
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

For public workspace, are we going to grant WorkspacePermissionMode.Management to all users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the conclusion is that we will make public and management workspace manageable by anyone, and the first one can change the permission if they want to limit the permission.

@yuye-aws
Copy link
Collaborator

I found that reserved workspaces were not automatically created from the left menu header. When workspace feature is enabled, the header obtain the workspace list like the following:

src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx
const workspaceList = useObservable(observables.workspaceList$, []);

Instead of simply get workspaceList$ observable, we need to call workspace _list to make this PR effective.

@SuZhou-Joe
Copy link
Collaborator Author

I found that reserved workspaces were not automatically created from the left menu header. When workspace feature is enabled, the header obtain the workspace list like the following:

src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx
const workspaceList = useObservable(observables.workspaceList$, []);

Instead of simply get workspaceList$ observable, we need to call workspace _list to make this PR effective.

There should be a place to call the workspace _list or the workspaceList$ will always be empty.

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
}

public getPrincipalsFromRequest(request: OpenSearchDashboardsRequest): Principals {
static getPrincipalsFromRequest(request: OpenSearchDashboardsRequest): Principals {
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: I might just move this out of the class and make it a pure util function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, changed that.

PUBLIC_WORKSPACE_ID,
{
name: i18n.translate('workspaces.public.workspace.default.name', {
defaultMessage: 'public',
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 tweak a bit

Suggested change
defaultMessage: 'public',
defaultMessage: 'Public',

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for this catch. According to mockup, it should be named "Global workspace", changed to that.

/**
* Setup public workspace if public workspace can not be found
*/
const hasPublicWorkspace = savedObjects.find((item) => item.id === PUBLIC_WORKSPACE_ID);
Copy link
Owner

Choose a reason for hiding this comment

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

The name hasPublicWorkspace indicates a boolean values, can we change find -> some?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, changed that.

*/
if (principals.users) {
const hasPersonalWorkspace = savedObjects.find((item) =>
principals.users?.includes(item.id)
Copy link
Owner

@ruanyl ruanyl Sep 19, 2023

Choose a reason for hiding this comment

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

Can you leave a comment and say something like: user id will be personal workspace id

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, done.

@@ -125,6 +227,52 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
type: WORKSPACE_TYPE,
}
);
const scopedClientWithoutPermissionCheck = this.getScopedClientWithoutPermission(requestDetail);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please fix lint

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
@raintygao
Copy link
Collaborator

@SuZhou-Joe
Copy link
Collaborator Author

Will permission related changes in this PR be conflicted with this task? https://github.com/orgs/opensearch-project/projects/127/views/5?sortedBy%5Bdirection%5D=asc&sortedBy%5BcolumnId%5D=Assignees&pane=issue&itemId=38846476

Let me change the setup permission to comply with the new permission model.

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
@SuZhou-Joe SuZhou-Joe merged commit 4bccdea into ruanyl:workspace Sep 20, 2023
21 of 23 checks passed
opensearch-workspace-development bot pushed a commit that referenced this pull request Sep 20, 2023
* feat: setup reserved workspaces when calling list workspaces API

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: fix test flow

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: fix lint

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: fix typos

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: setup personal workspace using correct id

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* refractor: move function getPrincipalsFromRequest to a util function

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: change code according to comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: modify reserved workspace permission

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
(cherry picked from commit 4bccdea)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
SuZhou-Joe pushed a commit that referenced this pull request Sep 20, 2023
… (#183)

* feat: setup reserved workspaces when calling list workspaces API



* feat: fix test flow



* feat: fix lint



* feat: fix typos



* fix: setup personal workspace using correct id



* refractor: move function getPrincipalsFromRequest to a util function



* feat: change code according to comment



* feat: modify reserved workspace permission



---------


(cherry picked from commit 4bccdea)

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-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.

5 participants