Commits

Anonymous committed 24227aa

Added ban links to the user profile, added simple unban page.

  • Participants
  • Parent commits e74f7d9

Comments (0)

Files changed (3)

solace/templates/users/profile.html

         <br><small>{{ _('Ordered by activity, most active first') }}</small>
         {%- endif %}
     {%- endif %}
+    {% if request.is_logged_in and request.user.is_admin %}
+    <dt>{{ _('Administrative tasks') }}
+    <dd>
+      {% if user.is_banned %}
+      <a href="{{ url_for('admin.unban_user', user=user.username) }}">{{ _('lift the ban') }}</a>
+      {% else %}
+      <a href="{{ url_for('admin.ban_user', user=user.username) }}">{{ _('ban this user') }}</a>
+      {% endif %}
+    {% endif %}
   </dl>
+  {% if user.is_banned %}
+  <p><strong>{{ _('This user was banned') }}</strong>
+  {% endif %}
   <h2>{{ _('Reputation') }}</h2>
   <p class="reputation">
     {{ user.reputation|numberformat }}
     Rule('/admin/') > 'admin.overview',
     Rule('/admin/status') > 'admin.status',
     Rule('/admin/bans') > 'admin.bans',
-    Rule('/admin/unban/<user>') > 'admin.unban',
+    Rule('/admin/ban/<user>') > 'admin.ban_user',
+    Rule('/admin/unban/<user>') > 'admin.unban_user',
 
     # AJAX
     Rule('/_set_language/<locale>') > 'core.set_language',

solace/views/admin.py

 from solace.settings import describe_settings
 from solace.templating import render_template
 from solace.utils.pagination import Pagination
-from solace.utils.admin import ban_user, unban_user
 from solace.utils.csrf import exchange_token_protected
+from solace.utils import admin as admin_utils
 
 
 @require_admin
     pagination = Pagination(request, query, request.args.get('page', type=int))
 
     if request.method == 'POST' and form.validate():
-        ban_user(form.user)
-        request.flash(_(u'The user “%s” was successfully banned.') %
+        admin_utils.ban_user(form.user)
+        request.flash(_(u'The user “%s” was successfully banned and notified.') %
                       form.user.username)
         return form.redirect('admin.bans')
 
 
 @exchange_token_protected
 @require_admin
-def unban(request, user):
+def unban_user(request, user):
     """Unbans a given user."""
     user = User.query.filter_by(username=user).first()
     if user is None:
     if not user.is_banned:
         request.flash(_(u'The user is not banned.'))
         return redirect(next)
-    unban_user(user)
-    request.flash(_(u'The user was unbanned and notified.'))
+    admin_utils.unban_user(user)
+    request.flash(_(u'The user “%s” was successfully unbanned and notified.') %
+                  user.username)
     return redirect(next)
+
+
+@exchange_token_protected
+@require_admin
+def ban_user(request, user):
+    """Bans a given user."""
+    user = User.query.filter_by(username=user).first()
+    if user is None:
+        raise NotFound()
+    next = request.next_url or url_for('admin.bans')
+    if user.is_banned:
+        request.flash(_(u'The user is already banned.'))
+        return redirect(next)
+    admin_utils.ban_user(user)
+    request.flash(_(u'The user “%s” was successfully banned and notified.') %
+                  user.username)
+    return redirect(next)