From dd75c8818960faa73e393fb838efe69c74cd252b Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Fri, 27 Dec 2024 23:42:41 +0100 Subject: [PATCH 1/6] rename template --- app/admin/routes.py | 12 ++++++------ app/templates/admin/{posts.html => content.html} | 4 ++-- app/templates/base.html | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename app/templates/admin/{posts.html => content.html} (95%) diff --git a/app/admin/routes.py b/app/admin/routes.py index e4978f38..5444b0f2 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1192,20 +1192,20 @@ def admin_users(): ) -@bp.route('/content/trash', methods=['GET']) +@bp.route('/content', methods=['GET']) @login_required @permission_required('administer all users') -def admin_content_trash(): +def admin_content(): page = request.args.get('page', 1, type=int) posts = Post.query.filter(Post.posted_at > utcnow() - timedelta(days=3), Post.deleted == False, Post.down_votes > 0).order_by(Post.score) posts = posts.paginate(page=page, per_page=100, error_out=False) - next_url = url_for('admin.admin_content_trash', page=posts.next_num) if posts.has_next else None - prev_url = url_for('admin.admin_content_trash', page=posts.prev_num) if posts.has_prev and page != 1 else None + next_url = url_for('admin.admin_content', page=posts.next_num) if posts.has_next else None + prev_url = url_for('admin.admin_content', page=posts.prev_num) if posts.has_prev and page != 1 else None - return render_template('admin/posts.html', title=_('Bad posts'), next_url=next_url, prev_url=prev_url, posts=posts, + return render_template('admin/content.html', title=_('Bad posts'), next_url=next_url, prev_url=prev_url, posts=posts, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), @@ -1217,7 +1217,7 @@ def admin_content_trash(): @login_required @permission_required('administer all users') def admin_content_spam(): - # Essentially the same as admin_content_trash() except only shows heavily downvoted posts by new users - who are usually spammers + # Essentially the same as admin_content() except only shows heavily downvoted posts by new users - who are usually spammers page = request.args.get('page', 1, type=int) replies_page = request.args.get('replies_page', 1, type=int) diff --git a/app/templates/admin/posts.html b/app/templates/admin/content.html similarity index 95% rename from app/templates/admin/posts.html rename to app/templates/admin/content.html index 69d8aa8d..4059190e 100644 --- a/app/templates/admin/posts.html +++ b/app/templates/admin/content.html @@ -4,7 +4,7 @@ {% extends "base.html" %} {% endif %} {% from 'bootstrap/form.html' import render_form %} -{% set active_child = 'admin_content_trash' %} +{% set active_child = 'admin_content' %} {% block app_content %}
@@ -36,4 +36,4 @@

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index 4070cce7..aa8b9894 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -229,7 +229,7 @@
  • {{ _('Communities') }}
  • {{ _('Topics') }}
  • {{ _('Users') }}
  • -
  • {{ _('Monitoring - content') }}
  • +
  • {{ _('Monitoring - content') }}
  • {{ _('Monitoring - spammy content') }}
  • {{ _('Deleted content') }}
  • {% if g.site.registration_mode == 'RequireApplication' %} From 7d198934737939e81904faa26b68b841c404c19f Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Sat, 28 Dec 2024 00:04:20 +0100 Subject: [PATCH 2/6] combine all admin content templates --- app/admin/routes.py | 8 +-- app/templates/admin/content.html | 30 +++++++++++- app/templates/admin/deleted_posts.html | 68 -------------------------- app/templates/admin/spam_posts.html | 40 --------------- 4 files changed, 34 insertions(+), 112 deletions(-) delete mode 100644 app/templates/admin/deleted_posts.html delete mode 100644 app/templates/admin/spam_posts.html diff --git a/app/admin/routes.py b/app/admin/routes.py index 5444b0f2..757e66d0 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1205,7 +1205,9 @@ def admin_content(): next_url = url_for('admin.admin_content', page=posts.next_num) if posts.has_next else None prev_url = url_for('admin.admin_content', page=posts.prev_num) if posts.has_prev and page != 1 else None - return render_template('admin/content.html', title=_('Bad posts'), next_url=next_url, prev_url=prev_url, posts=posts, + return render_template('admin/content.html', title=_('Bad posts'), + next_url=next_url, prev_url=prev_url, + posts=posts, post_replies=None, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), @@ -1240,7 +1242,7 @@ def admin_content_spam(): next_url_replies = url_for('admin.admin_content_spam', replies_page=post_replies.next_num) if post_replies.has_next else None prev_url_replies = url_for('admin.admin_content_spam', replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None - return render_template('admin/spam_posts.html', title=_('Likely spam'), + return render_template('admin/content.html', title=_('Likely spam'), next_url=next_url, prev_url=prev_url, next_url_replies=next_url_replies, prev_url_replies=prev_url_replies, posts=posts, post_replies=post_replies, @@ -1274,7 +1276,7 @@ def admin_content_deleted(): next_url_replies = url_for('admin.admin_content_deleted', replies_page=post_replies.next_num) if post_replies.has_next else None prev_url_replies = url_for('admin.admin_content_deleted', replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None - return render_template('admin/deleted_posts.html', title=_('Deleted content'), + return render_template('admin/content.html', title=_('Deleted content'), next_url=next_url, prev_url=prev_url, next_url_replies=next_url_replies, prev_url_replies=prev_url_replies, posts=posts, post_replies=post_replies, diff --git a/app/templates/admin/content.html b/app/templates/admin/content.html index 4059190e..a3357271 100644 --- a/app/templates/admin/content.html +++ b/app/templates/admin/content.html @@ -9,10 +9,13 @@ {% block app_content %}
    -

    {{ _('Most downvoted posts in the last 3 days') }}

    +

    {{ title }}

    + {% if post_replies %}

    Posts

    {% endif %}
    {% for post in posts.items %} {% include 'post/_post_teaser.html' %} + {% else %} +

    {{ _('No posts.') }}

    {% endfor %}
    + {% if post_replies %} +

    Comments

    +
    + {% for post_reply in post_replies.items %} + {% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %} + {% include 'post/_post_reply_teaser.html' %} + {% endwith %} +
    + {% else %} +

    {{ _('No comments.') }}

    + {% endfor %} +
    + + {% endif %}

    diff --git a/app/templates/admin/deleted_posts.html b/app/templates/admin/deleted_posts.html deleted file mode 100644 index 218dead8..00000000 --- a/app/templates/admin/deleted_posts.html +++ /dev/null @@ -1,68 +0,0 @@ -{% 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_content_deleted' %} - -{% block app_content %} -
    -
    -

    {{ _('Deleted posts') }}

    -
    - {% for post in posts.items %} - {% include 'post/_post_teaser.html' %} - {% else %} -

    {{ _('No deleted posts.') }}

    - {% endfor %} -
    - - {% if post_replies %} -

    Deleted comments

    -
    - {% for post_reply in post_replies.items %} - {% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %} - {% include 'post/_post_reply_teaser.html' %} - {% endwith %} -
    - {% else %} -

    {{ _('No deleted comments.') }}

    - {% endfor %} -
    - - {% else %} -

    {{ _('No comments yet.') }}

    - {% endif %} -
    -
    -
    -
    -
    - {% include 'admin/_nav.html' %} -
    -
    -
    -{% endblock %} diff --git a/app/templates/admin/spam_posts.html b/app/templates/admin/spam_posts.html deleted file mode 100644 index c7222352..00000000 --- a/app/templates/admin/spam_posts.html +++ /dev/null @@ -1,40 +0,0 @@ -{% 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_content_spam' %} - -{% block app_content %} -
    -
    -

    {{ _('Most downvoted posts in the last 3 days') }}

    -
    - {% for post in posts.items %} - {% include 'post/_post_teaser.html' %} - {% endfor %} -
    - {% if post_replies %} -

    Downvoted comments

    -
    - {% for post_reply in post_replies.items %} - {% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %} - {% include 'post/_post_reply_teaser.html' %} - {% endwith %} -
    - {% endfor %} -
    - {% else %} -

    {{ _('No comments yet.') }}

    - {% endif %} -
    -
    -
    -
    -
    - {% include 'admin/_nav.html' %} -
    -
    -
    -{% endblock %} From d9eb3939b84dfd05c8900641b36a6f496cfe9d8b Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Sat, 28 Dec 2024 01:01:21 +0100 Subject: [PATCH 3/6] combine admin monitor content/spam/trash/deleted into one route --- app/admin/routes.py | 123 ++++++++++++------------------- app/templates/admin/_nav.html | 3 +- app/templates/admin/content.html | 71 ++++++++++++------ app/templates/base.html | 4 +- 4 files changed, 100 insertions(+), 101 deletions(-) diff --git a/app/admin/routes.py b/app/admin/routes.py index 757e66d0..90a21304 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1196,90 +1196,65 @@ def admin_users(): @login_required @permission_required('administer all users') def admin_content(): - - page = request.args.get('page', 1, type=int) - - posts = Post.query.filter(Post.posted_at > utcnow() - timedelta(days=3), Post.deleted == False, Post.down_votes > 0).order_by(Post.score) - posts = posts.paginate(page=page, per_page=100, error_out=False) - - next_url = url_for('admin.admin_content', page=posts.next_num) if posts.has_next else None - prev_url = url_for('admin.admin_content', page=posts.prev_num) if posts.has_prev and page != 1 else None - - return render_template('admin/content.html', title=_('Bad posts'), - next_url=next_url, prev_url=prev_url, - posts=posts, post_replies=None, - 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('/content/spam', methods=['GET']) -@login_required -@permission_required('administer all users') -def admin_content_spam(): - # Essentially the same as admin_content() except only shows heavily downvoted posts by new users - who are usually spammers page = request.args.get('page', 1, type=int) replies_page = request.args.get('replies_page', 1, type=int) + posts_replies = request.args.get('posts_replies', '') + show = request.args.get('show', 'trash') + days = request.args.get('days', 3, type=int) + + posts = Post.query.join(User, User.id == Post.user_id).filter(Post.deleted == False) + post_replies = PostReply.query.join(User, User.id == PostReply.user_id).filter(PostReply.deleted == False) + if show == 'trash': + title = _('Bad / Most downvoted') + posts = posts.filter(Post.down_votes > 0) + if days > 0: + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=days)) + posts = posts.order_by(Post.score) + post_replies = post_replies.filter(PostReply.down_votes > 0) + if days > 0: + post_replies = post_replies.filter(PostReply.posted_at > utcnow() - timedelta(days=days)) + post_replies = post_replies.order_by(PostReply.score) + elif show == 'spammy': + title = _('Likely spam') + posts = posts.filter(Post.score <= 0) + if days > 0: + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=days), + User.created > utcnow() - timedelta(days=days)) + posts = posts.order_by(Post.score) + post_replies = post_replies.filter(PostReply.score <= 0) + if days > 0: + post_replies = post_replies.filter(PostReply.posted_at > utcnow() - timedelta(days=days), + User.created > utcnow() - timedelta(days=days)) + post_replies = post_replies.order_by(PostReply.score) + elif show == 'deleted': + title = _('Deleted content') + posts = Post.query.filter(Post.deleted == True) + if days > 0: + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=days)) + posts = posts.order_by(desc(Post.posted_at)) + post_replies = PostReply.query.filter(PostReply.deleted == True) + if days > 0: + post_replies = post_replies.filter(PostReply.posted_at > utcnow() - timedelta(days=days)) + post_replies = post_replies.order_by(desc(PostReply.posted_at)) + + if posts_replies == 'posts': + post_replies = post_replies.filter(False) + elif posts_replies == 'replies': + posts = posts.filter(False) - posts = Post.query.join(User, User.id == Post.user_id).\ - filter(User.created > utcnow() - timedelta(days=3)).\ - filter(Post.posted_at > utcnow() - timedelta(days=3)).\ - filter(Post.deleted == False).\ - filter(Post.score <= 0).order_by(Post.score) posts = posts.paginate(page=page, per_page=100, error_out=False) - - post_replies = PostReply.query.join(User, User.id == PostReply.user_id). \ - filter(User.created > utcnow() - timedelta(days=3)). \ - filter(PostReply.posted_at > utcnow() - timedelta(days=3)). \ - filter(PostReply.deleted == False). \ - filter(PostReply.score <= 0).order_by(PostReply.score) post_replies = post_replies.paginate(page=replies_page, per_page=100, error_out=False) - next_url = url_for('admin.admin_content_spam', page=posts.next_num) if posts.has_next else None - prev_url = url_for('admin.admin_content_spam', page=posts.prev_num) if posts.has_prev and page != 1 else None - next_url_replies = url_for('admin.admin_content_spam', replies_page=post_replies.next_num) if post_replies.has_next else None - prev_url_replies = url_for('admin.admin_content_spam', replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None + next_url = url_for('admin.admin_content', page=posts.next_num, replies_page=replies_page, posts_replies=posts_replies, show=show, days=days) if posts.has_next else None + prev_url = url_for('admin.admin_content', page=posts.prev_num, replies_page=replies_page, posts_replies=posts_replies, show=show, days=days) if posts.has_prev and page != 1 else None + next_url_replies = url_for('admin.admin_content', replies_page=post_replies.next_num, page=page, posts_replies=posts_replies, show=show, days=days) if post_replies.has_next else None + prev_url_replies = url_for('admin.admin_content', replies_page=post_replies.prev_num, page=page, posts_replies=posts_replies, show=show, days=days) if post_replies.has_prev and replies_page != 1 else None - return render_template('admin/content.html', title=_('Likely spam'), - next_url=next_url, prev_url=prev_url, - next_url_replies=next_url_replies, prev_url_replies=prev_url_replies, - posts=posts, post_replies=post_replies, - 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('/content/deleted', methods=['GET']) -@login_required -@permission_required('administer all users') -def admin_content_deleted(): - # Shows all soft deleted posts - page = request.args.get('page', 1, type=int) - replies_page = request.args.get('replies_page', 1, type=int) - - posts = Post.query.\ - filter(Post.deleted == True).\ - order_by(desc(Post.posted_at)) - posts = posts.paginate(page=page, per_page=100, error_out=False) - - post_replies = PostReply.query. \ - filter(PostReply.deleted == True). \ - order_by(desc(PostReply.posted_at)) - post_replies = post_replies.paginate(page=replies_page, per_page=100, error_out=False) - - next_url = url_for('admin.admin_content_deleted', page=posts.next_num) if posts.has_next else None - prev_url = url_for('admin.admin_content_deleted', page=posts.prev_num) if posts.has_prev and page != 1 else None - next_url_replies = url_for('admin.admin_content_deleted', replies_page=post_replies.next_num) if post_replies.has_next else None - prev_url_replies = url_for('admin.admin_content_deleted', replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None - - return render_template('admin/content.html', title=_('Deleted content'), + return render_template('admin/content.html', title=title, next_url=next_url, prev_url=prev_url, next_url_replies=next_url_replies, prev_url_replies=prev_url_replies, posts=posts, post_replies=post_replies, + posts_replies=posts_replies, show=show, days=days, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), diff --git a/app/templates/admin/_nav.html b/app/templates/admin/_nav.html index addf534b..c9bf00b7 100644 --- a/app/templates/admin/_nav.html +++ b/app/templates/admin/_nav.html @@ -6,6 +6,7 @@ {{ _('Communities') }} | {{ _('Topics') }} | {{ _('Users') }} | + {{ _('Content') }} | {% if site.registration_mode == 'RequireApplication' %} {{ _('Registration applications') }} | {% endif %} @@ -13,7 +14,7 @@ {{ _('Federation') }} | {{ _('Newsletter') }} | {{ _('Permissions') }} | - {{ _('Activities') }} + {{ _('Activities') }} | {{ _('Modlog') }} {% if debug_mode %} | {{ _('Dev Tools') }} diff --git a/app/templates/admin/content.html b/app/templates/admin/content.html index a3357271..a7e41db7 100644 --- a/app/templates/admin/content.html +++ b/app/templates/admin/content.html @@ -9,29 +9,54 @@ {% block app_content %}
    -

    {{ title }}

    - {% if post_replies %}

    Posts

    {% endif %} -
    - {% for post in posts.items %} - {% include 'post/_post_teaser.html' %} - {% else %} -

    {{ _('No posts.') }}

    - {% endfor %} -
    - - {% if post_replies %} -

    Comments

    +

    {{ _('Content') }}

    +
    +
    + + + +
    +
    +
    + + + + +
    +
    +

    {{ title }}

    + {% if posts_replies != 'replies' %} + {% if post_replies %}

    Posts

    {% endif %} +
    + {% for post in posts.items %} + {% include 'post/_post_teaser.html' %} + {% else %} +

    {{ _('No posts.') }}

    + {% endfor %} +
    + + {% endif %} + {% if posts_replies != 'posts' %} + {% if posts %}

    Comments

    {% endif %}
    {% for post_reply in post_replies.items %} {% with teaser=True, disable_voting=True, no_collapse=True, show_deleted=True %} diff --git a/app/templates/base.html b/app/templates/base.html index aa8b9894..17737c5d 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -229,9 +229,7 @@
  • {{ _('Communities') }}
  • {{ _('Topics') }}
  • {{ _('Users') }}
  • -
  • {{ _('Monitoring - content') }}
  • -
  • {{ _('Monitoring - spammy content') }}
  • -
  • {{ _('Deleted content') }}
  • +
  • {{ _('Content') }}
  • {% if g.site.registration_mode == 'RequireApplication' %}
  • {{ _('Registration applications') }}
  • {% endif %} From e7b64554c149fdbae1153ead84daa5cfc86e48c3 Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Sat, 28 Dec 2024 11:11:59 +0100 Subject: [PATCH 4/6] don't count as trash if it's only one downvote or score is >=10 --- app/admin/routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/admin/routes.py b/app/admin/routes.py index 90a21304..f458464e 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1206,11 +1206,11 @@ def admin_content(): post_replies = PostReply.query.join(User, User.id == PostReply.user_id).filter(PostReply.deleted == False) if show == 'trash': title = _('Bad / Most downvoted') - posts = posts.filter(Post.down_votes > 0) + posts = posts.filter(Post.down_votes > 1, Post.score < 10) if days > 0: posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=days)) posts = posts.order_by(Post.score) - post_replies = post_replies.filter(PostReply.down_votes > 0) + post_replies = post_replies.filter(PostReply.down_votes > 1, PostReply.score < 10) if days > 0: post_replies = post_replies.filter(PostReply.posted_at > utcnow() - timedelta(days=days)) post_replies = post_replies.order_by(PostReply.score) From 77805800977e5a073e3630d01f3ae1e63f09ee75 Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Sat, 28 Dec 2024 11:34:20 +0100 Subject: [PATCH 5/6] don't allow voting here --- app/templates/admin/content.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/admin/content.html b/app/templates/admin/content.html index a7e41db7..97205579 100644 --- a/app/templates/admin/content.html +++ b/app/templates/admin/content.html @@ -37,7 +37,9 @@ {% if post_replies %}

    Posts

    {% endif %}
    {% for post in posts.items %} - {% include 'post/_post_teaser.html' %} + {% with disable_voting=True %} + {% include 'post/_post_teaser.html' %} + {% endwith %} {% else %}

    {{ _('No posts.') }}

    {% endfor %} From 356b0890d5887d6b1c7980445a2c03d1f3217ea1 Mon Sep 17 00:00:00 2001 From: Hendrik L Date: Sat, 28 Dec 2024 11:38:40 +0100 Subject: [PATCH 6/6] fix erraneous html tag --- app/templates/admin/users.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html index 89acc5fa..af7d5223 100644 --- a/app/templates/admin/users.html +++ b/app/templates/admin/users.html @@ -32,7 +32,7 @@
    - +