Skip to content

Commit 2ec050c

Browse files
jstone-devbencap
authored andcommitted
Cleanup and response to PR feedback
1 parent f3fe567 commit 2ec050c

File tree

5 files changed

+11
-71
lines changed

5 files changed

+11
-71
lines changed

src/mavedb/lib/permissions.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
9898
editor_user_ids.add(user_association.user_id)
9999
elif user_association.contribution_role == ContributionRole.viewer:
100100
viewer_user_ids.add(user_association.user_id)
101-
user_is_admin = user_is_owner or (user_data is not None and (user_data.user.id in admin_user_ids))
102-
user_may_edit = user_is_admin or (
103-
user_data is not None and (user_data.user.id in admin_user_ids or user_data.user.id in editor_user_ids)
104-
)
101+
user_is_admin = user_is_owner or (user_data is not None and user_data.user.id in admin_user_ids)
102+
user_may_edit = user_is_admin or (user_data is not None and user_data.user.id in editor_user_ids)
105103
user_may_view_private = user_may_edit or (user_data is not None and (user_data.user.id in viewer_user_ids))
106104

107105
save_to_logging_context({"resource_is_published": published})
@@ -293,7 +291,6 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
293291
if user_may_view_private or not private:
294292
return PermissionResponse(True)
295293
# Roles which may perform this operation.
296-
# TODO should the mapper be able to list all collections? Do we ever intend to pass a collection urn to the mapper?
297294
elif roles_permitted(active_roles, [UserRole.admin]):
298295
return PermissionResponse(True)
299296
elif private:
@@ -317,8 +314,6 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
317314
else:
318315
return PermissionResponse(False, 403, f"insufficient permissions for URN '{item.urn}'")
319316
elif action == Action.DELETE:
320-
# TODO should collection admins be allowed to delete a collection?
321-
# TODO who should be allowed to delete an official collection? mavedb admins only?
322317
# A collection may be deleted even if it has been published, as long as it is not an official collection.
323318
if user_is_owner:
324319
return PermissionResponse(
@@ -334,7 +329,6 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
334329
return PermissionResponse(False, 404, f"collection with URN '{item.urn}' not found")
335330
else:
336331
return PermissionResponse(False)
337-
# TODO should collection admins be allowed to publish a collection? (I think yes)
338332
elif action == Action.PUBLISH:
339333
if user_is_admin:
340334
return PermissionResponse(True)
@@ -364,7 +358,6 @@ def has_permission(user_data: Optional[UserData], item: Base, action: Action) ->
364358
else f"insufficient permissions for URN '{item.urn}'"
365359
),
366360
)
367-
# TODO is add_role an ok name for this action, or should we create a new action called "add_user"?
368361
elif action == Action.ADD_ROLE:
369362
# Both collection admins and MaveDB admins can add a user to a collection role
370363
if user_is_admin or roles_permitted(active_roles, [UserRole.admin]):

src/mavedb/view_models/collection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,5 @@ class Collection(SavedCollection):
9191

9292
# Properties to return to admin clients or non-admin clients who are admins of the returned collection
9393
# NOTE: Coupled to ContributionRole enum
94-
# TODO should MaveDB admins get AdminUsers instead of Users?
9594
class AdminCollection(Collection):
9695
pass

src/mavedb/view_models/experiment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
class OfficialCollection(BaseModel):
33-
badge_name: Optional[str]
33+
badge_name: str
3434
name: str
3535
urn: str
3636

src/mavedb/view_models/score_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ExternalLink(BaseModel):
4343

4444

4545
class OfficialCollection(BaseModel):
46-
badge_name: Optional[str]
46+
badge_name: str
4747
name: str
4848
urn: str
4949

tests/routers/test_collections.py

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from copy import deepcopy
33

44
import jsonschema
5+
import pytest
56

