Switch to unified view

a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
...
...
81
    @classmethod
81
    @classmethod
82
    def post(cls, artifact, topic, **kw):
82
    def post(cls, artifact, topic, **kw):
83
        '''Create a notification and  send the notify message'''
83
        '''Create a notification and  send the notify message'''
84
        import allura.tasks.notification_tasks
84
        import allura.tasks.notification_tasks
85
        n = cls._make_notification(artifact, topic, **kw)
85
        n = cls._make_notification(artifact, topic, **kw)
86
        if n:
86
        allura.tasks.notification_tasks.notify.post(
87
            allura.tasks.notification_tasks.notify.post(
87
            n._id, artifact.index_id(), topic)
88
                n._id, artifact.index_id(), topic)
88
        return n
89
        return n
89
90
90
    @classmethod
91
    @classmethod
91
    def post_user(cls, user, artifact, topic, **kw):
92
    def post_user(cls, user, artifact, topic, **kw):
92
        '''Create a notification and deliver directly to a user's flash
93
        '''Create a notification and deliver directly to a user's flash
...
...
98
            session(mbox).flush(mbox)
99
            session(mbox).flush(mbox)
99
        except pymongo.errors.DuplicateKeyError:
100
        except pymongo.errors.DuplicateKeyError:
100
            session(mbox).expunge(mbox)
101
            session(mbox).expunge(mbox)
101
            mbox = Mailbox.query.get(user_id=user._id, is_flash=True)
102
            mbox = Mailbox.query.get(user_id=user._id, is_flash=True)
102
        n = cls._make_notification(artifact, topic, **kw)
103
        n = cls._make_notification(artifact, topic, **kw)
104
        if n:
103
        mbox.queue.append(n._id)
105
            mbox.queue.append(n._id)
104
        return n
106
        return n
105
107
106
    @classmethod
108
    @classmethod
107
    def _make_notification(cls, artifact, topic, **kwargs):
109
    def _make_notification(cls, artifact, topic, **kwargs):
110
        from allura.model import Project
108
        idx = artifact.index()
111
        idx = artifact.index()
109
        subject_prefix = '[%s:%s] ' % (
112
        subject_prefix = '[%s:%s] ' % (
110
            c.project.shortname, c.app.config.options.mount_point)
113
            c.project.shortname, c.app.config.options.mount_point)
111
        if topic == 'message':
114
        if topic == 'message':
112
            post = kwargs.pop('post')
115
            post = kwargs.pop('post')
...
...
154
            but the notification still gets sent if there is an error
157
            but the notification still gets sent if there is an error
155
            '''
158
            '''
156
            log.debug('Error rendering notification template %s: %s' % (artifact.type_s, e))
159
            log.debug('Error rendering notification template %s: %s' % (artifact.type_s, e))
157
160
158
        assert d['reply_to_address'] is not None
161
        assert d['reply_to_address'] is not None
162
        project = Project.query.get(_id=d.get('project_id', c.project._id))
163
        if project.notifications_disabled:
164
            log.info('Notifications disabled for project %s, not sending %s(%r)',
165
                     project.shortname, topic, artifact)
166
            return None
159
        n = cls(ref_id=artifact.index_id(),
167
        n = cls(ref_id=artifact.index_id(),
160
                topic=topic,
168
                topic=topic,
161
                link=kwargs.pop('link', artifact.url()),
169
                link=kwargs.pop('link', artifact.url()),
162
                **d)
170
                **d)
163
        return n
171
        return n