This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenConceptLab/ocl_issues#147: Users can view public collections that…
… are marked private if the user query is specified
- Loading branch information
Showing
13 changed files
with
1,143 additions
and
1,045 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
import {put, get, post} from "./utils" | ||
|
||
const api = { | ||
organizations: { | ||
new: async (orgId: string, token: string, publicAccess: boolean= true): Promise<Response> => publicAccess ? | ||
post('orgs/', {id: orgId, name: orgId}, token) : | ||
post('orgs/', {id: orgId, name: orgId, public_access: 'None'}, token), | ||
addNewMember: async (membersUrl, user, token) => put(`${membersUrl}${user}/`, undefined, token), | ||
}, | ||
collections: { | ||
list: async (ownerUrl, token, verbose=true) => (await get(`${ownerUrl}collections/?verbose=${verbose}`, token)).json(), | ||
new: async (ownerUrl, body, token) => (await post(`${ownerUrl}collections/`, body, token)).json(), | ||
}, | ||
}; | ||
|
||
export default api; |
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,63 @@ | ||
import * as faker from 'faker'; | ||
import {get, post, authenticate, authenticateAdmin, newUser, del} from "./utils"; | ||
import collectionFixture from "./fixtures/collection"; | ||
import api from "./api"; | ||
|
||
describe('List collections for a specific user or organization', () => { | ||
let adminToken; | ||
let user1InOrg1; | ||
let user2InOrg1; | ||
let user3NotInOrg1; | ||
let org1; | ||
let privateCollectionOwnedByUser1; | ||
let privateCollectionOwnedByOrg1; | ||
let publicCollectionOwnedByUser1; | ||
let publicCollectionOwnedByOrg1; | ||
|
||
beforeAll(async () => { | ||
adminToken = await authenticateAdmin(); | ||
// making this as random as possible since we can't delete users | ||
const generateRandomName = () => faker.name.firstName() + faker.name.lastName(); | ||
const username1 = generateRandomName(); | ||
const username2 = generateRandomName(); | ||
const username3 = generateRandomName(); | ||
const orgId1 = faker.company.bsNoun(); | ||
|
||
user1InOrg1 = await newUser(username1, username1, adminToken); | ||
user2InOrg1 = await newUser(username2, username2, adminToken); | ||
user3NotInOrg1 = await newUser(username3, username3, adminToken); | ||
user1InOrg1.token = await authenticate(username1, username1); | ||
user2InOrg1.token = await authenticate(username2, username2); | ||
user3NotInOrg1.token = await authenticate(username3, username3); | ||
|
||
org1 = await (await api.organizations.new(orgId1, adminToken)).json(); | ||
await api.organizations.addNewMember(org1.members_url, user1InOrg1.username, adminToken); | ||
await api.organizations.addNewMember(org1.members_url, user2InOrg1.username, adminToken); | ||
|
||
privateCollectionOwnedByUser1 = await api.collections.new(user1InOrg1.url, collectionFixture(), user1InOrg1.token); | ||
privateCollectionOwnedByOrg1 = await api.collections.new(org1.url, collectionFixture(), user1InOrg1.token); | ||
publicCollectionOwnedByUser1 = await api.collections.new(user1InOrg1.url, collectionFixture('View'), user1InOrg1.token); | ||
publicCollectionOwnedByOrg1 = await api.collections.new(org1.url, collectionFixture('View'), user1InOrg1.token); | ||
}); | ||
|
||
afterAll(async () => { | ||
const items = [ | ||
publicCollectionOwnedByOrg1, | ||
publicCollectionOwnedByUser1, | ||
privateCollectionOwnedByOrg1, | ||
privateCollectionOwnedByUser1, | ||
org1, | ||
user3NotInOrg1, | ||
user2InOrg1, | ||
user1InOrg1, | ||
]; | ||
for(let i in items) await del(items[i].url, adminToken); | ||
}); | ||
|
||
test('user can retrieve own collections', async () => { | ||
expect(await api.collections.list(`${user1InOrg1.url}`, user1InOrg1.token)).toEqual([ | ||
publicCollectionOwnedByUser1, | ||
privateCollectionOwnedByUser1, | ||
]) | ||
}); | ||
}); |
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,21 @@ | ||
import * as faker from 'faker'; | ||
|
||
const collection = (publicAccess = 'None') => { | ||
return { | ||
"type": "Collection", | ||
"uuid": faker.random.uuid(), | ||
"id": faker.random.number(), | ||
"external_id": "", | ||
"short_code": faker.company.bsNoun(), | ||
"name": faker.company.companyName(), | ||
"full_name": faker.company.companyName(), | ||
"collection_type": "Core Dataset", | ||
"public_access": publicAccess, | ||
"supported_locales": "en,es", | ||
"website": "", | ||
"description": "", | ||
"extras": {}, | ||
} | ||
}; | ||
|
||
export default collection; |
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 |
---|---|---|
@@ -1,15 +1,7 @@ | ||
__author__ = 'snyaggarwal' | ||
|
||
from oclapi.filters import HaystackSearchFilter | ||
from oclapi.filters import ConceptContainerPermissionedSearchFilter | ||
|
||
|
||
class CollectionSearchFilter(HaystackSearchFilter): | ||
def get_filters(self, request, view): | ||
filters = super(CollectionSearchFilter, self).get_filters(request, view) | ||
if view.parent_resource: | ||
filters.update({'owner': view.parent_resource.mnemonic}) | ||
filters.update({'ownerType': view.parent_resource.resource_type()}) | ||
else: | ||
filters.update({'public_can_view': True}) | ||
|
||
return filters | ||
class CollectionSearchFilter(ConceptContainerPermissionedSearchFilter): | ||
pass |
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
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 |
---|---|---|
@@ -1,16 +1,7 @@ | ||
__author__ = 'misternando' | ||
|
||
from oclapi.filters import HaystackSearchFilter | ||
from oclapi.filters import ConceptContainerPermissionedSearchFilter | ||
|
||
__author__ = 'misternando' | ||
|
||
|
||
class SourceSearchFilter(HaystackSearchFilter): | ||
def get_filters(self, request, view): | ||
filters = super(SourceSearchFilter, self).get_filters(request, view) | ||
if view.parent_resource: | ||
filters.update({'owner': view.parent_resource.mnemonic}) | ||
filters.update({'ownerType': view.parent_resource.resource_type()}) | ||
else: | ||
filters.update({'public_can_view': True}) | ||
return filters | ||
class SourceSearchFilter(ConceptContainerPermissionedSearchFilter): | ||
pass |
Oops, something went wrong.