mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
instance block on user profile
This commit is contained in:
parent
5b386ec190
commit
de2c5b710a
4 changed files with 57 additions and 10 deletions
|
@ -514,6 +514,10 @@ a {
|
|||
display: none;
|
||||
}
|
||||
|
||||
.display-inline {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
top: -40px; /* Adjust as needed to hide the link off-screen */
|
||||
|
|
|
@ -68,6 +68,10 @@ a {
|
|||
}
|
||||
}
|
||||
|
||||
.display-inline {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
top: -40px; /* Adjust as needed to hide the link off-screen */
|
||||
|
|
|
@ -77,17 +77,32 @@
|
|||
{% if user.matrix_user_id %}
|
||||
<a class="btn btn-primary" href="https://matrix.to/#/{{ user.matrix_user_id }}" rel="nofollow" aria-label="{{ _('Send message with matrix chat') }}">{{ _('Send message using Matrix') }}</a>
|
||||
{% endif %}
|
||||
{% if current_user.has_blocked_user(user.id) %}
|
||||
<a class="btn btn-primary" href="{{ url_for('user.unblock_profile', actor=user.link()) }}" rel="nofollow">{{ _('Unblock') }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-primary confirm_first" href="{{ url_for('user.block_profile', actor=user.link()) }}" rel="nofollow">{{ _('Block') }}</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-primary" href="{{ url_for('user.report_profile', actor=user.link()) }}" rel="nofollow">{{ _('Report') }}</a>
|
||||
{% endif %}
|
||||
{% if user.is_local() %}
|
||||
<a class="btn btn-primary" href="{{ url_for('user.fediverse_redirect', actor=user.link()) }}" rel="nofollow"><img src="/static/images/fediverse_logo.svg" width="25" height="25"> {{ _('Follow') }}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_local() -%}
|
||||
<a class="btn btn-primary" href="{{ url_for('user.fediverse_redirect', actor=user.link()) }}" rel="nofollow"><img src="/static/images/fediverse_logo.svg" width="22" height="22"> {{ _('Follow') }}</a>
|
||||
{% endif -%}
|
||||
|
||||
<div class="dropdown display-inline">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{{ _('More') }}
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% if current_user.has_blocked_user(user.id) -%}
|
||||
<a class="dropdown-item" href="{{ url_for('user.unblock_profile', actor=user.link()) }}" rel="nofollow">{{ _('Unblock') }}</a>
|
||||
{% else -%}
|
||||
<a class="dropdown-item confirm_first" href="{{ url_for('user.block_profile', actor=user.link()) }}" rel="nofollow">{{ _('Block %(user_name)s', user_name=user.display_name()) }}</a>
|
||||
{% endif -%}
|
||||
{% if not user.is_local() -%}
|
||||
{% if current_user.has_blocked_instance(user.instance_id) -%}
|
||||
<a class="dropdown-item" href="{{ url_for('user.instance_unblock', instance_id=user.instance_id, redirect='/u/' + user.link()) }}" rel="nofollow">{{ _('Unblock %(instance_name)s', instance_name=user.ap_domain) }}</a>
|
||||
{% else %}
|
||||
<a class="dropdown-item confirm_first" href="{{ url_for('user.user_block_instance', actor=user.link()) }}" rel="nofollow">{{ _('Block everyone from %(instance_name)s', instance_name=user.ap_domain) }}</a>
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
<li><a class="dropdown-item" href="{{ url_for('user.report_profile', actor=user.link()) }}" rel="nofollow">{{ _('Report') }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="small">{{ _('Instance') }}: <a href="{{ url_for('instance.instance_overview', instance_domain=user.instance_domain()) }}">{{ user.instance_domain() }}</a><br />
|
||||
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}<br />
|
||||
|
|
|
@ -574,6 +574,29 @@ def block_profile(actor):
|
|||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/u/<actor>/block_instance', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def user_block_instance(actor):
|
||||
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.instance_id == 1:
|
||||
flash(_('You cannot block your instance.'), 'error')
|
||||
else:
|
||||
existing = InstanceBlock.query.filter_by(user_id=current_user.id, instance_id=user.instance_id).first()
|
||||
if not existing:
|
||||
db.session.add(InstanceBlock(user_id=current_user.id, instance_id=user.instance_id))
|
||||
db.session.commit()
|
||||
cache.delete_memoized(blocked_instances, current_user.id)
|
||||
flash(_('Content from %(name)s will be hidden.', name=user.ap_domain))
|
||||
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
|
||||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/u/<actor>/unblock', methods=['GET'])
|
||||
@login_required
|
||||
def unblock_profile(actor):
|
||||
|
@ -682,6 +705,7 @@ def delete_profile(actor):
|
|||
goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}'
|
||||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/instance/<int:instance_id>/unblock', methods=['GET'])
|
||||
@login_required
|
||||
def instance_unblock(instance_id):
|
||||
|
|
Loading…
Reference in a new issue