|
a/Allura/allura/model/discuss.py |
|
b/Allura/allura/model/discuss.py |
|
... |
|
... |
139 |
def attachment_class(cls):
|
139 |
def attachment_class(cls):
|
140 |
return DiscussionAttachment
|
140 |
return DiscussionAttachment
|
141 |
|
141 |
|
142 |
@property
|
142 |
@property
|
143 |
def artifact(self):
|
143 |
def artifact(self):
|
144 |
aref = ArtifactReference(self.artifact_reference)
|
|
|
145 |
if aref is None: return self.discussion
|
144 |
if self.ref is None: return self.discussion
|
146 |
return aref.artifact
|
145 |
return self.ref.artifact
|
147 |
|
146 |
|
148 |
# Use wisely - there's .num_replies also
|
147 |
# Use wisely - there's .num_replies also
|
149 |
@property
|
148 |
@property
|
150 |
def post_count(self):
|
149 |
def post_count(self):
|
151 |
return Post.query.find(dict(
|
150 |
return Post.query.find(dict(
|
152 |
discussion_id=self.discussion_id,
|
151 |
discussion_id=self.discussion_id,
|
153 |
thread_id=self._id)).count()
|
152 |
thread_id=self._id)).count()
|
154 |
|
153 |
|
155 |
def primary(self, primary_class=None):
|
154 |
def primary(self):
|
156 |
result = primary_class.query.get(_id=self.artifact_reference.artifact_id)
|
|
|
157 |
if result is None: return self
|
155 |
if self.ref is None: return self
|
158 |
return result
|
156 |
return self.ref.artifact
|
159 |
|
157 |
|
160 |
def add_post(self, **kw):
|
158 |
def add_post(self, **kw):
|
161 |
"""Helper function to avoid code duplication."""
|
159 |
"""Helper function to avoid code duplication."""
|
162 |
p = self.post(**kw)
|
160 |
p = self.post(**kw)
|
163 |
p.commit()
|
161 |
p.commit()
|
|
... |
|
... |
167 |
Feed.post(self, title=p.subject, description=p.text)
|
165 |
Feed.post(self, title=p.subject, description=p.text)
|
168 |
return p
|
166 |
return p
|
169 |
|
167 |
|
170 |
def post(self, text, message_id=None, parent_id=None, timestamp=None, **kw):
|
168 |
def post(self, text, message_id=None, parent_id=None, timestamp=None, **kw):
|
171 |
require(has_artifact_access('post', self))
|
169 |
require(has_artifact_access('post', self))
|
172 |
if self.artifact_reference.artifact_id is not None:
|
170 |
if self.ref_id and self.artifact:
|
173 |
if self.artifact:
|
|
|
174 |
self.artifact.subscribe()
|
171 |
self.artifact.subscribe()
|
175 |
if message_id is None: message_id = h.gen_message_id()
|
172 |
if message_id is None: message_id = h.gen_message_id()
|
176 |
parent = parent_id and self.post_class().query.get(_id=parent_id)
|
173 |
parent = parent_id and self.post_class().query.get(_id=parent_id)
|
177 |
slug, full_slug = self.post_class().make_slugs(parent, timestamp)
|
174 |
slug, full_slug = self.post_class().make_slugs(parent, timestamp)
|
178 |
kwargs = dict(
|
175 |
kwargs = dict(
|
179 |
discussion_id=self.discussion_id,
|
176 |
discussion_id=self.discussion_id,
|
|
... |
|
... |
420 |
self.commit()
|
417 |
self.commit()
|
421 |
author = self.author()
|
418 |
author = self.author()
|
422 |
if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
|
419 |
if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
|
423 |
and author._id != None):
|
420 |
and author._id != None):
|
424 |
c.app.config.grant_permission('unmoderated_post', author)
|
421 |
c.app.config.grant_permission('unmoderated_post', author)
|
425 |
g.post_event('discussion.new_post', thd._id, self._id)
|
422 |
g.post_event('discussion.new_post', self.thread_id, self._id)
|
426 |
artifact = self.thread.artifact or self.thread
|
423 |
artifact = self.thread.artifact or self.thread
|
427 |
Notification.post(artifact, 'message', post=self)
|
424 |
Notification.post(artifact, 'message', post=self)
|
428 |
session(self).flush()
|
425 |
session(self).flush()
|
429 |
self.thread.update_stats()
|
426 |
self.thread.update_stats()
|
430 |
self.discussion.update_stats()
|
427 |
self.discussion.update_stats()
|