Skip to content

Commit

Permalink
[#2364] Change the API for Up after reviewing old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zzgvh committed Sep 19, 2016
1 parent 558090b commit af1922a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions akvo/rest/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UserSerializer(BaseRSRSerializer):
source='approved_employments', many=True, required=False
)
# Legacy fields to support Tastypie API emulation
user_profile = serializers.SerializerMethodField('get_user_profile')
legacy_org = serializers.SerializerMethodField('get_legacy_org')
username = serializers.SerializerMethodField('get_username')

class Meta:
Expand All @@ -64,15 +64,15 @@ class Meta:
'organisation',
'organisations',
'approved_employments',
'user_profile',
'legacy_org',
)
exclude = ('absolute_url',)

def __init__(self, *args, **kwargs):
""" Delete the 'absolute_url' field added in BaseRSRSerializer.__init__().
It's neither correct nor do we want this data to be visible.
Remove the fields "user_profile" and "username" that are only present to support older
Remove the fields "legacy_org" and "username" that are only present to support older
versions of Up calling the Tastypie API endpoints that we now emulate using DRF
"""
super(UserSerializer, self).__init__(*args, **kwargs)
Expand All @@ -81,14 +81,14 @@ def __init__(self, *args, **kwargs):
# Remove the fields unless we're called via Tastypie URLs
request = kwargs.get("context", {}).get("request", None)
if request and "/api/v1/" not in request.path:
del self.fields['user_profile']
del self.fields['legacy_org']
del self.fields['username']

def get_user_profile(self, obj):
""" The Tastypie endpoint included the organisation ID in a separate sub-object
def get_legacy_org(self, obj):
""" Up needs the last tag to be the user's org, it only needs the org ID
"""
if obj.first_organisation():
return {"object": "/api/v1/organisation/{}/".format(obj.first_organisation().id)}
return {"object": {"id": obj.first_organisation().id}}
return None

def get_username(self, obj):
Expand Down

0 comments on commit af1922a

Please sign in to comment.