67
from mavedb.lib.validation.urn_re import MAVEDB_COLLECTION_URN_RE
8+
from mavedb.models.enums.contribution_role import ContributionRole
79
from mavedb.view_models.collection import Collection
810
from tests.helpers.constants import (
911
EXTRA_USER,
@@ -48,7 +50,11 @@ def test_create_public_collection(client, setup_router_db):
4850
assert (key, expected_response[key]) == (key, response_data[key])
4951

5052

51-
def test_add_collection_admin(client, setup_router_db):
53+
@pytest.mark.parametrize(
54+
"role",
55+
ContributionRole._member_names_
56+
)
57+
def test_add_collection_user_to_collection_role(role, client, setup_router_db):
5258
collection = create_collection(client, {"private": True})
5359

5460
response = client.post(f"/api/v1/collections/{collection['urn']}/admins", json={"orcid_id": EXTRA_USER["username"]})
@@ -79,62 +85,6 @@ def test_add_collection_admin(client, setup_router_db):
7985
assert (key, expected_response[key]) == (key, response_data[key])
8086

8187

82-
def test_add_collection_editor(client, setup_router_db):
83-
collection = create_collection(client)
84-
85-
response = client.post(
86-
f"/api/v1/collections/{collection['urn']}/editors", json={"orcid_id": EXTRA_USER["username"]}
87-
)
88-
assert response.status_code == 200
89-
response_data = response.json()
90-
expected_response = deepcopy(TEST_COLLECTION_RESPONSE)
91-
expected_response.update(
92-
{
93-
"urn": collection["urn"],
94-
"badgeName": None,
95-
"description": None,
96-
"editors": [
97-
{
98-
"firstName": EXTRA_USER["first_name"],
99-
"lastName": EXTRA_USER["last_name"],
100-
"orcidId": EXTRA_USER["username"],
101-
}
102-
],
103-
}
104-
)
105-
assert sorted(expected_response.keys()) == sorted(response_data.keys())
106-
for key in expected_response:
107-
assert (key, expected_response[key]) == (key, response_data[key])
108-
109-
110-
def test_add_collection_viewer(client, setup_router_db):
111-
collection = create_collection(client)
112-
113-
response = client.post(
114-
f"/api/v1/collections/{collection['urn']}/viewers", json={"orcid_id": EXTRA_USER["username"]}
115-
)
116-
assert response.status_code == 200
117-
response_data = response.json()
118-
expected_response = deepcopy(TEST_COLLECTION_RESPONSE)
119-
expected_response.update(
120-
{
121-
"urn": response_data["urn"],
122-
"badgeName": None,
123-
"description": None,
124-
"viewers": [
125-
{
126-
"firstName": EXTRA_USER["first_name"],
127-
"lastName": EXTRA_USER["last_name"],
128-
"orcidId": EXTRA_USER["username"],
129-
}
130-
],
131-
}
132-
)
133-
assert sorted(expected_response.keys()) == sorted(response_data.keys())
134-
for key in expected_response:
135-
assert (key, expected_response[key]) == (key, response_data[key])
136-
137-
13888
def test_creator_can_read_private_collection(session, client, setup_router_db, anonymous_app_overrides):
13989
collection = create_collection(client)
14090

@@ -239,7 +189,6 @@ def test_unauthorized_user_cannot_read_private_collection(session, client, setup
239189

240190
with DependencyOverrider(extra_user_app_overrides):
241191
response = client.get(f"/api/v1/collections/{collection['urn']}")
242-
# response = client.get(f"/api/v1/users/me")
243192

244193
assert response.status_code == 404
245194
assert f"collection with URN '{collection['urn']}' not found" in response.json()["detail"]
@@ -250,7 +199,6 @@ def test_anonymous_cannot_read_private_collection(session, client, setup_router_
250199

251200
with DependencyOverrider(anonymous_app_overrides):
252201
response = client.get(f"/api/v1/collections/{collection['urn']}")
253-
# response = client.get(f"/api/v1/users/me")
254202

255203
assert response.status_code == 404
256204
assert f"collection with URN '{collection['urn']}' not found" in response.json()["detail"]

0 commit comments

Comments
 (0)