Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- import endpoints
- from google.appengine.ext import ndb
- class Location(ndb.Model):
- name = ndb.StringProperty(required=True)
- description = ndb.TextProperty()
- address = ndb.StringProperty(required=True)
- can_put = ndb.UserProperty(repeated=True)
- can_get = ndb.UserProperty(repeated=True)
- can_delete = ndb.UserProperty(repeated=True)
- created = ndb.DateTimeProperty(auto_now_add=True)
- modified = ndb.DateTimeProperty(auto_now=True)
- def _pre_put_hook(self):
- current_user = endpoints.get_current_user()
- if not current_user:
- logging.debug("Location put: Invalid token.")
- raise endpoints.UnauthorizedException("Invalid token.")
- if self.key.id() is None:
- self.can_get.append(current_user)
- self.can_put.append(current_user)
- self.can_delete.append(current_user)
- else:
- location = self.key.get()
- if not current_user in location.can_put:
- logging.debug("Location put: Permission denied.")
- raise endpoints.ForbiddenException("Permission denied.")
- @classmethod
- def _pre_get_hook(cls, key):
- current_user = endpoints.get_current_user()
- if not current_user:
- logging.debug("Location get: Invalid token.")
- raise endpoints.UnauthorizedException("Invalid token.")
- location = key.get()
- if not current_user in location.can_get:
- logging.debug("Location get: Permission denied.")
- raise endpoints.ForbiddenException("Permission denied.")
- @classmethod
- def _pre_delete_hook(cls, key):
- current_user = endpoints.get_current_user()
- if not current_user:
- logging.debug("Location delete: Invalid token.")
- raise endpoints.UnauthorizedException("Invalid token.")
- location = key.get()
- if not current_user in location.can_delete:
- logging.debug("Location delete: Permission denied.")
- raise endpoints.ForbiddenException("Permission denied.")
- RuntimeError: maximum recursion depth exceeded while calling a Python object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement