mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
moderators can remove themselves #21
This commit is contained in:
parent
070e5726ef
commit
0309cbded9
3 changed files with 20 additions and 12 deletions
|
@ -975,7 +975,7 @@ def community_mod_list(community_id: int):
|
||||||
if current_user.banned:
|
if current_user.banned:
|
||||||
return show_ban_message()
|
return show_ban_message()
|
||||||
community = Community.query.get_or_404(community_id)
|
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).\
|
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()
|
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()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
menu_topics=menu_topics(), site=g.site
|
menu_topics=menu_topics(), site=g.site
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
abort(401)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/community/<int:community_id>/moderators/add/<int:user_id>', methods=['GET', 'POST'])
|
@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()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
menu_topics=menu_topics(), site=g.site
|
menu_topics=menu_topics(), site=g.site
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
abort(401)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/community/<int:community_id>/moderators/remove/<int:user_id>', methods=['GET', 'POST'])
|
@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:
|
if current_user.banned:
|
||||||
return show_ban_message()
|
return show_ban_message()
|
||||||
community = Community.query.get_or_404(community_id)
|
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,
|
existing_member = CommunityMember.query.filter(CommunityMember.user_id == user_id,
|
||||||
CommunityMember.community_id == community_id).first()
|
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)
|
cache.delete_memoized(community_moderators, community_id)
|
||||||
|
|
||||||
return redirect(url_for('community.community_mod_list', community_id=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'])
|
@bp.route('/community/<int:community_id>/block_instance', methods=['GET', 'POST'])
|
||||||
|
|
|
@ -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">
|
<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') }}
|
{{ _('Settings') }}
|
||||||
</a>
|
</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">
|
<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') }}
|
{{ _('Moderators') }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
<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">
|
||||||
<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">
|
|
||||||
{{ _('Subscribers') }}
|
{{ _('Subscribers') }}
|
||||||
</a>
|
</a>
|
||||||
<a href="/community/{{ community.link() }}/moderate/appeals" class="btn {{ 'btn-primary' if current == 'appeals' else 'btn-outline-secondary' }} disabled" rel="nofollow noindex" >
|
<a href="/community/{{ community.link() }}/moderate/appeals" class="btn {{ 'btn-primary' if current == 'appeals' else 'btn-outline-secondary' }} disabled" rel="nofollow noindex" >
|
||||||
{{ _('Appeals') }}
|
{{ _('Appeals') }}
|
||||||
</a>
|
</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') }}
|
{{ _('Mod log') }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
|
@ -22,9 +22,11 @@
|
||||||
<h1 class="mt-2">{{ _('Moderators for %(community)s', community=community.display_name()) }}</h1>
|
<h1 class="mt-2">{{ _('Moderators for %(community)s', community=community.display_name()) }}</h1>
|
||||||
</div>
|
</div>
|
||||||
<p>{{ _('See and change who moderates this community') }}</p>
|
<p>{{ _('See and change who moderates this community') }}</p>
|
||||||
|
{% if community.is_owner() -%}
|
||||||
<div class="col-12 text-right">
|
<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>
|
<a class="btn btn-primary" href="{{ url_for('community.community_find_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif -%}
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-responsive">
|
<table class="table table-responsive">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -37,7 +39,7 @@
|
||||||
{% for moderator in moderators %}
|
{% for moderator in moderators %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ moderator.display_name() }}</td>
|
<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"
|
<a class="no-underline confirm_first"
|
||||||
href="{{ url_for('community.community_remove_moderator', community_id=community.id, user_id=moderator.id) }}"
|
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>
|
rel="nofollow"><span class="fe fe-delete"></span> {{ _('Remove') }}</a>{% endif %}</td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue