-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GQL-61: As a user, I can read and update provider level group permiss…
…ions (#131) * GQL-61: Updates the groups acl to check if a user has provider/system permission to update and read * GQL-61: Adds test for permissions acl
- Loading branch information
Showing
8 changed files
with
186 additions
and
32 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
src/permissions/acls/__tests__/canCreateProviderGroups.test.js
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,53 @@ | ||
import { canCreateProviderGroups } from '../canCreateProviderGroups' | ||
|
||
import * as hasPermission from '../../../utils/hasPermission' | ||
import { forbiddenError } from '../../../utils/forbiddenError' | ||
|
||
describe('canCreateProviderGroups', () => { | ||
test('when a tag is provided and the user has access to provider permission', async () => { | ||
vi.spyOn(hasPermission, 'hasPermission').mockResolvedValue(true) | ||
|
||
const result = await canCreateProviderGroups.resolve( | ||
null, | ||
{ | ||
tag: 'MOCK-PROVIDER' | ||
}, | ||
{ | ||
edlUsername: 'test-user' | ||
} | ||
) | ||
|
||
expect(result).toEqual(true) | ||
}) | ||
|
||
test('throws a ForbiddenError if the user does not have permission', async () => { | ||
vi.spyOn(hasPermission, 'hasPermission').mockResolvedValue(false) | ||
|
||
const result = await canCreateProviderGroups.resolve( | ||
null, | ||
{ | ||
tag: 'MOCK-PROVIDER' | ||
}, | ||
{ | ||
edlUsername: 'test-user' | ||
} | ||
) | ||
|
||
expect(result).toEqual(forbiddenError('Not authorized to perform [create] on provider object [GROUP]')) | ||
}) | ||
|
||
test('when a tag is not provided and the user does not have permission', async () => { | ||
vi.spyOn(hasPermission, 'hasPermission').mockResolvedValue(false) | ||
|
||
const result = await canCreateProviderGroups.resolve( | ||
null, | ||
{ | ||
tag: 'CMR' | ||
}, | ||
{ | ||
edlUsername: 'test-user' | ||
} | ||
) | ||
expect(result).toEqual(false) | ||
}) | ||
}) |
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
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
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,38 @@ | ||
import { rule } from 'graphql-shield' | ||
|
||
import { hasPermission } from '../../utils/hasPermission' | ||
import { forbiddenError } from '../../utils/forbiddenError' | ||
|
||
/** | ||
* Check to see if the user can create provider groups using | ||
* the cmr permissions api. In order to create provider groups, the user must have the `create` | ||
* permission on the GROUP provider_object. | ||
* @method | ||
* @return {(true|ForbiddenError)} | ||
*/ | ||
export const canCreateProviderGroups = rule()(async (parent, params, context) => { | ||
const { edlUsername } = context | ||
|
||
const { tag } = params | ||
|
||
// If tag, perform check to see if the user has access to the given provider. | ||
if (tag && tag !== 'CMR') { | ||
if ( | ||
await hasPermission( | ||
context, | ||
{ | ||
permissions: 'create', | ||
permissionOptions: { | ||
provider: tag, | ||
target: 'GROUP', | ||
user_id: edlUsername | ||
} | ||
} | ||
) | ||
) return true | ||
|
||
return forbiddenError('Not authorized to perform [create] on provider object [GROUP]') | ||
} | ||
|
||
return false | ||
}) |
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
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
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