Skip to content

Instantly share code, notes, and snippets.

@bogsio
Created July 23, 2014 16:55
Show Gist options
  • Save bogsio/89584cd60f986c87c4db to your computer and use it in GitHub Desktop.
Save bogsio/89584cd60f986c87c4db to your computer and use it in GitHub Desktop.
T2T - Add authorization
from tastypie.authorization import Authorization
from tastypie.exceptions import Unauthorized
class AuthorizationByUser(Authorization):
def read_list(self, object_list, bundle):
return object_list.filter(author=bundle.request.user)
def read_detail(self, object_list, bundle):
return bundle.obj.author == bundle.request.user
def create_list(self, object_list, bundle):
raise Unauthorized('Can\'t create lists')
def create_detail(self, object_list, bundle):
return Unauthorized('Can\'t create lists')
def update_list(self, object_list, bundle):
return Unauthorized('Can\'t update lists')
def update_detail(self, object_list, bundle):
return Unauthorized('Can\'t update lists')
def delete_list(self, object_list, bundle):
raise Unauthorized("Sorry, no deletes.")
def delete_detail(self, object_list, bundle):
raise Unauthorized("Sorry, no deletes.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment