diff --git a/app/admin/routes.py b/app/admin/routes.py index 530fa333..579dc19d 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1147,60 +1147,30 @@ def admin_users(): page = request.args.get('page', 1, type=int) search = request.args.get('search', '') local_remote = request.args.get('local_remote', '') + sort_by = request.args.get('sort_by', 'last_seen DESC') + last_seen = request.args.get('last_seen', 0, type=int) + + sort_by_btn = request.args.get('sort_by_btn', '') + if sort_by_btn: + return redirect(url_for('admin.admin_users', page=page, search=search, local_remote=local_remote, sort_by=sort_by_btn, last_seen=last_seen)) users = User.query.filter_by(deleted=False) if local_remote == 'local': users = users.filter_by(ap_id=None) - if local_remote == 'remote': + elif local_remote == 'remote': users = users.filter(User.ap_id != None) if search: users = users.filter(User.email.ilike(f"%{search}%")) - users = users.order_by(User.user_name).paginate(page=page, per_page=1000, error_out=False) + if last_seen > 0: + users = users.filter(User.last_seen > utcnow() - timedelta(days=last_seen)) + users = users.order_by(text('"user".' + sort_by)) + users = users.paginate(page=page, per_page=1000, error_out=False) - next_url = url_for('admin.admin_users', page=users.next_num) if users.has_next else None - prev_url = url_for('admin.admin_users', page=users.prev_num) if users.has_prev and page != 1 else None + next_url = url_for('admin.admin_users', page=users.next_num, search=search, local_remote=local_remote, sort_by=sort_by, last_seen=last_seen) if users.has_next else None + prev_url = url_for('admin.admin_users', page=users.prev_num, search=search, local_remote=local_remote, sort_by=sort_by, last_seen=last_seen) if users.has_prev and page != 1 else None return render_template('admin/users.html', title=_('Users'), next_url=next_url, prev_url=prev_url, users=users, - local_remote=local_remote, search=search, - moderating_communities=moderating_communities(current_user.get_id()), - joined_communities=joined_communities(current_user.get_id()), - menu_topics=menu_topics(), - site=g.site - ) - - -@bp.route('/users/trash', methods=['GET']) -@login_required -@permission_required('administer all users') -def admin_users_trash(): - - page = request.args.get('page', 1, type=int) - search = request.args.get('search', '') - local_remote = request.args.get('local_remote', '') - type = request.args.get('type', 'bad_rep') - - users = User.query.filter_by(deleted=False) - if local_remote == 'local': - users = users.filter_by(ap_id=None) - if local_remote == 'remote': - users = users.filter(User.ap_id != None) - if search: - 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).filter(User.reputation < -10) - 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_trash.html', title=_('Problematic users'), next_url=next_url, prev_url=prev_url, users=users, - local_remote=local_remote, search=search, type=type, + local_remote=local_remote, search=search, sort_by=sort_by, last_seen=last_seen, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), diff --git a/app/models.py b/app/models.py index 1c8c3f26..7aae3641 100644 --- a/app/models.py +++ b/app/models.py @@ -710,6 +710,7 @@ class User(UserMixin, db.Model): cover = db.relationship('File', lazy='joined', foreign_keys=[cover_id], single_parent=True, cascade="all, delete-orphan") instance = db.relationship('Instance', lazy='joined', foreign_keys=[instance_id]) conversations = db.relationship('Conversation', lazy='dynamic', secondary=conversation_member, backref=db.backref('members', lazy='joined')) + user_notes = db.relationship('UserNote', lazy='dynamic', foreign_keys="UserNote.target_id") ap_id = db.Column(db.String(255), index=True) # e.g. username@server ap_profile_id = db.Column(db.String(255), index=True, unique=True) # e.g. https://server/u/username @@ -1022,6 +1023,7 @@ class User(UserMixin, db.Model): db.session.query(PostBookmark).filter(PostBookmark.user_id == self.id).delete() db.session.query(PostReplyBookmark).filter(PostReplyBookmark.user_id == self.id).delete() db.session.query(ModLog).filter(ModLog.user_id == self.id).delete() + db.session.query(UserNote).filter(or_(UserNote.user_id == self.id, UserNote.target_id == self.id)).delete() def purge_content(self, soft=True): files = File.query.join(Post).filter(Post.user_id == self.id).all() @@ -1077,7 +1079,14 @@ class User(UserMixin, db.Model): # returns true if the post has been read, false if not def has_read_post(self, post): return self.read_post.filter(read_posts.c.read_post_id == post.id).count() > 0 - + + @cache.memoize(timeout=500) + def get_note(self, by_user): + user_note = self.user_notes.filter(UserNote.target_id == self.id, UserNote.user_id == by_user.id).first() + if user_note: + return user_note.body + else: + return None class ActivityLog(db.Model): diff --git a/app/templates/admin/_nav.html b/app/templates/admin/_nav.html index dea6efd2..addf534b 100644 --- a/app/templates/admin/_nav.html +++ b/app/templates/admin/_nav.html @@ -6,7 +6,6 @@ {{ _('Communities') }} | {{ _('Topics') }} | {{ _('Users') }} | - {{ _('Watch') }} | {% if site.registration_mode == 'RequireApplication' %} {{ _('Registration applications') }} | {% endif %} diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index 17b0e90e..89acc5fa 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -11,44 +11,84 @@
{{ _('Name') }} | -{{ _('Seen') }} | -{{ _('Attitude') }} | -{{ _('Reputation') }} | ++ + | {{ _('Banned') }} | -{{ _('Reports') }} | -{{ _('IP and country code') }} | -{{ _('Source') }} | ++ + | ++ + | ++ + | ++ + | {{ _('Actions') }} |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{ render_username(user, add_domain=False) }} {{ user.user_name }}{% if not user.is_local() %} |
- {% if request.args.get('local_remote', '') == 'local' %} - {{ arrow.get(user.last_seen).humanize(locale=locale) }} - {% else %} - {{ user.last_seen }} - {% endif %} - | -{% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %} | -{% if user.reputation %}R {{ user.reputation | round | int }}{% endif %} | {{ 'Banned'|safe if user.banned }} {{ 'Banned posts'|safe if user.ban_posts }} {{ 'Banned comments'|safe if user.ban_comments }} | {{ user.reports if user.reports > 0 }} | -{{ user.ip_address if user.ip_address }} {{ user.ip_address_country if user.ip_address_country }} |
- {{ user.referrer if user.referrer }} | -Edit | - Delete + | {% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %} | +{% if user.reputation %}R {{ user.reputation | round | int }}{% endif %} | +{{ arrow.get(user.last_seen).humanize(locale=locale) }} | +Edit,
+ Delete,
+ + {% if user.banned %} + Ban, + {% else %} + Ban, + {% endif %} + Purge |
Name | -Seen | -Attitude | -Rep | -Banned | -Reports | -IP | -Source | -Actions | -
---|---|---|---|---|---|---|---|---|
{{ render_username(user, add_domain=False) }} - {{ user.user_name }}{% if not user.is_local() %} |
- {% if request.args.get('local_remote', '') == 'local' %} - {{ arrow.get(user.last_seen).humanize(locale=locale) }} - {% else %} - {{ user.last_seen }} - {% endif %} - | -{% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %} | -{% if user.reputation %}R {{ user.reputation | round | int }}{% endif %} | -{{ 'Banned'|safe if user.banned }} | -{{ user.reports if user.reports > 0 }} | -{{ user.ip_address if user.ip_address }} | -{{ user.referrer if user.referrer }} | -Edit | - Delete - | -
{{ _('Registration is closed. Only admins can create accounts.') }}
+{{ _('If you would like to sign up for PieFed, choose one of the other instances in our network:') }}
+ {% endif %} diff --git a/app/templates/base.html b/app/templates/base.html index a7467df1..d48d00e8 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -27,6 +27,12 @@ {% endif -%} {% endif -%} + {% if current_user.is_authenticated -%} + {% set user_note = user.get_note(current_user) %} + {% if user_note -%} + [{{ user_note | truncate(12, True) }}] + {% endif -%} + {% endif -%} {% endif -%} {% endmacro -%} @@ -217,7 +223,6 @@