This commit is contained in:
rimu 2023-10-22 18:26:57 +13:00
parent c85338506c
commit 5cc66e4a1a
2 changed files with 45 additions and 12 deletions

View file

@ -98,17 +98,23 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
{% if user_access('ban users', current_user.id) %} {% if user_access('ban users', current_user.id) %}
<div class="col-4"> {% if user.banned %}
<a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/ban">{{ _('Ban') }}</a> <div class="col-4">
</div> <a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/unban">{{ _('Unban') }}</a>
</div>
{% else %}
<div class="col-4">
<a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/ban">{{ _('Ban') }}</a>
</div>
{% endif %}
{% endif %} {% endif %}
{% if user_access('manage users', current_user.id) %} {% if user_access('manage users', current_user.id) %}
<div class="col-4"> <div class="col-4">
<a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/delete">{{ _('Delete') }}</a> <a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/delete">{{ _('Delete') }}</a>
</div> </div>
<div class="col-4"> <div class="col-4">
<a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/ban_purge">{{ _('Ban + Purge') }}</a> <a class="w-100 btn btn-primary confirm_first" href="/u/{{ user.user_name }}/ban_purge">{{ _('Ban + Purge') }}</a>
</div> </div>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View file

@ -102,7 +102,32 @@ def ban_profile(actor):
else: else:
abort(401) abort(401)
return redirect(f'/u/{actor}') goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
return redirect(goto)
@bp.route('/u/<actor>/unban', methods=['GET'])
def unban_profile(actor):
if user_access('ban users', current_user.id):
actor = actor.strip()
user = User.query.filter_by(user_name=actor, deleted=False).first()
if user is None:
user = User.query.filter_by(ap_id=actor, deleted=False).first()
if user is None:
abort(404)
if user.id == current_user.id:
flash('You cannot unban yourself.', 'error')
else:
user.banned = False
db.session.commit()
flash(f'{actor} has been unbanned.')
else:
abort(401)
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
return redirect(goto)
@bp.route('/u/<actor>/delete', methods=['GET']) @bp.route('/u/<actor>/delete', methods=['GET'])
@ -125,7 +150,8 @@ def delete_profile(actor):
else: else:
abort(401) abort(401)
return redirect(f'/u/{actor}') goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
return redirect(goto)
@bp.route('/u/<actor>/ban_purge', methods=['GET']) @bp.route('/u/<actor>/ban_purge', methods=['GET'])
@ -156,4 +182,5 @@ def ban_purge_profile(actor):
else: else:
abort(401) abort(401)
return redirect(f'/u/{actor}') goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
return redirect(goto)