示例#1
0
    def handle(self,
               session,
               author,
               method,
               url,
               path,
               query_string,
               status,
               resource,
               resource_id,
               sub_resource=None,
               sub_resource_id=None,
               resource_before=None,
               resource_after=None):
        """This worker handles API events and attempts to determine whether
        they correspond to user subscriptions.

        :param session: An event-specific SQLAlchemy session.
        :param author: The author's user record.
        :param method: The HTTP Method.
        :param url: The Referer header from the request.
        :param path: The full HTTP Path requested.
        :param query_string: The HTTP query string from the request.
        :param status: The returned HTTP Status of the response.
        :param resource: The resource type.
        :param resource_id: The ID of the resource.
        :param sub_resource: The subresource type.
        :param sub_resource_id: The ID of the subresource.
        :param resource_before: The resource state before this event occurred.
        :param resource_after: The resource state after this event occurred.
        """
        if resource == 'timeline_event':
            story_id = resource_after.get('story_id')
            worklist_id = resource_after.get('worklist_id')
            if story_id is not None:
                subscribers = sub_api.subscription_get_all_subscriber_ids(
                    'story', story_id, session=session)
                self.handle_timeline_events(session, resource_after, author,
                                            subscribers)
            if worklist_id is not None:
                subscribers = sub_api.subscription_get_all_subscriber_ids(
                    'worklist', worklist_id, session=session)
                self.handle_timeline_events(session, resource_after, author,
                                            subscribers)

        elif resource == 'project_group':
            subscribers = sub_api.subscription_get_all_subscriber_ids(
                resource, resource_id, session=session)
            self.handle_resources(session=session,
                                  method=method,
                                  resource_id=resource_id,
                                  sub_resource_id=sub_resource_id,
                                  author=author,
                                  subscribers=subscribers)

        if method == 'DELETE' and not (sub_resource_id or sub_resource):
            self.handle_deletions(session, resource, resource_id)
示例#2
0
    def handle(self, session, author, method, url, path, query_string, status,
               resource, resource_id, sub_resource=None, sub_resource_id=None,
               resource_before=None, resource_after=None):
        """This worker handles API events and attempts to determine whether
        they correspond to user subscriptions.

        :param session: An event-specific SQLAlchemy session.
        :param author: The author's user record.
        :param method: The HTTP Method.
        :param url: The Referer header from the request.
        :param path: The full HTTP Path requested.
        :param query_string: The HTTP query string from the request.
        :param status: The returned HTTP Status of the response.
        :param resource: The resource type.
        :param resource_id: The ID of the resource.
        :param sub_resource: The subresource type.
        :param sub_resource_id: The ID of the subresource.
        :param resource_before: The resource state before this event occurred.
        :param resource_after: The resource state after this event occurred.
        """
        if resource == 'timeline_event':
            story_id = resource_after.get('story_id')
            worklist_id = resource_after.get('worklist_id')
            if story_id is not None:
                subscribers = sub_api.subscription_get_all_subscriber_ids(
                    'story', story_id, session=session)
                self.handle_timeline_events(
                    session, resource_after, author, subscribers)
            if worklist_id is not None:
                subscribers = sub_api.subscription_get_all_subscriber_ids(
                    'worklist', worklist_id, session=session)
                self.handle_timeline_events(
                    session, resource_after, author, subscribers)

        elif resource == 'project_group':
            subscribers = sub_api.subscription_get_all_subscriber_ids(
                resource, resource_id, session=session)
            self.handle_resources(session=session,
                                  method=method,
                                  resource_id=resource_id,
                                  sub_resource_id=sub_resource_id,
                                  author=author,
                                  subscribers=subscribers)

        if method == 'DELETE' and not (sub_resource_id or sub_resource):
            self.handle_deletions(session, resource, resource_id)
示例#3
0
    def handle(self, author_id, method, path, status, resource, resource_id,
               sub_resource=None, sub_resource_id=None,
               resource_before=None, resource_after=None):
        """This worker handles API events and attempts to determine whether
        they correspond to user subscriptions.

        :param author_id: ID of the author's user record.
        :param method: The HTTP Method.
        :param path: The full HTTP Path requested.
        :param status: The returned HTTP Status of the response.
        :param resource: The resource type.
        :param resource_id: The ID of the resource.
        :param sub_resource: The subresource type.
        :param sub_resource_id: The ID of the subresource.
        :param resource_before: The resource state before this event occurred.
        :param resource_after: The resource state after this event occurred.
        """

        if resource == 'timeline_event':
            event = timeline_events.event_get(resource_id)
            subscribers = subscriptions.subscription_get_all_subscriber_ids(
                'story', event.story_id
            )
            handle_timeline_events(event, author_id, subscribers)

        elif resource == 'project_group':
            subscribers = subscriptions.subscription_get_all_subscriber_ids(
                resource, resource_id
            )
            handle_resources(method=method,
                             resource_id=resource_id,
                             sub_resource_id=sub_resource_id,
                             author_id=author_id,
                             subscribers=subscribers)

        if method == 'DELETE' and not sub_resource_id:
            handle_deletions(resource, resource_id)
