From 0309cbded9f05078117359ed98efbb0174b81ca7 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:52:44 +0800 Subject: [PATCH] moderators can remove themselves #21 --- app/community/routes.py | 10 ++++++++-- .../community/_community_moderation_nav.html | 12 ++++++------ app/templates/community/community_mod_list.html | 10 ++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index f0e8404e..1b1c8610 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -975,7 +975,7 @@ def community_mod_list(community_id: int): if current_user.banned: return show_ban_message() community = Community.query.get_or_404(community_id) - if community.is_owner() or current_user.is_admin(): + if community.is_owner() or current_user.is_admin() or community.is_moderator(current_user): moderators = User.query.filter(User.banned == False).join(CommunityMember, CommunityMember.user_id == User.id).\ filter(CommunityMember.community_id == community_id, or_(CommunityMember.is_moderator == True, CommunityMember.is_owner == True)).all() @@ -986,6 +986,8 @@ def community_mod_list(community_id: int): joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), site=g.site ) + else: + abort(401) @bp.route('/community//moderators/add/', methods=['GET', 'POST']) @@ -1057,6 +1059,8 @@ def community_find_moderator(community_id: int): joined_communities=joined_communities(current_user.get_id()), menu_topics=menu_topics(), site=g.site ) + else: + abort(401) @bp.route('/community//moderators/remove/', methods=['GET', 'POST']) @@ -1065,7 +1069,7 @@ def community_remove_moderator(community_id: int, user_id: int): if current_user.banned: return show_ban_message() community = Community.query.get_or_404(community_id) - if community.is_owner() or current_user.is_admin(): + if community.is_owner() or current_user.is_admin() or user_id == current_user.id: existing_member = CommunityMember.query.filter(CommunityMember.user_id == user_id, CommunityMember.community_id == community_id).first() @@ -1085,6 +1089,8 @@ def community_remove_moderator(community_id: int, user_id: int): cache.delete_memoized(community_moderators, community_id) return redirect(url_for('community.community_mod_list', community_id=community.id)) + else: + abort(401) @bp.route('/community//block_instance', methods=['GET', 'POST']) diff --git a/app/templates/community/_community_moderation_nav.html b/app/templates/community/_community_moderation_nav.html index 4c08d25c..a3d1e725 100644 --- a/app/templates/community/_community_moderation_nav.html +++ b/app/templates/community/_community_moderation_nav.html @@ -3,20 +3,20 @@ {{ _('Settings') }} +{% endif %} + + {{ _('Reports') }} + {{ _('Moderators') }} -{% endif %} - - {{ _('Reports') }} - - + {{ _('Subscribers') }} {{ _('Appeals') }} - + {{ _('Mod log') }} \ No newline at end of file diff --git a/app/templates/community/community_mod_list.html b/app/templates/community/community_mod_list.html index 48ea4ca1..a4243311 100644 --- a/app/templates/community/community_mod_list.html +++ b/app/templates/community/community_mod_list.html @@ -22,9 +22,11 @@

{{ _('Moderators for %(community)s', community=community.display_name()) }}

{{ _('See and change who moderates this community') }}

- + {% if community.is_owner() -%} + + {% endif -%} @@ -37,7 +39,7 @@ {% for moderator in moderators %} -
{{ moderator.display_name() }}{% if not community.is_owner(moderator) %} + {% if not community.is_owner(moderator) and (current_user.is_admin() or moderator.id == current_user.id) %} {{ _('Remove') }}{% endif %}