From 7de1fd78919927dbe08cdecf212aa93cd75904e2 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 12 Jun 2024 07:47:04 +0800 Subject: [PATCH] bad attitude users - filter by recently active --- app/admin/routes.py | 4 +- app/models.py | 5 +- app/templates/admin/users.html | 2 - app/templates/admin/users_trash.html | 85 ++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 app/templates/admin/users_trash.html diff --git a/app/admin/routes.py b/app/admin/routes.py index 614a117f..e3f5d9b2 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -533,16 +533,18 @@ def admin_users_trash(): users = users.filter(User.email.ilike(f"%{search}%")) if type == '' or type == 'bad_rep': + users = users.filter(User.last_seen > utcnow() - timedelta(days=7)) users = users.filter(User.reputation < -10) users = users.order_by(User.reputation).paginate(page=page, per_page=1000, error_out=False) elif type == 'bad_attitude': + users = users.filter(User.last_seen > utcnow() - timedelta(days=7)) users = users.filter(User.attitude < 0.0) users = users.order_by(User.attitude).paginate(page=page, per_page=1000, error_out=False) next_url = url_for('admin.admin_users_trash', page=users.next_num, search=search, local_remote=local_remote, type=type) if users.has_next else None prev_url = url_for('admin.admin_users_trash', page=users.prev_num, search=search, local_remote=local_remote, type=type) if users.has_prev and page != 1 else None - return render_template('admin/users.html', title=_('Problematic users'), next_url=next_url, prev_url=prev_url, users=users, + return render_template('admin/users_trash.html', title=_('Problematic users'), next_url=next_url, prev_url=prev_url, users=users, local_remote=local_remote, search=search, type=type, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), diff --git a/app/models.py b/app/models.py index 625beca1..59906c2e 100644 --- a/app/models.py +++ b/app/models.py @@ -808,7 +808,10 @@ class User(UserMixin, db.Model): if total_downvotes == 0: # guard against division by zero self.attitude = 1.0 else: - self.attitude = (total_upvotes - total_downvotes) / (total_upvotes + total_downvotes) + if total_upvotes + total_downvotes > 2: # Only calculate attitude if they've done 3 or more votes as anything less than this could be an outlier and not representative of their overall attitude + self.attitude = (total_upvotes - total_downvotes) / (total_upvotes + total_downvotes) + else: + self.attitude = 1.0 def subscribed(self, community_id: int) -> int: if community_id is None: diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index e34961c2..3283f80d 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -15,8 +15,6 @@ - - diff --git a/app/templates/admin/users_trash.html b/app/templates/admin/users_trash.html new file mode 100644 index 00000000..e34961c2 --- /dev/null +++ b/app/templates/admin/users_trash.html @@ -0,0 +1,85 @@ +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} +{% from 'bootstrap/form.html' import render_form %} +{% set active_child = 'admin_users' %} + +{% block app_content %} +
+
+

{{ _('Users') }}

+ {{ _('Add local user') }} +
+ + + + + + + +
+ + + + + + + + + + + + + {% for user in users.items %} + + + + + + + + + + + + + {% endfor %} +
NameLocal/RemoteSeenAttitudeRepBannedReportsIPSourceActions
+ {{ user.display_name() }}{{ 'Local' if user.is_local() else 'Remote' }}{% if request.args.get('local_remote', '') == 'local' %} + {{ moment(user.last_seen).fromNow() }} + {% else %} + {{ user.last_seen }} + {% endif %} + {{ user.attitude * 100 if user.attitude != 1 }}{{ 'R ' + str(user.reputation) if user.reputation }}{{ 'Banned'|safe if user.banned }} {{ user.reports if user.reports > 0 }} {{ user.ip_address if user.ip_address }} {{ user.referrer if user.referrer }} View local | + {% if not user.is_local() %} + View remote | + {% else %} + View remote | + {% endif %} + Edit | + Delete +
+ + + +
+
+
+ {% include 'admin/_nav.html' %} +
+
+
+{% endblock %} \ No newline at end of file