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

[#1289] tastypie auth #1296

Merged
merged 2 commits into from
Mar 4, 2015
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
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