incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#6539] use _id (indexed) instead of full_slug as key when approving posts
Date Tue, 03 Sep 2013 20:43:27 GMT
Updated Branches:
  refs/heads/master faa5a9e8a -> 7a51d42e7


[#6539] use _id (indexed) instead of full_slug as key when approving posts

In 93768a36 test_post_count was already rendered irrelevant, so removing
altogether.  Fixed up test_threads_with_zero_posts as best we can for now


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

Branch: refs/heads/master
Commit: 7a51d42e7e0f03702ae3e80fdc97da91372a6d27
Parents: faa5a9e
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Tue Sep 3 20:16:37 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Tue Sep 3 20:16:37 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py            |  5 +-
 .../templates/widgets/moderate_posts.html       |  2 +-
 .../test_discussion_moderation_controller.py    | 18 ++---
 .../tests/functional/test_forum.py              | 73 +++++++++-----------
 4 files changed, 48 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7a51d42e/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 9f745a3..74879ad 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -429,7 +429,10 @@ class ModerationController(BaseController):
     def save_moderation(self, post=[], delete=None, spam=None, approve=None, **kw):
         for p in post:
             if 'checked' in p:
-                posted = self.PostModel.query.get(full_slug=p['full_slug'])
+                posted = self.PostModel.query.get(
+                    _id=p['_id'],
+                    discussion_id=self.discussion._id,  # make sure nobody hacks the HTML
form to moderate other posts
+                )
                 if posted:
                     if delete:
                         posted.delete()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7a51d42e/Allura/allura/templates/widgets/moderate_posts.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/moderate_posts.html b/Allura/allura/templates/widgets/moderate_posts.html
index 2babc7f..25294a3 100644
--- a/Allura/allura/templates/widgets/moderate_posts.html
+++ b/Allura/allura/templates/widgets/moderate_posts.html
@@ -43,7 +43,7 @@
       {% for post in value.posts %}
         <tr>
           <td>
-            <input type="hidden" name="post-{{loop.index0}}.full_slug" value="{{post.full_slug}}"/>
+            <input type="hidden" name="post-{{loop.index0}}._id" value="{{post._id}}"/>
             <input type="checkbox" name="post-{{loop.index0}}.checked"/>
           </td>
           <td>{{h.ago(post.timestamp)}}</td>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7a51d42e/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
index ccf1fc2..520f691 100644
--- a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
+++ b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from nose.tools import assert_equal
 from mock import Mock
 from ming.orm import ThreadLocalORMSession
 
@@ -33,27 +34,29 @@ class TestWhenModerating(WithDatabase):
 
     def setUp(self):
         super(TestWhenModerating, self).setUp()
-        create_post('mypost')
-        discussion_controller = Mock()
+        post = create_post('mypost')
+        discussion_controller = Mock(
+            discussion = Mock(_id=post.discussion_id),
+        )
         self.controller = ModerationController(discussion_controller)
 
     def test_that_it_can_approve(self):
         mod_date = self.get_post().mod_date
         self.moderate_post(approve=True)
         post = self.get_post()
-        assert post.status == 'ok'
-        assert post.thread.last_post_date.strftime("%Y-%m-%d %H:%M:%S") == mod_date.strftime("%Y-%m-%d
%H:%M:%S")
+        assert_equal(post.status, 'ok')
+        assert_equal(post.thread.last_post_date.strftime("%Y-%m-%d %H:%M:%S"), mod_date.strftime("%Y-%m-%d
%H:%M:%S"))
 
     def test_that_it_can_mark_as_spam(self):
         self.moderate_post(spam=True)
-        assert self.get_post().status == 'spam'
+        assert_equal(self.get_post().status, 'spam')
 
     def test_that_it_can_be_deleted(self):
         self.moderate_post(delete=True)
-        assert self.get_post() is None
+        assert_equal(self.get_post(), None)
 
     def moderate_post(self, **kwargs):
-        self.controller.save_moderation(post=[dict(checked=True, full_slug=self.get_post().full_slug)],
+        self.controller.save_moderation(post=[dict(checked=True, _id=self.get_post()._id)],
                                  **kwargs)
         ThreadLocalORMSession.flush_all()
 
@@ -95,4 +98,3 @@ def show_moderation_index(discussion, **kwargs_for_controller):
     controller = ModerationController(discussion_controller)
     template_variables = controller.index(**kwargs_for_controller)
     return template_variables
-

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7a51d42e/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 c319263..89efa7c 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -27,6 +27,7 @@ from email.mime.multipart import MIMEMultipart
 import pkg_resources
 from pylons import tmpl_context as c, app_globals as g
 from nose.tools import assert_equal, assert_in
+from ming.orm import ThreadLocalORMSession
 
 from allura import model as M
 from allura.tasks import mail_tasks
@@ -326,32 +327,16 @@ class TestForum(TestController):
         r = self.app.get('/discussion/testforum/')
         r = self.app.get('/discussion/testforum/childforum/')
 
-    def test_post_count(self):
-        # Make sure post counts don't get skewed during moderation
-        r = self.app.get('/discussion/create_topic/')
-        f = r.html.find('form',{'action':'/p/test/discussion/save_new_topic'})
-        params = dict()
-        inputs = f.findAll('input')
-        for field in inputs:
-            if field.has_key('name'):
-                params[field['name']] = field.has_key('value') and field['value'] or ''
-        params[f.find('textarea')['name']] = '1st post in Test Post Count thread'
-        params[f.find('select')['name']] = 'testforum'
-        params[f.find('input',{'style':'width: 90%'})['name']] = 'Test Post Count'
-        r = self.app.post('/discussion/save_new_topic', params=params)
-        for i in range(2):
-            r = self.app.get('/discussion/testforum/moderate')
-            slug = r.html.find('input', {'name': 'post-0.full_slug'})
-            if slug is None: slug = '' #FIXME this makes the test keep passing, but clearly
something isn't found
-            r = self.app.post('/discussion/testforum/moderate/save_moderation', params={
-                    'post-0.full_slug': slug,
-                    'post-0.checked': 'on',
-                    'approve': 'Approve Marked'})
-
     def test_threads_with_zero_posts(self):
         # Make sure that threads with zero posts (b/c all posts have been
         # deleted or marked as spam) don't show in the UI.
-        def _post():
+
+        # FIXME: This only works for posts that were initially pending, not
+        # those deleted or spammed later.
+
+        self._set_anon_allowed()
+
+        def _post_pending():
             r = self.app.get('/discussion/create_topic/')
             f = r.html.find('form',{'action':'/p/test/discussion/save_new_topic'})
             params = dict()
@@ -362,30 +347,35 @@ class TestForum(TestController):
             params[f.find('textarea')['name']] = '1st post in Zero Posts thread'
             params[f.find('select')['name']] = 'testforum'
             params[f.find('input',{'style':'width: 90%'})['name']] = 'Test Zero Posts'
-            r = self.app.post('/discussion/save_new_topic', params=params)
+            r = self.app.post('/discussion/save_new_topic', params=params,
+                              extra_environ=dict(username='*anonymous'),
+                              status=302)
+            assert r.location.startswith('http://localhost/p/test/discussion/testforum/thread/'),
r.location
+
         def _check():
-            r = self.app.get('/discussion/')
-            assert 'Test Zero Posts' in r
+            # FIXME fix [#5907]
+            #r = self.app.get('/discussion/')
+            #assert 'Test Zero Posts' not in r
             r = self.app.get('/discussion/testforum/')
-            assert 'Test Zero Posts' in r
+            assert 'Test Zero Posts' not in r
+
         # test posts marked as spam
-        _post()
-        r = self.app.get('/discussion/testforum/moderate')
-        slug = r.html.find('input', {'name': 'post-0.full_slug'})
-        if slug is None: slug = '' #FIXME this makes the test keep passing, but clearly something
isn't found
+        _post_pending()
+        r = self.app.get('/discussion/testforum/moderate?status=pending')
+        post_id = r.html.find('input', {'name': 'post-0._id'})['value']
         r = self.app.post('/discussion/testforum/moderate/save_moderation', params={
-                'post-0.full_slug': slug,
+                'post-0._id': post_id,
                 'post-0.checked': 'on',
                 'spam': 'Spam Marked'})
         _check()
+
         # test posts deleted
-        _post()
-        r = self.app.get('/discussion/testforum/moderate')
-        slug = r.html.find('input', {'name': 'post-0.full_slug'})
-        if slug is None: slug = '' #FIXME this makes the test keep passing, but clearly something
isn't found
+        _post_pending()
+        r = self.app.get('/discussion/testforum/moderate?status=pending')
+        post_id = r.html.find('input', {'name': 'post-0._id'})['value']
         r = self.app.post('/discussion/testforum/moderate/save_'
                           'moderation', params={
-                'post-0.full_slug': slug,
+                'post-0._id': post_id,
                 'post-0.checked': 'on',
                 'delete': 'Delete Marked'})
         _check()
@@ -428,9 +418,7 @@ class TestForum(TestController):
         n = M.Notification.query.find(dict(subject="[test:discussion] this is <h2>
o'clock")).first()
         assert_in('---\n\n[this is &lt;h2&gt; o&#39;clock]', n.text)
 
-    @mock.patch('allura.model.discuss.g.spam_checker')
-    def test_anonymous_post(self, spam_checker):
-        spam_checker.check.return_value = True
+    def _set_anon_allowed(self):
         r = self.app.get('/admin/discussion/permissions')
         select = r.html.find('select', {'name': 'card-3.new'})
         opt_anon = select.find(text='*anonymous').parent
@@ -444,6 +432,11 @@ class TestForum(TestController):
                 'card-3.value': opt_auth['value'],
                 'card-3.new': opt_anon['value'],
                 'card-3.id': 'post'})
+
+    @mock.patch('allura.model.discuss.g.spam_checker')
+    def test_anonymous_post(self, spam_checker):
+        spam_checker.check.return_value = True
+        self._set_anon_allowed()
         r = self.app.get('/discussion/create_topic/')
         f = r.html.find('form',{'action':'/p/test/discussion/save_new_topic'})
         params = dict()


Mime
View raw message