forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix group permissions convert (#321)
Signed-off-by: Lin Wang <[email protected]>
- Loading branch information
Showing
2 changed files
with
99 additions
and
32 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/plugins/workspace/public/components/workspace_form/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WorkspacePermissionMode } from '../../../common/constants'; | ||
import { WorkspacePermissionItemType } from './constants'; | ||
import { | ||
convertPermissionSettingsToPermissions, | ||
convertPermissionsToPermissionSettings, | ||
} from './utils'; | ||
|
||
describe('convertPermissionSettingsToPermissions', () => { | ||
it('should return undefined if permission items not provided', () => { | ||
expect(convertPermissionSettingsToPermissions(undefined)).toBeUndefined(); | ||
expect(convertPermissionSettingsToPermissions([])).toBeUndefined(); | ||
}); | ||
|
||
it('should return consistent permission settings', () => { | ||
expect( | ||
convertPermissionSettingsToPermissions([ | ||
{ | ||
type: WorkspacePermissionItemType.User, | ||
userId: 'foo', | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
type: WorkspacePermissionItemType.Group, | ||
group: 'bar', | ||
modes: [WorkspacePermissionMode.LibraryWrite], | ||
}, | ||
]) | ||
).toEqual({ | ||
library_read: { users: ['foo'] }, | ||
library_write: { groups: ['bar'] }, | ||
read: { users: ['foo'] }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('convertPermissionsToPermissionSettings', () => { | ||
it('should return consistent permission settings', () => { | ||
expect( | ||
convertPermissionsToPermissionSettings({ | ||
library_read: { users: ['foo'] }, | ||
library_write: { groups: ['bar'] }, | ||
read: { users: ['foo'] }, | ||
write: { groups: ['bar'] }, | ||
}) | ||
).toEqual([ | ||
{ | ||
type: WorkspacePermissionItemType.User, | ||
userId: 'foo', | ||
modes: [WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.Read], | ||
}, | ||
{ | ||
type: WorkspacePermissionItemType.Group, | ||
group: 'bar', | ||
modes: [WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Write], | ||
}, | ||
]); | ||
}); | ||
it('should only convert workspace supported permissions', () => { | ||
expect( | ||
convertPermissionsToPermissionSettings({ | ||
another_read: { users: ['foo'] }, | ||
}) | ||
).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters