allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [38/50] git commit: [#6392] ticket:432 Unblock multiple users at once and validation
Date Thu, 26 Sep 2013 18:29:56 GMT
[#6392] ticket:432 Unblock multiple users at once and validation


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

Branch: refs/heads/tv/6612
Commit: c85fad83ea82c99d37bd2a12de0852cc49c8ccef
Parents: 12420f5
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Sep 11 16:57:21 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Sep 24 17:36:24 2013 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                         | 35 ++++++++++++++++-------
 Allura/allura/tests/functional/test_admin.py | 10 +++++++
 2 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c85fad83/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index a887375..a9a8816 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -20,11 +20,13 @@ from urllib import basejoin
 from cStringIO import StringIO
 from collections import defaultdict
 
-from tg import expose, redirect, flash
+from tg import expose, redirect, flash, validate
 from tg.decorators import without_trailing_slash
 from pylons import request, app_globals as g, tmpl_context as c
 from paste.deploy.converters import asbool, asint
 from bson import ObjectId
+from bson.errors import InvalidId
+from formencode import validators as V
 
 from ming.orm import session, state
 from ming.utils import LazyProperty
@@ -585,24 +587,35 @@ class DefaultAdminController(BaseController):
 
     @expose()
     def block_user(self, username, perm, reason=None):
+        if not username or not perm:
+            redirect(request.referer)
         user = model.User.by_username(username)
         if not user:
             flash('User "%s" not found' % username, 'error')
-            return redirect(request.referer)
-
+            redirect(request.referer)
         ace = model.ACE.deny(user.project_role()._id, perm, reason)
         if not model.ACL.contains(ace, self.app.acl):
             self.app.acl.append(ace)
-        return redirect(request.referer)
+        redirect(request.referer)
 
+    @validate(dict(user_id=V.Set(),
+                   perm=V.UnicodeString()))
     @expose()
-    def unblock_user(self, user_id, perm):
-        user = model.User.query.get(_id=ObjectId(user_id))
-        ace = model.ACE.deny(user.project_role()._id, perm)
-        ace = model.ACL.contains(ace, self.app.acl)
-        if ace:
-            self.app.acl.remove(ace)
-        return redirect(request.referer)
+    def unblock_user(self, user_id=None, perm=None):
+        try:
+            user_id = map(ObjectId, user_id)
+        except InvalidId:
+            user_id = []
+        users = model.User.query.find({'_id': {'$in': user_id}}).all()
+        if not users:
+            flash('Select user to unblock', 'error')
+            redirect(request.referer)
+        for user in users:
+            ace = model.ACE.deny(user.project_role()._id, perm)
+            ace = model.ACL.contains(ace, self.app.acl)
+            if ace:
+                self.app.acl.remove(ace)
+        redirect(request.referer)
 
     @expose('jinja:allura:templates/app_admin_permissions.html')
     @without_trailing_slash

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c85fad83/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 556eade..a0378e1 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -167,6 +167,16 @@ class TestProjectAdmin(TestController):
         assert "uninstall tool test-tool" in r.body, r.body
 
     @td.with_wiki
+    def test_block_user_empty_data(self):
+        # shouldn't fail
+        self.app.post('/admin/wiki/block_user', params={'username': '', 'perm': '', 'reason':
''})
+
+    @td.with_wiki
+    def test_unblock_user_empty_data(self):
+        # shouldn't fail
+        self.app.post('/admin/wiki/unblock_user', params={'user_id': '', 'perm': ''})
+
+    @td.with_wiki
     def test_block_user(self):
         r = self.app.get('/admin/wiki/permissions')
         assert '<a href="#" class="block-user">' in r


Mime
View raw message