You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2018/07/06 20:16:43 UTC

allura git commit: [#8213] consolidate nearly-identical logic for top-level and nested replies. Makes tickets mod_date update for both types of comments now

Repository: allura
Updated Branches:
  refs/heads/db/8213 [created] 2a34b5de7


[#8213] consolidate nearly-identical logic for top-level and nested replies.  Makes tickets mod_date update for both types of comments now


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2a34b5de
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2a34b5de
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2a34b5de

Branch: refs/heads/db/8213
Commit: 2a34b5de72952643cee9c7a3919c6e1cb27842b1
Parents: a1181f2
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Jul 6 15:56:25 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Jul 6 16:09:36 2018 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py | 53 +++++++++++++++++--------------
 1 file changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2a34b5de/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index b91e213..bd561f7 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -211,23 +211,10 @@ class ThreadController(BaseController, FeedController):
     @validate(pass_validator, error_handler=error_handler)
     @utils.AntiSpam.validate('Spambot protection engaged')
     def post(self, **kw):
-        require_access(self.thread, 'post')
-        self.rate_limit(M.Post, "Comment", redir=request.referrer)
-        if self.thread.ref:
-            require_access(self.thread.ref.artifact, 'post')
-        kw = self.W.edit_post.to_python(kw, None)
-        if not kw['text']:
-            flash('Your post was not saved. You must provide content.',
-                  'error')
-            redirect(request.referer)
-
-        file_info = kw.get('file_info', None)
-        p = self.thread.add_post(**kw)
-        p.add_multiple_attachments(file_info)
-        if self.thread.artifact:
-            self.thread.artifact.mod_date = datetime.utcnow()
-        flash('Message posted')
-        redirect(request.referer)
+        handle_post_or_reply(thread=self.thread,
+                             edit_widget=self.W.edit_post,
+                             rate_limit=self.rate_limit,
+                             kw=kw)
 
     @expose()
     @require_post()
@@ -258,6 +245,25 @@ class ThreadController(BaseController, FeedController):
             self.thread.url())
 
 
+def handle_post_or_reply(thread, edit_widget, rate_limit, kw, parent_post_id=None):
+    require_access(thread, 'post')
+    rate_limit(M.Post, "Comment", redir=request.referrer)
+    if thread.ref:
+        require_access(thread.ref.artifact, 'post')
+    kw = edit_widget.to_python(kw, None)
+    if not kw['text']:
+        flash('Your post was not saved. You must provide content.',
+              'error')
+        redirect(request.referer)
+    file_info = kw.get('file_info', None)
+    p = thread.add_post(parent_id=parent_post_id, **kw)
+    p.add_multiple_attachments(file_info)
+    if thread.artifact:
+        thread.artifact.mod_date = datetime.utcnow()
+    flash('Message posted')
+    redirect(request.referer)
+
+
 class PostController(BaseController):
     __metaclass__ = h.ProxiedAttrMeta
     M = h.attrproxy('_discussion_controller', 'M')
@@ -347,13 +353,12 @@ class PostController(BaseController):
     @validate(pass_validator, error_handler=error_handler)
     @utils.AntiSpam.validate('Spambot protection engaged')
     @require_post(redir='.')
-    def reply(self, file_info=None, **kw):
-        require_access(self.thread, 'post')
-        self.rate_limit(M.Post, "Comment", redir=request.referrer)
-        kw = self.W.edit_post.to_python(kw, None)
-        p = self.thread.add_post(parent_id=self.post._id, **kw)
-        p.add_multiple_attachments(file_info)
-        redirect(request.referer)
+    def reply(self, **kw):
+        handle_post_or_reply(thread=self.thread,
+                             parent_post_id=self.post._id,
+                             edit_widget=self.W.edit_post,
+                             rate_limit=self.rate_limit,
+                             kw=kw)
 
     @h.vardec
     @expose()