-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add group update methods #61
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,90 +1,168 @@ | ||
| import { beforeAll, expect, test } from 'vitest'; | ||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { resetTestDatabase, testRoc } from '../../testUtils.ts'; | ||
| import type { Ok } from '../../types.ts'; | ||
| import type { RocGroupPermission } from '../Roc.ts'; | ||
|
|
||
| const ok: Ok = { ok: true }; | ||
|
|
||
| beforeAll(async () => { | ||
| await resetTestDatabase(); | ||
| }); | ||
|
|
||
| test('create group', async () => { | ||
| const group = await testRoc.createGroup('group1'); | ||
| // Makes sure we are testing all the possible permissions defined by the types | ||
| const groupMap: Record<RocGroupPermission, true> = { | ||
| addAttachment: true, | ||
| create: true, | ||
| createGroup: true, | ||
| delete: true, | ||
| owner: true, | ||
| read: true, | ||
| readGroup: true, | ||
| readImport: true, | ||
| write: true, | ||
| writeGroup: true, | ||
| }; | ||
stropitek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const allGroups = Object.keys(groupMap) as RocGroupPermission[]; | ||
stropitek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| expect(group).toStrictEqual({ ok: true }); | ||
| }); | ||
| describe('create and update groups', () => { | ||
| it('create group', async () => { | ||
| const group = await testRoc.createGroup('group1'); | ||
|
|
||
| expect(group).toStrictEqual(ok); | ||
| }); | ||
|
|
||
| it('add user to group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const data = await testRoc.addUserToGroup(groupName, 'john@doe.com'); | ||
|
|
||
| test('get group', async () => { | ||
| const group = await testRoc.getGroup('group1'); | ||
| expect(data).toStrictEqual(ok); | ||
|
|
||
| expect(group).toMatchObject({ | ||
| $owners: ['admin@cheminfo.org'], | ||
| $type: 'group', | ||
| customUsers: [], | ||
| name: 'group1', | ||
| rights: [], | ||
| users: [], | ||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(group.users).toStrictEqual(['john@doe.com']); | ||
| }); | ||
| }); | ||
|
|
||
| test('get group info', async () => { | ||
| const groupInfo = await testRoc.getGroupInfo('group1'); | ||
| it('removes user from group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| await testRoc.addUserToGroup(groupName, 'john@doe.com'); | ||
| const data = await testRoc.removeUserFromGroup(groupName, 'john@doe.com'); | ||
|
|
||
| expect(data).toStrictEqual(ok); | ||
|
|
||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(groupInfo).toMatchObject({ | ||
| name: 'group1', | ||
| rights: [], | ||
| users: [], | ||
| expect(group.users).toStrictEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| test('get group info with ldap info', async () => { | ||
| const groupInfo = await testRoc.getGroupInfo('group1', { | ||
| ldapInfo: true, | ||
| it('add permission to group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const data = await testRoc.addPermissionToGroup(groupName, 'read'); | ||
|
|
||
| expect(data).toStrictEqual(ok); | ||
|
|
||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(group.rights).toStrictEqual(['read']); | ||
| }); | ||
|
|
||
| expect(groupInfo).toMatchObject({ | ||
| name: 'group1', | ||
| rights: [], | ||
| users: [], | ||
| ldapInfo: [], | ||
| it('adds permission to group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| for (const permission of allGroups) { | ||
| // rest-on-couch does not support concurrent requests without the possibility of conflicts. | ||
| // eslint-disable-next-line no-await-in-loop | ||
| await testRoc.addPermissionToGroup(groupName, permission); | ||
| } | ||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(group.rights.toSorted()).toStrictEqual(allGroups); | ||
| }); | ||
| }); | ||
|
|
||
| test('get groups info', async () => { | ||
| await testRoc.createGroup('group2'); | ||
| const groupsInfo = await testRoc.getGroupsInfo(); | ||
|
|
||
| expect(groupsInfo).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "name": "group1", | ||
| "rights": [], | ||
| "users": [], | ||
| }, | ||
| { | ||
| "name": "group2", | ||
| "rights": [], | ||
| "users": [], | ||
| }, | ||
| ] | ||
| `); | ||
| it('remove permissions from group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| await testRoc.addPermissionToGroup(groupName, 'read'); | ||
| const data = await testRoc.removePermissionFromGroup(groupName, 'read'); | ||
|
|
||
| expect(data).toStrictEqual(ok); | ||
|
|
||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(group.rights).toStrictEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| test('get groups info with ldap info', async () => { | ||
| const groupsInfo = await testRoc.getGroupsInfo({ ldapInfo: true }); | ||
|
|
||
| expect(groupsInfo).toMatchInlineSnapshot(` | ||
| [ | ||
| { | ||
| "ldapInfo": [], | ||
| "name": "group1", | ||
| "rights": [], | ||
| "users": [], | ||
| }, | ||
| { | ||
| "ldapInfo": [], | ||
| "name": "group2", | ||
| "rights": [], | ||
| "users": [], | ||
| }, | ||
| ] | ||
| `); | ||
| describe('get groups', () => { | ||
| it('get group', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const group = await testRoc.getGroup(groupName); | ||
|
|
||
| expect(group).toMatchObject({ | ||
| $owners: ['admin@cheminfo.org'], | ||
| $type: 'group', | ||
| customUsers: [], | ||
| name: groupName, | ||
| rights: [], | ||
| users: [], | ||
| }); | ||
| }); | ||
|
|
||
| it('get group info', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const groupInfo = await testRoc.getGroupInfo(groupName); | ||
|
|
||
| expect(groupInfo).toMatchObject({ | ||
| name: groupName, | ||
| rights: [], | ||
| users: [], | ||
| }); | ||
| }); | ||
|
|
||
| it('get group info with ldap info', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const groupInfo = await testRoc.getGroupInfo(groupName, { | ||
| ldapInfo: true, | ||
| }); | ||
|
|
||
| expect(groupInfo).toMatchObject({ | ||
| name: groupName, | ||
| rights: [], | ||
| users: [], | ||
| ldapInfo: [], | ||
| }); | ||
| }); | ||
|
|
||
| it('get groups info', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const groupsInfo = await testRoc.getGroupsInfo(); | ||
| const group = groupsInfo.find((g) => g.name === groupName); | ||
|
|
||
| expect(group).toStrictEqual({ | ||
| name: groupName, | ||
| rights: [], | ||
| users: [], | ||
| }); | ||
| }); | ||
|
|
||
| it('get groups info with ldap info', async () => { | ||
| const groupName = crypto.randomUUID(); | ||
| await testRoc.createGroup(groupName); | ||
| const groupsInfo = await testRoc.getGroupsInfo({ ldapInfo: true }); | ||
| const group = groupsInfo.find((g) => g.name === groupName); | ||
|
|
||
| expect(group).toStrictEqual({ | ||
| ldapInfo: [], | ||
| name: groupName, | ||
| rights: [], | ||
| users: [], | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.