Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import logging
  2. import endpoints
  3. from google.appengine.ext import ndb
  4.  
  5. class Location(ndb.Model):
  6. name = ndb.StringProperty(required=True)
  7. description = ndb.TextProperty()
  8. address = ndb.StringProperty(required=True)
  9. can_put = ndb.UserProperty(repeated=True)
  10. can_get = ndb.UserProperty(repeated=True)
  11. can_delete = ndb.UserProperty(repeated=True)
  12. created = ndb.DateTimeProperty(auto_now_add=True)
  13. modified = ndb.DateTimeProperty(auto_now=True)
  14.  
  15. def _pre_put_hook(self):
  16. current_user = endpoints.get_current_user()
  17. if not current_user:
  18. logging.debug("Location put: Invalid token.")
  19. raise endpoints.UnauthorizedException("Invalid token.")
  20.  
  21. if self.key.id() is None:
  22. self.can_get.append(current_user)
  23. self.can_put.append(current_user)
  24. self.can_delete.append(current_user)
  25. else:
  26. location = self.key.get()
  27. if not current_user in location.can_put:
  28. logging.debug("Location put: Permission denied.")
  29. raise endpoints.ForbiddenException("Permission denied.")
  30.  
  31. @classmethod
  32. def _pre_get_hook(cls, key):
  33. current_user = endpoints.get_current_user()
  34. if not current_user:
  35. logging.debug("Location get: Invalid token.")
  36. raise endpoints.UnauthorizedException("Invalid token.")
  37.  
  38. location = key.get()
  39. if not current_user in location.can_get:
  40. logging.debug("Location get: Permission denied.")
  41. raise endpoints.ForbiddenException("Permission denied.")
  42.  
  43. @classmethod
  44. def _pre_delete_hook(cls, key):
  45. current_user = endpoints.get_current_user()
  46. if not current_user:
  47. logging.debug("Location delete: Invalid token.")
  48. raise endpoints.UnauthorizedException("Invalid token.")
  49.  
  50. location = key.get()
  51. if not current_user in location.can_delete:
  52. logging.debug("Location delete: Permission denied.")
  53. raise endpoints.ForbiddenException("Permission denied.")
  54.  
  55. RuntimeError: maximum recursion depth exceeded while calling a Python object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement