Skip to content

Commit

Permalink
merge workspace error fix
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Aug 18, 2023
1 parent 54a84dc commit f8a28be
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,45 +71,43 @@ export class WorkspaceSavedObjectsClientWrapper {
request: OpenSearchDashboardsRequest,
permissionMode: WorkspacePermissionMode | WorkspacePermissionMode[]
) {
//PermissionMode here is an array which is merged by workspace type required permission and other saved object required permission.
//So we only need to do one permission check no matter its type.
// PermissionMode here is an array which is merged by workspace type required permission and other saved object required permission.
// So we only need to do one permission check no matter its type.
if (!id) {
return;
}
if (
!(await this.permissionControl.validate(
request,
{
type,
id,
},
this.formatWorkspacePermissionModeToStringArray(permissionMode)
))
) {
const validateResult = await this.permissionControl.validate(
request,
{
type,
id,
},
this.formatWorkspacePermissionModeToStringArray(permissionMode)
);
if (!validateResult?.result) {
throw generateWorkspacePermissionError();
}
}

private async validateMultiObjectsPermissions(
objects: Pick<SavedObject, 'id' | 'type'>[],
objects: Array<Pick<SavedObject, 'id' | 'type'>>,
request: OpenSearchDashboardsRequest,
permissionMode: WorkspacePermissionMode | WorkspacePermissionMode[]
) {
//PermissionMode here is an array which is merged by workspace type required permission and other saved object required permission.
//So we only need to do one permission check no matter its type.
// PermissionMode here is an array which is merged by workspace type required permission and other saved object required permission.
// So we only need to do one permission check no matter its type.
let permitted = true;

for (const { id, type } of objects) {
if (
!(await this.permissionControl.validate(
request,
{
type,
id,
},
this.formatWorkspacePermissionModeToStringArray(permissionMode)
))
) {
const validateResult = await this.permissionControl.validate(
request,
{
type,
id,
},
this.formatWorkspacePermissionModeToStringArray(permissionMode)
);
if (!validateResult?.result) {
permitted = false;
break;
}
Expand Down

0 comments on commit f8a28be

Please sign in to comment.