allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject allura git commit: [#7816] ticket:709 Manage user's pending status
Date Mon, 12 Jan 2015 15:52:22 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/7816 [created] 4c6700d52


[#7816] ticket:709 Manage user's pending status


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

Branch: refs/heads/ib/7816
Commit: 4c6700d52a17c8343a3e0f66b199bac0ca1424ac
Parents: 184ffd6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Jan 12 15:32:00 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon Jan 12 15:36:29 2015 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         |  7 +-
 Allura/allura/lib/plugin.py                     | 12 +++
 .../templates/site_admin_user_details.html      |  5 +-
 .../allura/tests/functional/test_site_admin.py  | 91 ++++++++++++++++++++
 4 files changed, 112 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4c6700d5/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 5b84267..043678a 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -521,12 +521,17 @@ class AdminUserDetailsController(object):
         user = M.User.by_username(username)
         if not user or user.is_anonymous():
             raise HTTPNotFound()
-        if status == 'enable' and user.disabled:
+        if status == 'enable' and (user.disabled or user.pending):
+            AuthenticationProvider.get(request).activate_user(user)
             AuthenticationProvider.get(request).enable_user(user)
             flash('User enabled')
         elif status == 'disable' and not user.disabled:
             AuthenticationProvider.get(request).disable_user(user)
             flash('User disabled')
+        elif status == 'pending':
+            AuthenticationProvider.get(request).deactivate_user(user)
+            AuthenticationProvider.get(request).enable_user(user)
+            flash('Set user status to pending')
         redirect(request.referer)
 
     @expose()

http://git-wip-us.apache.org/repos/asf/allura/blob/4c6700d5/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index e761ef3..5cf1905 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -197,6 +197,10 @@ class AuthenticationProvider(object):
         '''Activate user after registration'''
         raise NotImplementedError, 'activate_user'
 
+    def deactivate_user(self, user):
+        '''Deactivate user (== registation not confirmed)'''
+        raise NotImplementedError, 'deactivate_user'
+
     def by_username(self, username):
         '''
         Find a user by username.
@@ -366,6 +370,11 @@ class LocalAuthenticationProvider(AuthenticationProvider):
         session(user).flush(user)
         h.auditlog_user('Account activated', user=user)
 
+    def deactivate_user(self, user):
+        user.pending = True
+        session(user).flush(user)
+        h.auditlog_user('Account deactivated', user=user)
+
     def validate_password(self, user, password):
         return self._validate_password(user, password)
 
@@ -624,6 +633,9 @@ class LdapAuthenticationProvider(AuthenticationProvider):
     def activate_user(self, user):
         return LocalAuthenticationProvider(None).activate_user(user)
 
+    def deactivate_user(self, user):
+        return LocalAuthenticationProvider(None).deactivate_user(user)
+
     def get_last_password_updated(self, user):
         return LocalAuthenticationProvider(None).get_last_password_updated(user)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/4c6700d5/Allura/allura/templates/site_admin_user_details.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_user_details.html b/Allura/allura/templates/site_admin_user_details.html
index 8f18d7e..f5a8d2d 100644
--- a/Allura/allura/templates/site_admin_user_details.html
+++ b/Allura/allura/templates/site_admin_user_details.html
@@ -42,8 +42,9 @@
         <div class="grid-6">
         <form action='/nf/admin/user/set_status' method="POST">
           <div class='grid-6'>
-            <label><input type="radio" name="status" value="enable"{% if not user.disabled
%} checked="checked"{% endif %}>Enabled</label><br>
-            <label><input type="radio" name="status" value="disable"{% if user.disabled
%} checked="checked"{% endif %}>Disabled</label>
+            <label><input type="radio" name="status" value="enable"{% if not user.disabled
and not user.pending %} checked="checked"{% endif %}>Enabled</label><br>
+            <label><input type="radio" name="status" value="disable"{% if user.disabled
%} checked="checked"{% endif %}>Disabled</label><br>
+            <label><input type="radio" name="status" value="pending"{% if user.pending
and not user.disabled %} checked="checked"{% endif %}>Pending</label>
           </div>
           <input type='hidden' name='username' value='{{ user.username }}'>
           {{lib.csrf_token()}}

http://git-wip-us.apache.org/repos/asf/allura/blob/4c6700d5/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index 197d058..6c327c7 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -347,7 +347,9 @@ class TestUserDetails(TestController):
         assert_in(u'Comment by test-admin: I was hêre!', r)
 
     def test_disable_user(self):
+        # user was not pending
         assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
         r = self.app.get('/nf/admin/user/test-user-3')
         form = r.forms[0]
         assert_equal(form['username'].value, 'test-user-3')
@@ -356,12 +358,66 @@ class TestUserDetails(TestController):
         r = form.submit()
         assert_in(u'User disabled', self.webflash(r))
         assert_equal(M.User.by_username('test-user-3').disabled, True)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+
+        # user was pending
+        user = M.User.by_username('test-user-3')
+        user.disabled = False
+        user.pending = True
+        ThreadLocalORMSession.flush_all()
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
+        r = self.app.get('/nf/admin/user/test-user-3')
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user-3')
+        assert_equal(form['status'].value, 'pending')
+        form['status'].value = 'disable'
+        r = form.submit()
+        assert_in(u'User disabled', self.webflash(r))
+        assert_equal(M.User.by_username('test-user-3').disabled, True)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
 
     def test_enable_user(self):
+        # user was not pending
+        user = M.User.by_username('test-user-3')
+        user.disabled = True
+        ThreadLocalORMSession.flush_all()
+        assert_equal(M.User.by_username('test-user-3').disabled, True)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+        r = self.app.get('/nf/admin/user/test-user-3')
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user-3')
+        assert_equal(form['status'].value, 'disable')
+        form['status'].value = 'enable'
+        r = form.submit()
+        assert_in(u'User enabled', self.webflash(r))
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+
+        # user was pending
+        user = M.User.by_username('test-user-3')
+        user.disabled = False
+        user.pending = True
+        ThreadLocalORMSession.flush_all()
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
+        r = self.app.get('/nf/admin/user/test-user-3')
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user-3')
+        assert_equal(form['status'].value, 'pending')
+        form['status'].value = 'enable'
+        r = form.submit()
+        assert_in(u'User enabled', self.webflash(r))
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+
+        # user was pending and disabled
         user = M.User.by_username('test-user-3')
         user.disabled = True
+        user.pending = True
         ThreadLocalORMSession.flush_all()
         assert_equal(M.User.by_username('test-user-3').disabled, True)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
         r = self.app.get('/nf/admin/user/test-user-3')
         form = r.forms[0]
         assert_equal(form['username'].value, 'test-user-3')
@@ -370,6 +426,41 @@ class TestUserDetails(TestController):
         r = form.submit()
         assert_in(u'User enabled', self.webflash(r))
         assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+
+    def test_set_pending(self):
+        # user was disabled
+        user = M.User.by_username('test-user-3')
+        user.disabled = True
+        ThreadLocalORMSession.flush_all()
+        assert_equal(M.User.by_username('test-user-3').disabled, True)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+        r = self.app.get('/nf/admin/user/test-user-3')
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user-3')
+        assert_equal(form['status'].value, 'disable')
+        form['status'].value = 'pending'
+        r = form.submit()
+        assert_in(u'Set user status to pending', self.webflash(r))
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
+
+        # user was enabled
+        user = M.User.by_username('test-user-3')
+        user.pending = False
+        user.disabled = False
+        ThreadLocalORMSession.flush_all()
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, False)
+        r = self.app.get('/nf/admin/user/test-user-3')
+        form = r.forms[0]
+        assert_equal(form['username'].value, 'test-user-3')
+        assert_equal(form['status'].value, 'enable')
+        form['status'].value = 'pending'
+        r = form.submit()
+        assert_in(u'Set user status to pending', self.webflash(r))
+        assert_equal(M.User.by_username('test-user-3').disabled, False)
+        assert_equal(M.User.by_username('test-user-3').pending, True)
 
     def test_emails(self):
         # add test@example.com


Mime
View raw message