示例#4
0
    def handle(self, session, author, method, path, status, resource,
               resource_id, sub_resource=None, sub_resource_id=None,
               resource_before=None, resource_after=None):
        """This worker handles API events and attempts to determine whether
        they correspond to user subscriptions.

        :param session: An event-specific SQLAlchemy session.
        :param author: The author's user record.
        :param method: The HTTP Method.
        :param path: The full HTTP Path requested.
        :param status: The returned HTTP Status of the response.
        :param resource: The resource type.
        :param resource_id: The ID of the resource.
        :param sub_resource: The subresource type.
        :param sub_resource_id: The ID of the subresource.
        :param resource_before: The resource state before this event occurred.
        :param resource_after: The resource state after this event occurred.
        """
        if resource == 'timeline_event':
            event = db_api.entity_get(models.TimeLineEvent, resource_id,
                                      session=session)
            subscribers = sub_api.subscription_get_all_subscriber_ids(
                'story', event.story_id, session=session)
            self.handle_timeline_events(session, event, author, subscribers)

        elif resource == 'project_group':
            subscribers = sub_api.subscription_get_all_subscriber_ids(
                resource, resource_id, session=session)
            self.handle_resources(session=session,
                                  method=method,
                                  resource_id=resource_id,
                                  sub_resource_id=sub_resource_id,
                                  author=author,
                                  subscribers=subscribers)

        if method == 'DELETE' and not sub_resource_id:
            self.handle_deletions(session, resource, resource_id)
示例#5
0
    def get_subscribers(self, session, resource, resource_id):
        """Get a list of users who are subscribed to the resource,
        whose email address is valid, and whose email preferences indicate
        that they'd like to receive non-digest email.
        """
        subscribers = []

        # Resolve all the subscriber ID's.
        subscriber_ids = subscription_get_all_subscriber_ids(resource,
                                                             resource_id,
                                                             session=session)
        users = db_base.model_query(models.User, session) \
            .filter(models.User.id.in_(subscriber_ids)).all()

        for user in users:
            if not self.get_preference('plugin_email_enable', user) == 'true':
                continue
            subscribers.append(user)

        return subscribers
示例#6
0
    def get_subscribers(self, session, resource, resource_id):
        """Get a list of users who are subscribed to the resource,
        whose email address is valid, and whose email preferences indicate
        that they'd like to receive non-digest email.
        """
        subscribers = []

        # Resolve all the subscriber ID's.
        subscriber_ids = subscription_get_all_subscriber_ids(resource,
                                                             resource_id,
                                                             session=session)
        users = db_base.model_query(models.User, session) \
            .filter(models.User.id.in_(subscriber_ids)).all()

        for user in users:
            if not self.get_preference('plugin_email_enable', user) == 'true':
                continue
            subscribers.append(user)

        return subscribers
示例#7
0
    def test_get_subscribers(self):
        '''Test subscription discovery. The tested algorithm is as follows:
        If you're subscribed to a project_group, you will be notified about
        project_group, project, story, and task changes. If you are
        subscribed to a project, you will be notified about project, story, and
        task changes. If you are subscribed to a task, you will be notified
        about changes to that task. If you are subscribed to a story,
        you will be notified about changes to that story and its tasks.

        '''

        subscribers = subscription_get_all_subscriber_ids('invalid', 1)
        self.assertSetEqual(set(), subscribers)

        subscribers = subscription_get_all_subscriber_ids('timeline_event', 1)
        self.assertSetEqual({1, 3}, subscribers)

        subscribers = subscription_get_all_subscriber_ids('story', 1)
        self.assertSetEqual({1, 3}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('story', 2)
        self.assertSetEqual(set(), subscribers)
        subscribers = subscription_get_all_subscriber_ids('story', 3)
        self.assertSetEqual(set(), subscribers)
        subscribers = subscription_get_all_subscriber_ids('story', 4)
        self.assertSetEqual(set(), subscribers)
        subscribers = subscription_get_all_subscriber_ids('story', 5)
        self.assertSetEqual(set(), subscribers)

        subscribers = subscription_get_all_subscriber_ids('task', 1)
        self.assertSetEqual({1, 3}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('task', 2)
        self.assertSetEqual({3}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('task', 3)
        self.assertSetEqual({1, 3}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('task', 4)
        self.assertSetEqual(set(), subscribers)

        subscribers = subscription_get_all_subscriber_ids('project', 1)
        self.assertSetEqual({1}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('project', 2)
        self.assertSetEqual(set(), subscribers)
        subscribers = subscription_get_all_subscriber_ids('project', 3)
        self.assertSetEqual({1}, subscribers)

        subscribers = subscription_get_all_subscriber_ids('project_group', 1)
        self.assertSetEqual({1}, subscribers)
        subscribers = subscription_get_all_subscriber_ids('project_group', 2)
        self.assertSetEqual(set(), subscribers)
        subscribers = subscription_get_all_subscriber_ids('project_group', 3)
        self.assertSetEqual(set(), subscribers)