Esempio n. 1
0
 def get(self, request, uuid):
     """Returns json representation of a resource with a given uuid."""
     item = self.collection.find_item(uuid)
     if item is None:
         return http.HttpResponseNotFound(
             '%s not found' % self.collection.item_name.capitalize())
     return http.HttpResponseOKJson(item.attributes_dict(request.site_url))
Esempio n. 2
0
 def get(self, request, location_uuid):
     """Check if a resource that enables open access to a location exists."""
     location = request.site.locations.find_item(location_uuid)
     if location is None:
         return http.HttpResponseNotFound('Location not found.')
     if not location.open_access_granted():
         return http.HttpResponseNotFound(
             'Open access to location disallowed.')
     return http.HttpResponseOKJson(self._attributes_dict(request))
Esempio n. 3
0
 def get(self, request):
     """Returns json representation of all resources in the collection."""
     items_list = [
         item.attributes_dict(request.site_url)
         for item in self.collection.all()
     ]
     return http.HttpResponseOKJson({
         'self': _full_url(request),
         self.collection_name: items_list
     })
Esempio n. 4
0
 def put(self, request, title, header, message, branding):
     try:
         request.site.update_skin(title=title,
                                  header=header,
                                  message=message,
                                  branding=branding)
     except ValidationError as ex:
         return http.HttpResponseBadRequest(
             'Failed to update login page: ' + ', '.join(ex.messages))
     return http.HttpResponseOKJson(request.site.skin())
Esempio n. 5
0
    def put(self, request, location_uuid):
        """Creates a resource that enables open access to a given location."""
        location = request.site.locations.find_item(location_uuid)
        if location is None:
            return http.HttpResponseNotFound('Location not found.')

        if location.open_access_granted():
            return http.HttpResponseOKJson(self._attributes_dict(request))

        location.grant_open_access()
        response = http.HttpResponseCreated(self._attributes_dict(request))
        response['Location'] = _full_url(request)
        return response
Esempio n. 6
0
    def get(self, request, location_uuid, user_uuid):
        """Checks if a resource that grants access exists.

        This is not equivalent of checking if the user can access the
        location. If the location is open, but the user is not
        explicitly granted access, not found failure is returned.
        """
        location = request.site.locations.find_item(location_uuid)
        if location is None:
            return http.HttpResponseNotFound('Location not found.')
        try:
            permission = location.get_permission(user_uuid)
            return http.HttpResponseOKJson(
                permission.attributes_dict(request.site_url))
        except LookupError as ex:
            return http.HttpResponseNotFound(str(ex))
Esempio n. 7
0
    def put(self, request, location_uuid, user_uuid):
        """Creates a resource.

        Grants access to a given location by a given user.
        """
        location = request.site.locations.find_item(location_uuid)
        if not location:
            return http.HttpResponseNotFound('Location not found.')
        try:
            (permission, created) = location.grant_access(user_uuid)
            attributes_dict = permission.attributes_dict(request.site_url)
            if created:
                response = http.HttpResponseCreated(attributes_dict)
                response['Location'] = attributes_dict['self']
            else:
                response = http.HttpResponseOKJson(attributes_dict)
            return response
        except LookupError as ex:
            return http.HttpResponseNotFound(str(ex))
Esempio n. 8
0
 def get(self, request):
     """Returns an email or an authentication required error."""
     user = _get_user(request)
     if user is not None:
         return http.HttpResponseOKJson({'email': user.email})
     return http.HttpResponseNotAuthenticated()
Esempio n. 9
0
 def get(self, request):
     return http.HttpResponseOKJson(request.site.skin())