Skip to content

Commit

Permalink
feat: workspace saved client wrapper ACLSearchParams.permissionModes …
Browse files Browse the repository at this point in the history
…use passed value

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Sep 20, 2023
1 parent ccd0520 commit b724852
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { i18n } from '@osd/i18n';
import { intersection } from 'lodash';

import {
OpenSearchDashboardsRequest,
Expand Down Expand Up @@ -32,6 +33,12 @@ import { SavedObjectsPermissionControlContract } from '../permission_control/cli
import { WorkspaceFindOptions } from '../types';
import { getPrincipalsFromRequest } from '../utils';

const ALL_WORKSPACE_INNER_DATA_PERMISSION_MODES: string[] = [
WorkspacePermissionMode.LibraryRead,
WorkspacePermissionMode.LibraryWrite,
WorkspacePermissionMode.Management,
];

// Can't throw unauthorized for now, the page will be refreshed if unauthorized
const generateWorkspacePermissionError = () => {
SavedObjectsErrorHelpers.decorateForbiddenError(
Expand Down Expand Up @@ -360,21 +367,20 @@ export class WorkspaceSavedObjectsClientWrapper {
if (!options.ACLSearchParams) {
options.ACLSearchParams = {};
}
const workspaceInnerPermissionModes = options.ACLSearchParams.permissionModes
? intersection(
options.ACLSearchParams.permissionModes,
ALL_WORKSPACE_INNER_DATA_PERMISSION_MODES
)
: ALL_WORKSPACE_INNER_DATA_PERMISSION_MODES;

if (this.isRelatedToWorkspace(options.type)) {
options.ACLSearchParams.permissionModes = options.permissionModes ?? [
WorkspacePermissionMode.LibraryRead,
WorkspacePermissionMode.LibraryWrite,
WorkspacePermissionMode.Management,
];
options.ACLSearchParams.permissionModes = workspaceInnerPermissionModes;
options.ACLSearchParams.principals = principals;
} else {
const permittedWorkspaceIds = await this.permissionControl.getPermittedWorkspaceIds(
wrapperOptions.request,
[
WorkspacePermissionMode.LibraryRead,
WorkspacePermissionMode.LibraryWrite,
WorkspacePermissionMode.Management,
]
workspaceInnerPermissionModes
);

if (options.workspaces) {
Expand Down Expand Up @@ -408,10 +414,12 @@ export class WorkspaceSavedObjectsClientWrapper {
*/
options.workspaces = undefined;
options.ACLSearchParams.workspaces = permittedWorkspaceIds;
options.ACLSearchParams.permissionModes = [
WorkspacePermissionMode.Read,
WorkspacePermissionMode.Write,
];
options.ACLSearchParams.permissionModes = options.ACLSearchParams.permissionModes
? intersection(options.ACLSearchParams.permissionModes, [
WorkspacePermissionMode.Read,
WorkspacePermissionMode.Write,
])
: [WorkspacePermissionMode.Read, WorkspacePermissionMode.Write];
options.ACLSearchParams.principals = principals;
}
}
Expand Down

0 comments on commit b724852

Please sign in to comment.