Skip to content
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

GQL-52: Allow querying for Acls from within a group #127

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/resolvers/__tests__/acl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,64 @@ describe('Acl', () => {
})
})
})

describe('when the acl does not have catalogItemIdentity', () => {
test('returns null for collections', async () => {
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 1,
'CMR-Took': 7,
'CMR-Request-Id': 'abcd-1234-efgh-5678'
})
.get(/access-control\/acls/)
.reply(200, {
items: [
{
acl: {}
}
]
})

const response = await server.executeOperation({
variables: {},
query: `
query GetAcls($params: AclsInput) {
acls(params: $params) {
items {
catalogItemIdentity {
granuleApplicable
collectionApplicable
}
collections {
count
}
}
}
}`

}, {
contextValue
})

const { data, errors } = response.body.singleResult

expect(errors).toBeUndefined()

expect(data).toEqual({
acls: {
items: [
{
catalogItemIdentity: {
collectionApplicable: null,
granuleApplicable: null
},
collections: null
}
]
}
})
})
})
})

describe('acls', () => {
Expand Down
147 changes: 147 additions & 0 deletions src/resolvers/__tests__/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Group', () => {
process.env = { ...OLD_ENV }

process.env.ursRootUrl = 'http://example-urs.com'
process.env.cmrRootUrl = 'http://example-cmr.com'
})

afterEach(() => {
Expand Down Expand Up @@ -435,5 +436,151 @@ describe('Group', () => {
})
})
})

describe('acls', () => {
test('requests and returns a list of acls for this group', async () => {
nock(/example-urs/, {
reqheaders: {
'Client-Id': 'eed-test-graphql',
'X-Request-Id': 'abcd-1234-efgh-5678'
}
})
.get(/api\/user_groups\/90336eb8-309c-44f5-aaa8-1672765b1195/)
.reply(200, {
group_id: '90336eb8-309c-44f5-aaa8-1672765b1195',
app_uid: 'mmt_test',
client_id: '81FEem91NlTQreWv2UgtXQ',
name: 'Test Group',
description: 'Just a test group',
shared_user_group: false,
created_by: 'mmt_test',
tag: 'MMT_2'
})

nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 1,
'CMR-Took': 7,
'CMR-Request-Id': 'abcd-1234-efgh-5678'
})
.get('/access-control/acls?include_full_acl=true&page_size=25&permitted_group=90336eb8-309c-44f5-aaa8-1672765b1195')
.reply(200, {
items: [
{
concept_id: 'ACL100000-EDSC',
revision_id: 1,
identity_type: 'Catalog Item',
name: 'Mock Test Name',
location: 'Mock Location',
acl: {
group_permissions: [
{
permissions: [
'read'
],
group_id: '90336eb8-309c-44f5-aaa8-1672765b1195'
}
],
catalog_item_identity: {
name: 'Mock test',
provider_id: 'TEST_123',
collection_applicable: true,
collection_identifier: {
concept_ids: ['C120042746-MMT_2']
},
granule_applicable: true
}
}
}
]
})

nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Took': 7,
'CMR-Request-Id': 'abcd-1234-efgh-5678'
})
.get('/search/collections.umm_json?concept_id[]=C120042746-MMT_2&page_size=20')
.reply(200, {
items: [{
meta: {
'concept-id': 'C120042746-MMT_2',
'revision-id': '1'
},
umm: {
ShortName: 'Cras mattis consectetur purus sit amet fermentum.',
Version: '1'
}
}]
})

const response = await server.executeOperation({
variables: {
groupParams: {
id: '90336eb8-309c-44f5-aaa8-1672765b1195'
},
groupAclsParams: {
limit: 25
}
},
query: `query Group (
$groupParams: GroupInput
$groupAclsParams: GroupAclsInput
) {
group (
params: $groupParams
) {
id
acls (
params: $groupAclsParams
) {
items {
catalogItemIdentity {
granuleApplicable
collectionApplicable
}
collections {
items {
shortName
version
}
}
conceptId
}
}
}
}`
}, {
contextValue
})

const { data, errors } = response.body.singleResult

expect(errors).toBeUndefined()

expect(data).toEqual({
group: {
acls: {
items: [{
catalogItemIdentity: {
collectionApplicable: true,
granuleApplicable: true
},
collections: {
items: [
{
shortName: 'Cras mattis consectetur purus sit amet fermentum.',
version: '1'
}
]
},
conceptId: 'ACL100000-EDSC'
}]
},
id: '90336eb8-309c-44f5-aaa8-1672765b1195'
}
})
})
})
})
})
2 changes: 1 addition & 1 deletion src/resolvers/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default {
},

catalogItemIdentity: async (source) => {
const { catalogItemIdentity } = source
const { catalogItemIdentity = {} } = source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have to worry about null here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sir, we're good.


const camelcasedData = camelcaseKeys(catalogItemIdentity, { deep: true })

Expand Down
16 changes: 16 additions & 0 deletions src/resolvers/group.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseResolveInfo } from 'graphql-parse-resolve-info'
import { parseRequestedFields } from '../utils/parseRequestedFields'
import { handlePagingParams } from '../utils/handlePagingParams'

export default {
Query: {
Expand Down Expand Up @@ -79,6 +80,21 @@ export default {
context,
requestInfo
)
},

acls: async (source, args, context, info) => {
const { groupId } = source

const { dataSources } = context

return dataSources.aclSourceFetch(
handlePagingParams({
...args,
permittedGroup: groupId
}),
context,
parseResolveInfo(info)
)
}
}
}
3 changes: 1 addition & 2 deletions src/types/acl.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Acl {
"Collections query parameters"
params: CollectionsInput
) : CollectionList

}

type CatalogItemIdentity {
Expand Down Expand Up @@ -129,7 +128,7 @@ input AclsInput {
"Type of the object being controlled."
identityType: IdentityType

"The size of the range GraphDB searches on. Defaults to 20."
"The number of Acls to return."
limit: Int

"Zero based offset of individual results."
Expand Down
14 changes: 14 additions & 0 deletions src/types/group.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ type Group {

"List of members of the group."
members: GroupMemberList

"List of Acls this group belongs to."
acls (
"Group acls query parameters."
params: GroupAclsInput
): AclList
}

input GroupAclsInput {
"The number of Acls to return."
limit: Int

"Zero based offset of individual results."
offset: Int
}

type GroupList {
Expand Down