[#6947] Skip activity creation for meta comments
Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 884f736..9d27470 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -255,7 +255,7 @@
return g.spam_checker.check(post.text, artifact=post, user=c.user)
def post(self, text, message_id=None, parent_id=None,
- timestamp=None, ignore_security=False, **kw):
+ timestamp=None, ignore_security=False, is_meta=False, **kw):
if not ignore_security:
require_access(self, 'post')
if self.ref_id and self.artifact:
@@ -271,7 +271,8 @@
thread_id=self._id,
parent_id=parent_id,
text=text,
- status='pending')
+ status='pending',
+ is_meta=is_meta)
if timestamp is not None:
kwargs['timestamp'] = timestamp
if message_id is not None:
@@ -462,6 +463,8 @@
edit_count = FieldProperty(int, if_missing=0)
spam_check_id = FieldProperty(str, if_missing='')
text_cache = FieldProperty(MarkdownCache)
+ # meta comment - system generated, describes changes to an artifact
+ is_meta = FieldProperty(bool, if_missing=False)
thread = RelationProperty(Thread)
discussion = RelationProperty(Discussion)
@@ -673,7 +676,7 @@
self.thread.update_stats()
if hasattr(artifact, 'update_stats'):
artifact.update_stats()
- if self.text:
+ if self.text and not self.is_meta:
g.director.create_activity(author, 'posted', self, target=artifact,
related_nodes=[self.app_config.project])
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 8860b3b..d6ec7e0 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -281,10 +281,7 @@
'summary': 'my ticket',
'description': 'new description',
})
- # create_activity is called twice here:
- # - once for the ticket modification
- # - once for the auto-comment that's created for the ticket diff
- assert create_activity.call_count == 2
+ assert create_activity.call_count == 1
assert create_activity.call_args[0][1] == 'modified'
def test_new_ticket(self):
@@ -672,6 +669,16 @@
assert '<span class="gd">-2</span>' in r, r.showbrowser()
assert '<span class="gi">+4</span>' in r, r.showbrowser()
+ def test_meta_comment(self):
+ self.new_ticket(summary="foo")
+ self.app.post('/bugs/1/update_ticket', {
+ 'summary': 'bar',
+ 'comment': 'user comment',
+ })
+ t = tm.Ticket.query.get(ticket_num=1)
+ assert_true(t.discussion_thread.first_post.is_meta)
+ assert_false(t.discussion_thread.last_post.is_meta)
+
def test_ticket_label_unlabel(self):
summary = 'test labeling and unlabeling a ticket'
self.new_ticket(summary=summary)
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index cb8db76..0ae0cad 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1430,7 +1430,7 @@
change_text = h.render_genshi_plaintext(
tpl_fn,
changelist=changes.get_changed())
- post = thread.add_post(text=change_text)
+ thread.add_post(text=change_text, is_meta=True)
self.ticket.commit()
if comment:
self.ticket.discussion_thread.post(text=comment)