Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Return the contributor admin ID when serializing other locations
Browse files Browse the repository at this point in the history
Profile page URLs are constructed using the ID of the admin user for the
contributor. We update the serialization of the "Other locations" section of the
facility detail page to be consistent with other places in the app where we
create profile page links.
  • Loading branch information
jwalgran committed Feb 7, 2020
1 parent bda3bc5 commit 2f95c59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/django/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ def get_other_locations(self, facility):
{
'lat': l.location.y,
'lng': l.location.x,
'contributor_id': l.contributor_id,
'contributor_id': l.contributor.admin.id if l.contributor
else None,
'contributor_name': l.contributor.name if l.contributor
else None,
'notes': l.notes,
Expand All @@ -475,7 +476,7 @@ def get_other_locations(self, facility):
'lat': l.facility_list_item.geocoded_point.y,
'lng': l.facility_list_item.geocoded_point.x,
'contributor_id': l.facility_list_item.source
.contributor_id,
.contributor.admin.id,
'contributor_name':
l.facility_list_item.source.contributor.name
if l.facility_list_item.source.contributor else None,
Expand Down
23 changes: 22 additions & 1 deletion src/django/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3717,6 +3717,11 @@ def setUp(self):
name='test contributor 2',
contrib_type=Contributor.OTHER_CONTRIB_TYPE)

self.assertFalse(self.other_contributor.id == self.other_user.id,
'We want to verify that we serialize the proper ID '
'and we can only do that if we have distinct '
'Contributor and User ID values.')

self.other_list = FacilityList \
.objects \
.create(header='header',
Expand Down Expand Up @@ -3780,6 +3785,14 @@ def test_serializes_other_match_location_in_facility_details(self):
5,
)

# The UI needs to build profile page links that use the ID of the User
# who is the "admin" of the Contributor, not the ID of the Contributor
# itself.
self.assertEqual(
data['properties']['other_locations'][0]['contributor_id'],
self.other_user.id
)

def test_does_not_serialize_inactive_list_item_matches(self):
self.other_source.is_active = False
self.other_source.save()
Expand Down Expand Up @@ -3815,7 +3828,7 @@ def test_serializes_other_locations_in_facility_details(self):
UpdateLocationParams.LAT: 41,
UpdateLocationParams.LNG: 43,
UpdateLocationParams.NOTES: 'A note',
UpdateLocationParams.CONTRIBUTOR_ID: self.contributor.id,
UpdateLocationParams.CONTRIBUTOR_ID: self.other_contributor.id,
})

self.client.logout()
Expand All @@ -3835,6 +3848,14 @@ def test_serializes_other_locations_in_facility_details(self):
'A note',
)

# The UI needs to build profile page links that use the ID of the User
# who is the "admin" of the Contributor, not the ID of the Contributor
# itself.
self.assertEqual(
data['properties']['other_locations'][0]['contributor_id'],
self.other_user.id
)

def test_serializes_other_location_without_note_or_contributor(self):
self.client.login(email=self.superuser_email,
password=self.superuser_password)
Expand Down

0 comments on commit 2f95c59

Please sign in to comment.