Пример #1
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))
Пример #2
0
    def delete(self, request, location_uuid):
        """Deletes a resource.

        Disables 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 not location.open_access_granted():
            return http.HttpResponseNotFound(
                'Open access to location already disallowed.')
        location.revoke_open_access()
        return http.HttpResponseNoContent()
Пример #3
0
    def delete(self, request, location_uuid, user_uuid):
        """Deletes a resource.

        Revokes access to a given location by a given user. If the
        location is open, the user will still be able to access the
        location after this call succeeds.
        """
        location = request.site.locations.find_item(location_uuid)
        if not location:
            return http.HttpResponseNotFound('Location not found.')
        try:
            location.revoke_access(user_uuid)
            return http.HttpResponseNoContent()
        except LookupError as ex:
            return http.HttpResponseNotFound(str(ex))
Пример #4
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))
Пример #5
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))
Пример #6
0
 def delete(self, request, uuid):
     """Deletes a resource with a given uuid."""
     deleted = self.collection.delete_item(uuid)
     if not deleted:
         return http.HttpResponseNotFound(
             '%s not found' % self.collection.item_name.capitalize())
     return http.HttpResponseNoContent()
Пример #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))
Пример #8
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