[odrs-web] Allow banning users from the admin panel



commit 79ebdf0023236360c32b0270c8985bb34bc39f9b
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jun 2 20:56:48 2017 +0100

    Allow banning users from the admin panel

 admin.py            |   11 +++++++++++
 database.py         |   16 ++++++++++++++++
 templates/show.html |    3 +++
 3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/admin.py b/admin.py
index 4a53c1a..fc58983 100644
--- a/admin.py
+++ b/admin.py
@@ -237,6 +237,17 @@ def modify(review_id):
     db.review_modify(review)
     return redirect(url_for('.review', review_id=review_id))
 
+@admin.route('/user_ban/<user_hash>')
+@login_required
+def user_ban(user_hash):
+    """ Change details about a review """
+    try:
+        db = ReviewsDatabase(os.environ)
+        db.user_ban(user_hash)
+    except CursorError as e:
+        return error_internal(str(e))
+    return redirect(url_for('.show_reported'))
+
 @admin.route('/unreport/<review_id>')
 @login_required
 def unreport(review_id):
diff --git a/database.py b/database.py
index 8780ce9..920cc05 100644
--- a/database.py
+++ b/database.py
@@ -406,6 +406,22 @@ class ReviewsDatabase(object):
         except mdb.Error as e:
             raise CursorError(cur, e)
 
+    def user_ban(self, user_hash):
+        """ Ban a user """
+
+        # check it exists
+        user = self.user_get_by_hash(user_hash)
+        if not user:
+            return
+
+        # update the karma value
+        try:
+            cur = self._db.cursor()
+            cur.execute("UPDATE users SET is_banned = 1 "
+                        "WHERE user_hash = %s;", (user_hash,))
+        except mdb.Error as e:
+            raise CursorError(cur, e)
+
     def reviews_get_rating_for_app_id(self, app_id, min_total=1):
         """ Gets the ratings information for the application """
         try:
diff --git a/templates/show.html b/templates/show.html
index e9bb957..1125082 100644
--- a/templates/show.html
+++ b/templates/show.html
@@ -50,6 +50,9 @@
       <a href="/admin/unreport/{{ r.review_id }}">
         <button class="inline" type="button">Unreport</button>
       </a>
+      <a href="/admin/user_ban/{{ r.user_hash }}">
+        <button class="inline" type="button">Ban User</button>
+      </a>
 {% endif %}
 {% endif %}
     </td>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]