[odrs-web/oscp] Delete the users reviews if they are banned
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web/oscp] Delete the users reviews if they are banned
- Date: Wed, 3 Jul 2019 13:41:56 +0000 (UTC)
commit b38344e5001960bfdc9b998c6a334dc962fcd808
Author: Richard Hughes <richard hughsie com>
Date: Wed Jul 3 13:00:00 2019 +0100
Delete the users reviews if they are banned
app_data/odrs/tests/odrs_test.py | 8 ++++++--
app_data/odrs/views_admin.py | 7 ++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/app_data/odrs/tests/odrs_test.py b/app_data/odrs/tests/odrs_test.py
index e739d4c..0474cf5 100644
--- a/app_data/odrs/tests/odrs_test.py
+++ b/app_data/odrs/tests/odrs_test.py
@@ -215,13 +215,17 @@ class OdrsTest(unittest.TestCase):
self.login()
rv = self.app.get('/admin/user_ban/{}'.format(self.user_hash), follow_redirects=True)
assert b'Banned user' in rv.data, rv.data
+ assert b'deleted 1 reviews' in rv.data, rv.data
self.logout()
+ # check review was actually deleted
+ rv = self.app.get('/1.0/reviews/api/all')
+ assert rv.data == b'[]', rv.data
+
# try to submit another review
- rv = self._review_submit()
+ rv = self._review_submit(app_id='gimp.desktop')
assert b'account has been disabled due to abuse' in rv.data, rv.data
-
def test_login_logout(self):
# test logging in and out
diff --git a/app_data/odrs/views_admin.py b/app_data/odrs/views_admin.py
index 155661d..675cb0e 100644
--- a/app_data/odrs/views_admin.py
+++ b/app_data/odrs/views_admin.py
@@ -318,8 +318,13 @@ def admin_user_ban(user_hash):
flash('No user with that user_hash')
return redirect(url_for('.odrs_index'))
user.is_banned = True
+
+ # delete any of the users reviews
+ nr_delete = len(user.reviews)
+ for review in user.reviews:
+ db.session.delete(review)
db.session.commit()
- flash('Banned user')
+ flash('Banned user and deleted {} reviews'.format(nr_delete))
return redirect(url_for('.odrs_show_reported'))
@app.route('/admin/unreport/<review_id>')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]