incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/4] git commit: [#284] ticket:258 added approve delete spam buttons on each unmoderated post
Date Mon, 11 Feb 2013 19:53:06 GMT
[#284] ticket:258 added approve delete spam buttons on each unmoderated post


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

Branch: refs/heads/master
Commit: 19d02336b97289c93f83ec2fb4c4ad35a45e5b6b
Parents: 627bcf5
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Wed Feb 6 14:04:57 2013 +0400
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Feb 11 19:52:19 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py               |    7 ++-
 Allura/allura/lib/widgets/discuss.py               |   34 ++++++++++++++-
 Allura/allura/templates/widgets/moderate_post.html |   12 +++++-
 Allura/allura/templates/widgets/post_widget.html   |   14 +++---
 Allura/allura/tests/functional/test_discuss.py     |   14 ++++++
 .../forgediscussion/tests/functional/test_forum.py |    6 +++
 6 files changed, 75 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index c537574..9851f4b 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -332,11 +332,12 @@ class PostController(BaseController):
         require_access(self.post.thread, 'moderate')
         if kw.pop('delete', None):
             self.post.delete()
-            self.thread.update_stats()
         elif kw.pop('spam', None):
             self.post.status = 'spam'
-            self.thread.update_stats()
-        redirect(request.referer)
+        elif kw.pop('approve', None):
+            self.post.status = 'ok'
+        self.thread.update_stats()
+        return dict(result ='success')
 
     @h.vardec
     @expose()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/Allura/allura/lib/widgets/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index d82179c..eeb75ad 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -265,10 +265,42 @@ class Post(HierWidget):
             $('div.discussion-post').each(function () {
                 var post = this;
                 $('.submit', post).button();
-                $('.flag_post, .delete_post', post).click(function (ele) {
+                $('.flag_post', post).click(function (ele) {
                     this.parentNode.submit();
                     return false;
                 });
+
+                if($('.moderate_post', post)){
+                    $('.moderate_post', post).click(function(e){
+                        e.preventDefault();
+                        var mod = $(this).text();
+                        var id_post = $(post).attr('id');
+                        var session_id = $('input[name=_session_id]').val();
+                        $.ajax({
+                            type: 'POST',
+                            url: this.parentNode.action,
+                            data: jQuery(this.parentNode).serialize(),
+                            success: function() {
+                                if (mod == 'Delete'){
+                                    $(post).remove();
+                                }
+                                else if (mod == 'Approve'){
+                                    $('a.reply_post', post).show();
+                                    $('a.shortlink', post).show();
+                                    $('a.edit_post', post).show();
+                                    $('div.moderate', post).removeClass('moderate');
+                                    $('form.moderate_spam', post).hide();
+                                    $('form.moderate_approve', post).hide();
+                                }
+                                else if (mod == 'Spam'){
+                                    $(post).remove();
+                                }
+                            }
+                        });
+                    });
+                };
+
+
                 if($('a.edit_post', post)){
                     $('a.edit_post', post).click(function (ele) {
                         $('.display_post', post).hide();

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/Allura/allura/templates/widgets/moderate_post.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/moderate_post.html b/Allura/allura/templates/widgets/moderate_post.html
index 27099c7..897b60a 100644
--- a/Allura/allura/templates/widgets/moderate_post.html
+++ b/Allura/allura/templates/widgets/moderate_post.html
@@ -1,5 +1,15 @@
 <form method="POST" action="{{action}}">
     <input type="hidden" name="delete" value="True"/>
-    <a href="" class="delete_post little_link"><span>Delete</span></a>
+    <a href="" class="moderate_post little_link"><span>Delete</span></a>
+</form>
+<br/>
+<form method="POST" class="moderate_approve" action="{{action}}" {%if status != 'pending'%}
style="display:none"{%endif%}>
+    <input type="hidden" name="approve" value="True"/>
+    <a href="" class="moderate_post little_link"><span>Approve</span></a>
+</form>
+<br/>
+<form method="POST" class="moderate_spam" action="{{action}}" {%if status != 'pending'%}
style="display:none"{%endif%}>
+    <input type="hidden" name="spam" value="True"/>
+    <a href="" class="moderate_post little_link"><span>Spam</span></a>
 </form>
 <br/>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/Allura/allura/templates/widgets/post_widget.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/post_widget.html b/Allura/allura/templates/widgets/post_widget.html
index 5160a1d..27d4739 100644
--- a/Allura/allura/templates/widgets/post_widget.html
+++ b/Allura/allura/templates/widgets/post_widget.html
@@ -75,21 +75,21 @@
         {% endif %}
         </div>
         <div class="options grid-3">
-        {% if value.status == 'ok' %}
         {% if h.has_access(value.thread, 'post')() %}
-          <a href="" class="reply_post btn"><b data-icon="{{g.icons['reply'].char}}"
class="ico {{g.icons['reply'].css}}"></b>Reply</a>
+          <a href="" class="reply_post btn"{%if value.status == 'pending'%} style="display:none"{%endif%}><b
data-icon="{{g.icons['reply'].char}}" class="ico {{g.icons['reply'].css}}"></b>Reply</a>
         {% endif %}
         <div style="clear:both">
-          <a href="{{shortlink_url}}" class="little_link shortlink"><span>Link</span></a><br/>
-          {% if h.has_access(value, 'moderate')() %}
-            <a href="" class="edit_post little_link"><span>Edit</span></a><br/>
-            {{widgets.moderate_post.display(value=value, action=value.url()+'moderate')}}
+            <a href="{{shortlink_url}}" class="little_link shortlink"{%if value.status
== 'pending'%} style="display:none"{%endif%}><span>Link</span></a><br/>
+          {% if h.has_access(value, 'moderate')()%}
+            <a href="" class="edit_post little_link"{%if value.status == 'pending'%} style="display:none"{%endif%}><span>Edit</span></a><br/>
+          {% endif %}
+          {% if h.has_access(value, 'moderate')()%}
+            {{widgets.moderate_post.display(value=value, action=value.url()+'moderate', status
= value.status)}}
           {% endif %}
           {% if h.has_access(value.thread, 'post')() %}
             <a href="#" class="add_attachment little_link"><span>Attach</span></a>
           {% endif %}
         </div>
-        {% endif %}
       </div>
       <div class="shortlink_popup modal" style="display: none">
         <b data-icon="{{g.icons['close'].char}}" class="ico {{g.icons['close'].css}} close"></b>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index 2e0b64c..1e3cb13 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -94,6 +94,20 @@ class TestDiscuss(TestController):
         self.app.post(permalinks[1]+'moderate', params=dict(delete='delete'))
         self.app.post(permalinks[0]+'moderate', params=dict(spam='spam'))
 
+    def test_moderate(self):
+        r = self._make_post('Test post')
+        post_link = str(r.html.find('div', {'class': 'edit_post_form reply'}).find('form')['action'])
+        post = M.Post.query.find().first()
+        post.status = 'pending'
+        self.app.post(post_link + 'moderate', params=dict(spam='spam'))
+        post = M.Post.query.find().first()
+        assert post.status == 'spam'
+        self.app.post(post_link + 'moderate', params=dict(approve='approve'))
+        post = M.Post.query.find().first()
+        assert post.status == 'ok'
+        self.app.post(post_link + 'moderate', params=dict(delete='delete'))
+        assert M.Post.query.find().count() == 0
+
     def test_post_paging(self):
         home = self.app.get('/wiki/_discuss/')
         thread_link = [ a for a in home.html.findAll('a')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19d02336/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index e2ea957..60866e9 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -426,6 +426,12 @@ class TestForum(TestController):
         assert 'Post awaiting moderation' in r
         r = self.app.get(thread.request.url)
         assert '<div class="display_post moderate">' in r
+        assert '<a href="" class="edit_post little_link" style="display:none">' in
r
+        assert '<a href="" class="reply_post btn" style="display:none">' in r
+        assert 'class="little_link shortlink" style="display:none">' in r
+        assert 'name="delete"' in r
+        assert 'name="approve"' in r
+        assert 'name="spam"' in r
         assert 'Post content' in r
         r = self.app.get('/discussion/testforum/moderate/')
         post = FM.ForumPost.query.get(text='Post content')


Mime
View raw message