mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
instance block on instance profile
This commit is contained in:
parent
de2c5b710a
commit
8a008e3a8a
5 changed files with 43 additions and 25 deletions
|
@ -1,12 +1,13 @@
|
|||
from collections import namedtuple
|
||||
|
||||
from flask import request, url_for, g, abort
|
||||
from flask_login import current_user
|
||||
from flask import request, url_for, g, abort, flash, redirect
|
||||
from flask_login import current_user, login_required
|
||||
from flask_babel import _
|
||||
from sqlalchemy import or_, desc
|
||||
|
||||
from app import db, cache
|
||||
from app.instance import bp
|
||||
from app.models import Instance, User, Post, read_posts
|
||||
from app.models import Instance, User, Post, read_posts, InstanceBlock
|
||||
from app.utils import render_template, moderating_communities, joined_communities, menu_topics, blocked_domains, \
|
||||
blocked_instances, blocked_communities, blocked_users, user_filters_home, recently_upvoted_posts, \
|
||||
recently_downvoted_posts
|
||||
|
@ -179,3 +180,32 @@ def instance_posts(instance_domain):
|
|||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(), site=g.site,)
|
||||
|
||||
|
||||
@bp.route('/instance/<int:instance_id>/block', methods=['GET'])
|
||||
@login_required
|
||||
def instance_block(instance_id):
|
||||
instance = Instance.query.get_or_404(instance_id)
|
||||
existing_block = InstanceBlock.query.filter_by(user_id=current_user.id, instance_id=instance.id).first()
|
||||
if not existing_block:
|
||||
db.session.add(InstanceBlock(user_id=current_user.id, instance_id=instance.id))
|
||||
db.session.commit()
|
||||
cache.delete_memoized(blocked_instances, current_user.id)
|
||||
flash(f'{instance.domain} has been blocked.')
|
||||
|
||||
goto = request.args.get('redirect') if 'redirect' in request.args else url_for('user.user_settings_filters')
|
||||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/instance/<int:instance_id>/unblock', methods=['GET'])
|
||||
@login_required
|
||||
def instance_unblock(instance_id):
|
||||
instance = Instance.query.get_or_404(instance_id)
|
||||
existing_block = InstanceBlock.query.filter_by(user_id=current_user.id, instance_id=instance.id).first()
|
||||
if existing_block:
|
||||
db.session.delete(existing_block)
|
||||
db.session.commit()
|
||||
cache.delete_memoized(blocked_instances, current_user.id)
|
||||
flash(f'{instance.domain} has been unblocked.')
|
||||
|
||||
goto = request.args.get('redirect') if 'redirect' in request.args else url_for('user.user_settings_filters')
|
||||
return redirect(goto)
|
||||
|
|
|
@ -19,17 +19,20 @@
|
|||
<p>{{ _('This is a %(software)s instance.', software=instance.software) }}</p>
|
||||
<p><a href="{{ url_for('instance.instance_people', instance_domain=instance.domain) }}">{{ _('People') }}</a><br />
|
||||
<a href="{{ url_for('instance.instance_posts', instance_domain=instance.domain) }}">{{ _('Posts') }}</a></p>
|
||||
<p><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ _('Go to instance') }}</a></p>
|
||||
<p><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ _('Go to instance') }} <span class="fe fe-external"></span></a></p>
|
||||
</div>
|
||||
|
||||
<aside id="side_pane" class="col-12 col-md-4 side_pane" role="complementary">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2> </h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
{% if current_user.is_authenticated -%}
|
||||
{% if current_user.has_blocked_instance(instance.id) -%}
|
||||
<a class="btn btn-primary" href="{{ url_for('instance.instance_unblock', instance_id=instance.id, redirect='/instance/' + instance.domain) }}" rel="nofollow">{{ _('Unblock %(instance_name)s', instance_name=instance.domain) }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-primary confirm_first" href="{{ url_for('instance.instance_block', instance_id=instance.id, redirect='/instance/' + instance.domain) }}" rel="nofollow">{{ _('Block everyone from %(instance_name)s', instance_name=instance.domain) }}</a>
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
{% for instance in blocked_instances %}
|
||||
<tr>
|
||||
<td><a href="https://{{ instance.domain }}">{{ instance.domain }}</a></td>
|
||||
<td><a class="no-underline confirm_first" href="{{ url_for('user.instance_unblock', instance_id=instance.id) }}" rel="nofollow"><span class="fe fe-delete"></span> {{ _('Unblock') }}</a></td>
|
||||
<td><a class="no-underline confirm_first" href="{{ url_for('instance.instance_unblock', instance_id=instance.id) }}" rel="nofollow"><span class="fe fe-delete"></span> {{ _('Unblock') }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
{% 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>
|
||||
<a class="dropdown-item" href="{{ url_for('instance.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 -%}
|
||||
|
|
|
@ -706,21 +706,6 @@ def delete_profile(actor):
|
|||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/instance/<int:instance_id>/unblock', methods=['GET'])
|
||||
@login_required
|
||||
def instance_unblock(instance_id):
|
||||
instance = Instance.query.get_or_404(instance_id)
|
||||
existing_block = InstanceBlock.query.filter_by(user_id=current_user.id, instance_id=instance.id).first()
|
||||
if existing_block:
|
||||
db.session.delete(existing_block)
|
||||
db.session.commit()
|
||||
cache.delete_memoized(blocked_instances, current_user.id)
|
||||
flash(f'{instance.domain} has been unblocked.')
|
||||
|
||||
goto = request.args.get('redirect') if 'redirect' in request.args else url_for('user.user_settings_filters')
|
||||
return redirect(goto)
|
||||
|
||||
|
||||
@bp.route('/user/community/<int:community_id>/unblock', methods=['GET'])
|
||||
@login_required
|
||||
def user_community_unblock(community_id):
|
||||
|
|
Loading…
Reference in a new issue