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

[OSDEV-1474] Add contributor type to /api/contributors/ endpoint #461

Merged
merged 5 commits into from
Dec 17, 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
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### What's new
* [OSDEV-1383](https://opensupplyhub.atlassian.net/browse/OSDEV-1383) - Edited text of the automated email that notifies a contributor when one of their facilities has been claimed. The new text provides more information to the contributor to understand the claim process and how they can encourage more of their facilities to claim their profile.
* [OSDEV-1474](https://opensupplyhub.atlassian.net/browse/OSDEV-1474) - Added contributor type value to response of `/api/contributors/` endpoint.

### Release instructions:
* Ensure that the following commands are included in the `post_deployment` command:
Expand Down
32 changes: 26 additions & 6 deletions src/django/api/tests/test_contributors_list_api_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def setUp(self):
self.contrib_six_name = "contributor with one good and one error item"
self.contrib_seven_name = "contributor with create=False API source"

self.contrib_one_type = "Brand / Retailer"
self.contrib_two_type = "Multi-Stakeholder Initiative"
self.contrib_three_type = "Union"
self.contrib_four_type = "Brand / Retailer"
self.contrib_five_type = "Multi-Stakeholder Initiative"
self.contrib_six_type = "Test"
self.contrib_seven_type = "Union"

self.country_code = "US"
self.list_one_name = "one"
self.list_one_b_name = "one-b"
Expand All @@ -57,43 +65,44 @@ def setUp(self):
self.contrib_one = Contributor.objects.create(
admin=self.user_one,
name=self.contrib_one_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_one_type,
)

self.contrib_two = Contributor.objects.create(
admin=self.user_two,
name=self.contrib_two_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_two_type,
)

self.contrib_three = Contributor.objects.create(
admin=self.user_three,
name=self.contrib_three_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_three_type,
)

self.contrib_four = Contributor.objects.create(
admin=self.user_four,
name=self.contrib_four_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_four_type,
)

self.contrib_five = Contributor.objects.create(
admin=self.user_five,
name=self.contrib_five_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_five_type,
)

self.contrib_six = Contributor.objects.create(
admin=self.user_six,
name=self.contrib_six_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
other_contrib_type=self.contrib_six_type,
)

self.contrib_seven = Contributor.objects.create(
admin=self.user_seven,
name=self.contrib_seven_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_seven_type,
)

self.list_one = FacilityList.objects.create(
Expand Down Expand Up @@ -216,12 +225,18 @@ def test_contributors_list_has_only_contributors_with_active_lists(self):
response = self.client.get("/api/contributors/")
response_data = response.json()
contributor_names = list(zip(*response_data))[1]
contributor_types = list(zip(*response_data))[2]

self.assertIn(
self.contrib_one_name,
contributor_names,
)

self.assertIn(
self.contrib_one_type,
contributor_types,
)

self.assertNotIn(
self.contrib_two_name,
contributor_names,
Expand All @@ -247,6 +262,11 @@ def test_contributors_list_has_only_contributors_with_active_lists(self):
contributor_names,
)

self.assertIn(
self.contrib_six_type,
contributor_types,
)

self.assertEqual(
2,
len(contributor_names),
Expand Down
18 changes: 12 additions & 6 deletions src/django/api/views/contributor/all_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
@throttle_classes([])
def all_contributors(_):
"""
Returns list contributors as a list of tuples of contributor IDs and names.
Returns list contributors as a list of tuples of
contributor IDs, names and types.

## Sample Response

[
[1, "Contributor One"]
[2, "Contributor Two"]
[1, "Contributor One", "Brand/Retailer"]
[2, "Contributor Two", "Service Provider"]
]
"""
response_data = [
(contributor.id, contributor.name)
for contributor
in active_contributors().order_by('name')
(
contributor.id,
contributor.name,
contributor.other_contrib_type
if contributor.contrib_type == "Other"
else contributor.contrib_type
)
for contributor in active_contributors().order_by('name')
]

return Response(response_data)
Loading