moderators can remove themselves #21

This commit is contained in:
rimu 2024-07-16 19:52:44 +08:00
parent 070e5726ef
commit 0309cbded9
3 changed files with 20 additions and 12 deletions

View file

@ -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/<int:community_id>/moderators/add/<int:user_id>', 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/<int:community_id>/moderators/remove/<int:user_id>', 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/<int:community_id>/block_instance', methods=['GET', 'POST'])

View file

@ -3,20 +3,20 @@
<a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn {{ 'btn-primary' if current == '' or current == 'edit_settings' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Settings') }}
</a>
{% endif %}
<a href="{{ url_for('community.community_moderate', actor=community.link()) }}" aria-label="{{ _('Sort by hot') }}" class="btn {{ 'btn-primary' if current == '' or current == 'reports' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Reports') }}
</a>
<a href="{{ url_for('community.community_mod_list', community_id=community.id) }}" class="btn {{ 'btn-primary' if current == 'moderators' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Moderators') }}
</a>
{% endif %}
<a href="/community/{{ community.link() }}/moderate" aria-label="{{ _('Sort by hot') }}" class="btn {{ 'btn-primary' if current == '' or current == 'reports' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Reports') }}
</a>
<a href="/community/{{ community.link() }}/moderate/subscribers" class="btn {{ 'btn-primary' if current == 'subscribers' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="{{ url_for('community.community_moderate_subscribers', actor=community.link()) }}" class="btn {{ 'btn-primary' if current == 'subscribers' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Subscribers') }}
</a>
<a href="/community/{{ community.link() }}/moderate/appeals" class="btn {{ 'btn-primary' if current == 'appeals' else 'btn-outline-secondary' }} disabled" rel="nofollow noindex" >
{{ _('Appeals') }}
</a>
<a href="/community/{{ community.link() }}/moderate/modlog" class="btn {{ 'btn-primary' if current == 'modlog' else 'btn-outline-secondary' }} " rel="nofollow noindex" >
<a href="{{ url_for('community.community_modlog', actor=community.link()) }}" class="btn {{ 'btn-primary' if current == 'modlog' else 'btn-outline-secondary' }} " rel="nofollow noindex" >
{{ _('Mod log') }}
</a>
</div>

View file

@ -22,9 +22,11 @@
<h1 class="mt-2">{{ _('Moderators for %(community)s', community=community.display_name()) }}</h1>
</div>
<p>{{ _('See and change who moderates this community') }}</p>
<div class="col-12 text-right">
<a class="btn btn-primary" href="{{ url_for('community.community_find_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a>
</div>
{% if community.is_owner() -%}
<div class="col-12 text-right">
<a class="btn btn-primary" href="{{ url_for('community.community_find_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a>
</div>
{% endif -%}
</div>
<table class="table table-responsive">
<thead>
@ -37,7 +39,7 @@
{% for moderator in moderators %}
<tr>
<td>{{ moderator.display_name() }}</td>
<td>{% if not community.is_owner(moderator) %}
<td>{% if not community.is_owner(moderator) and (current_user.is_admin() or moderator.id == current_user.id) %}
<a class="no-underline confirm_first"
href="{{ url_for('community.community_remove_moderator', community_id=community.id, user_id=moderator.id) }}"
rel="nofollow"><span class="fe fe-delete"></span> {{ _('Remove') }}</a>{% endif %}</td>