Skip to content

Commit

Permalink
Merge pull request #1296 from akvo/1289_tastypie_auth
Browse files Browse the repository at this point in the history
1289 tastypie auth
  • Loading branch information
kardan committed Mar 4, 2015
2 parents 45fef4d + b0343ce commit cd9fd0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 0 additions & 4 deletions akvo/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType

from tastypie.authentication import ApiKeyAuthentication
from tastypie.http import HttpUnauthorized

#from models import AkvoApiKey
from akvo.rsr.models import Organisation

class ConditionalApiKeyAuthentication(ApiKeyAuthentication):
""" Allows for requiring API key authentication only for selected request methods
Expand Down
5 changes: 4 additions & 1 deletion akvo/api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def dehydrate(self, bundle):
"""
bundle = super(UserResource, self).dehydrate(bundle)
if self._meta.authentication.is_authenticated(bundle.request):
organisations = bundle.request.user.organisations.all()
try:
organisations = bundle.request.user.organisations.all()
except:
organisations = []

# find out if the user has a profile that's associated with the API key owner org
profile = get_user_model().objects.filter(organisations__in=organisations, id=bundle.obj.id)
Expand Down

0 comments on commit cd9fd0a

Please sign in to comment.