Skip to content

Commit

Permalink
Merge pull request #3250 from specify/issue-2480
Browse files Browse the repository at this point in the history
Make api endpoint return distinct divisions
  • Loading branch information
maxpatiiuk authored Apr 5, 2023
2 parents e779e0e + c1ee21e commit a89a552
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion specifyweb/specify/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,22 @@ def test_set_user_agents(self):
self.assertEqual(response.status_code, 204)

def test_set_user_agents_missing_exception(self):
collection2 = models.Collection.objects.create(
catalognumformatname='test2',
collectionname='TestCollection2',
isembeddedcollectingevent=False,
discipline=self.discipline)

UserPolicy.objects.create(
collection_id=collection2.id,
specifyuser_id=self.specifyuser.id,
resource='%',
action='%',
)

c = Client()
c.force_login(self.specifyuser)

response = c.post(
f'/api/set_agents/{self.specifyuser.id}/',
data=[],
Expand All @@ -486,7 +500,7 @@ def test_set_user_agents_missing_exception(self):
{'MissingAgentForAccessibleCollection': {
'all_accessible_divisions': [self.division.id],
'missing_for_6': [],
'missing_for_7': [self.collection.id]
'missing_for_7': [self.collection.id, collection2.id]
}}
)

Expand Down
2 changes: 1 addition & 1 deletion specifyweb/specify/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def check_collection_access_against_agents(userid: int) -> None:
if missing_for_6 or missing_for_7:
all_divisions = models.Division.objects.filter(
disciplines__collections__id__in=[cid for cid, _ in sp6_collections] + [c.id for c in sp7_collections]
).values_list('id', flat=True)
).values_list('id', flat=True).distinct()
raise MissingAgentForAccessibleCollection({
'missing_for_6': missing_for_6,
'missing_for_7': missing_for_7,
Expand Down

0 comments on commit a89a552

Please sign in to comment.