Switch to unified view

a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
...
...
15
15
16
Notifications are also available for use in feeds
16
Notifications are also available for use in feeds
17
'''
17
'''
18
18
19
import logging
19
import logging
20
from bson import ObjectId
20
from datetime import datetime, timedelta
21
from datetime import datetime, timedelta
21
from collections import defaultdict
22
from collections import defaultdict
22
from webhelpers import feedgenerator as FG
23
from webhelpers import feedgenerator as FG
23
24
24
from pylons import c, g
25
from pylons import c, g
...
...
29
from ming import schema as S
30
from ming import schema as S
30
from ming.orm import FieldProperty, ForeignIdProperty, RelationProperty, session
31
from ming.orm import FieldProperty, ForeignIdProperty, RelationProperty, session
31
from ming.orm.declarative import MappedClass
32
from ming.orm.declarative import MappedClass
32
33
33
from allura.lib import helpers as h
34
from allura.lib import helpers as h
35
from allura.lib import security
34
import allura.tasks.mail_tasks
36
import allura.tasks.mail_tasks
35
37
36
from .session import main_orm_session, project_orm_session
38
from .session import main_orm_session, project_orm_session
37
from .auth import User
39
from .auth import User
38
40
...
...
205
        return template.render(dict(
207
        return template.render(dict(
206
            notification=self,
208
            notification=self,
207
            prefix=config.get('forgemail.url', 'https://sourceforge.net')))
209
            prefix=config.get('forgemail.url', 'https://sourceforge.net')))
208
210
209
    def send_direct(self, user_id):
211
    def send_direct(self, user_id):
212
        user = User.query.get(_id=ObjectId(user_id))
213
        artifact = self.ref.artifact
214
        # Don't send if user doesn't have read perms to the artifact
215
        if user and artifact and \
216
                not security.has_access(artifact, 'read', user)():
217
            log.debug("Skipping notification - User %s doesn't have read "
218
                      "access to artifact %s" % (user_id, str(self.ref_id)))
219
            return
210
        allura.tasks.mail_tasks.sendmail.post(
220
        allura.tasks.mail_tasks.sendmail.post(
211
            destinations=[str(user_id)],
221
            destinations=[str(user_id)],
212
            fromaddr=self.from_address,
222
            fromaddr=self.from_address,
213
            reply_to=self.reply_to_address,
223
            reply_to=self.reply_to_address,
214
            subject=self.subject,
224
            subject=self.subject,
...
...
218
228
219
    @classmethod
229
    @classmethod
220
    def send_digest(self, user_id, from_address, subject, notifications,
230
    def send_digest(self, user_id, from_address, subject, notifications,
221
                    reply_to_address=None):
231
                    reply_to_address=None):
222
        if not notifications: return
232
        if not notifications: return
233
        # Filter out notifications for which the user doesn't have read
234
        # permissions to the artifact.
235
        user = User.query.get(_id=ObjectId(user_id))
236
        artifact = self.ref.artifact
237
        def perm_check(notification):
238
            return not (user and artifact) or \
239
                    security.has_access(artifact, 'read', user)()
240
        notifications = filter(perm_check, notifications)
241
223
        if reply_to_address is None:
242
        if reply_to_address is None:
224
            reply_to_address = from_address
243
            reply_to_address = from_address
225
        text = [ 'Digest of %s' % subject ]
244
        text = [ 'Digest of %s' % subject ]
226
        for n in notifications:
245
        for n in notifications:
227
            text.append('From: %s' % n.from_address)
246
            text.append('From: %s' % n.from_address)