예제 #1
0
    def get(self,
            marker=None,
            offset=None,
            limit=None,
            event_type=None,
            subscriber_id=None,
            sort_field='id',
            sort_dir='asc'):
        """Retrieve a list of subscriptions.

        :param marker: The resource id where the page should begin.
        :param offset: The offset to begin the page at.
        :param limit: The number of subscriptions to retrieve.
        :param event_type: The type of resource to search by.
        :param subscriber_id: The unique ID of the subscriber to search by.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """

        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_sub = subscription_events_api.subscription_events_get(marker)
        current_user = user_api.user_get(request.current_user_id)
        if current_user.id != subscriber_id and \
                not current_user.is_superuser:
            abort(403, _("Permission Denied"))

        if marker_sub and marker_sub.user_id != subscriber_id:
            marker_sub = None

        subscriptions = subscription_events_api.subscription_events_get_all(
            marker=marker_sub,
            offset=offset,
            limit=limit,
            subscriber_id=subscriber_id,
            event_type=event_type,
            sort_field=sort_field,
            sort_dir=sort_dir)
        subscription_count = \
            subscription_events_api.subscription_events_get_count(
                subscriber_id=subscriber_id,
                event_type=event_type)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        if offset is not None:
            response.headers['X-Offset'] = str(offset)
        response.headers['X-Total'] = str(subscription_count)
        if marker_sub:
            response.headers['X-Marker'] = str(marker_sub.id)

        return [SubscriptionEvent.from_db_model(s) for s in subscriptions]
    def get(self, marker=None, offset=None, limit=None, event_type=None,
            subscriber_id=None, sort_field='id', sort_dir='asc'):
        """Retrieve a list of subscriptions.

        :param marker: The resource id where the page should begin.
        :param offset: The offset to begin the page at.
        :param limit: The number of subscriptions to retrieve.
        :param event_type: The type of resource to search by.
        :param subscriber_id: The unique ID of the subscriber to search by.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """

        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_sub = subscription_events_api.subscription_events_get(marker)
        current_user = user_api.user_get(request.current_user_id)
        if current_user.id != subscriber_id and \
                not current_user.is_superuser:
            abort(403, _("Permission Denied"))

        if marker_sub and marker_sub.user_id != subscriber_id:
            marker_sub = None

        subscriptions = subscription_events_api.subscription_events_get_all(
            marker=marker_sub,
            offset=offset,
            limit=limit,
            subscriber_id=subscriber_id,
            event_type=event_type,
            sort_field=sort_field,
            sort_dir=sort_dir)
        subscription_count = \
            subscription_events_api.subscription_events_get_count(
                subscriber_id=subscriber_id,
                event_type=event_type)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        if offset is not None:
            response.headers['X-Offset'] = str(offset)
        response.headers['X-Total'] = str(subscription_count)
        if marker_sub:
            response.headers['X-Marker'] = str(marker_sub.id)

        return [SubscriptionEvent.from_db_model(s) for s in subscriptions]