allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [11/27] git commit: [#7657] ticket:651 Add ability for admin to enable/disable account
Date Mon, 29 Sep 2014 16:17:42 GMT
[#7657] ticket:651 Add ability for admin to enable/disable account


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

Branch: refs/heads/db/7657
Commit: 6bcbdafa5f90557322ca9cb3e2e6f47cce885d91
Parents: dfbf4f7
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 16 10:41:51 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 26 16:39:45 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py         | 14 +++++++++++
 Allura/allura/lib/plugin.py                     | 20 +++++++++++++++-
 .../templates/site_admin_user_details.html      | 25 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/6bcbdafa/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 13bbb6e..bee6c8a 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -511,6 +511,20 @@ class AdminUserDetailsController(object):
             flash('Can not add comment "%s" for user %s' % (comment, user))
         redirect(request.referer)
 
+    @expose()
+    @require_post()
+    def set_status(self, username=None, status=None):
+        user = M.User.by_username(username)
+        if not user:
+            raise HTTPNotFound()
+        if status == 'enable' and user.disabled:
+            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')
+        redirect(request.referer)
+
 
 class StatsSiteAdminExtension(SiteAdminExtension):
     controllers = {'stats': StatsController}

http://git-wip-us.apache.org/repos/asf/allura/blob/6bcbdafa/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 78aae92..1186cf6 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -179,6 +179,10 @@ class AuthenticationProvider(object):
         '''Disable user account'''
         raise NotImplementedError, 'disable_user'
 
+    def enable_user(self, user):
+        '''Enable user account'''
+        raise NotImplementedError, 'enable_user'
+
     def by_username(self, username):
         '''
         Find a user by username.
@@ -324,7 +328,18 @@ class LocalAuthenticationProvider(AuthenticationProvider):
     def disable_user(self, user):
         user.disabled = True
         session(user).flush(user)
-        h.auditlog_user('Account disabled', user=user)
+        suffix = u''
+        if user != c.user:
+            suffix = u' by %s' % c.user.username
+        h.auditlog_user(u'Account disabled' + suffix, user=user)
+
+    def enable_user(self, user):
+        user.disabled = False
+        session(user).flush(user)
+        suffix = u''
+        if user != c.user:
+            suffix = u' by %s' % c.user.username
+        h.auditlog_user(u'Account enabled' + suffix, user=user)
 
     def validate_password(self, user, password):
         return self._validate_password(user, password)
@@ -566,6 +581,9 @@ class LdapAuthenticationProvider(AuthenticationProvider):
     def disable_user(self, user):
         return LocalAuthenticationProvider(None).disable_user(user)
 
+    def enable_user(self, user):
+        return LocalAuthenticationProvider(None).enable_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/6bcbdafa/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 bfd17e7..e6eab2a 100644
--- a/Allura/allura/templates/site_admin_user_details.html
+++ b/Allura/allura/templates/site_admin_user_details.html
@@ -28,11 +28,24 @@
     <div class="grid-23">
       <fieldset>
         <legend>General</legend>
+        <div class="grid-19">
         <ul>
           <li>Username: {{ user.username }} (<a href="{{ user.url() }}">Go to
profile page</a>)</li>
           <li>Full name: {{ user.get_pref('display_name') }}</li>
           <li>Registered: {{ user.registration_date() }} ({{ h.ago(user.registration_date())
}})</li>
         </ul>
+        </div>
+
+        <div class="grid-3">
+        <form action='/nf/admin/user/set_status' method="POST">
+          <div class='grid-3'>
+            <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>
+          </div>
+          <input type='hidden' name='username' value='{{ user.username }}'>
+          {{lib.csrf_token()}}
+        </form>
+        </div>
       </fieldset>
     </div>
   {% endblock general_info %}
@@ -108,3 +121,15 @@
 }
 </style>
 {% endblock %}
+
+{% block extra_js %}
+{{ super() }}
+<script>
+$(document).ready(function() {
+  // enabled/disabled change
+  $('input[name="status"]').change(function(e) {
+    $(this).parents('form').submit();
+  });
+});
+</script>
+{% endblock %}


Mime
View raw message