Switch to unified view

a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
...
...
6
6
7
from ming import schema
7
from ming import schema
8
from ming.orm.base import session
8
from ming.orm.base import session
9
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
9
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
10
10
11
import allura.tasks
12
from allura.lib import helpers as h
11
from allura.lib import helpers as h
12
from allura.lib import security
13
from allura.lib.security import require, has_artifact_access
13
from allura.lib.security import require_access, has_access
14
from .artifact import Artifact, VersionedArtifact, Snapshot, Message, Feed
14
from .artifact import Artifact, VersionedArtifact, Snapshot, Message, Feed
15
from .attachments import BaseAttachment
15
from .attachments import BaseAttachment
16
from .auth import User
16
from .auth import User
17
17
18
log = logging.getLogger(__name__)
18
log = logging.getLogger(__name__)
...
...
168
            self.first_post_id = p._id
168
            self.first_post_id = p._id
169
        Feed.post(self, title=p.subject, description=p.text)
169
        Feed.post(self, title=p.subject, description=p.text)
170
        return p
170
        return p
171
171
172
    def post(self, text, message_id=None, parent_id=None, timestamp=None, **kw):
172
    def post(self, text, message_id=None, parent_id=None, timestamp=None, **kw):
173
        require(has_artifact_access('post', self))
173
        require_access(self, 'post')
174
        if self.ref_id and self.artifact:
174
        if self.ref_id and self.artifact:
175
            self.artifact.subscribe()
175
            self.artifact.subscribe()
176
        if message_id is None: message_id = h.gen_message_id()
176
        if message_id is None: message_id = h.gen_message_id()
177
        parent = parent_id and self.post_class().query.get(_id=parent_id)
177
        parent = parent_id and self.post_class().query.get(_id=parent_id)
178
        slug, full_slug = self.post_class().make_slugs(parent, timestamp)
178
        slug, full_slug = self.post_class().make_slugs(parent, timestamp)
...
...
185
            text=text,
185
            text=text,
186
            status='pending')
186
            status='pending')
187
        if timestamp is not None: kwargs['timestamp'] = timestamp
187
        if timestamp is not None: kwargs['timestamp'] = timestamp
188
        if message_id is not None: kwargs['_id'] = message_id
188
        if message_id is not None: kwargs['_id'] = message_id
189
        post = self.post_class()(**kwargs)
189
        post = self.post_class()(**kwargs)
190
        if has_artifact_access('unmoderated_post')():
190
        if has_access(self, 'unmoderated_post')():
191
            log.info('Auto-approving message from %s', c.user.username)
191
            log.info('Auto-approving message from %s', c.user.username)
192
            post.approve()
192
            post.approve()
193
        return post
193
        return post
194
194
195
    def update_stats(self):
195
    def update_stats(self):
...
...
420
        if self.status == 'ok': return
420
        if self.status == 'ok': return
421
        self.status = 'ok'
421
        self.status = 'ok'
422
        if self.parent_id is None:
422
        if self.parent_id is None:
423
            thd = self.thread_class().query.get(_id=self.thread_id)
423
            thd = self.thread_class().query.get(_id=self.thread_id)
424
            g.post_event('discussion.new_thread', thd._id)
424
            g.post_event('discussion.new_thread', thd._id)
425
        self.give_access('moderate', user=self.author())
425
        author = self.author()
426
        security.simple_grant(
427
            self.acl, author.project_role()._id, 'moderate')
426
        self.commit()
428
        self.commit()
427
        author = self.author()
428
        if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
429
        if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
429
            and author._id != None):
430
            and author._id != None):
430
            c.app.config.grant_permission('unmoderated_post', author)
431
            security.simple_grant(
432
                self.acl, author.project_role()._id, 'unmoderated_post')
431
        g.post_event('discussion.new_post', self.thread_id, self._id)
433
        g.post_event('discussion.new_post', self.thread_id, self._id)
432
        artifact = self.thread.artifact or self.thread
434
        artifact = self.thread.artifact or self.thread
433
        Notification.post(artifact, 'message', post=self)
435
        Notification.post(artifact, 'message', post=self)
434
        session(self).flush()
436
        session(self).flush()
435
        self.thread.last_post_date = max(
437
        self.thread.last_post_date = max(