blocking tables inside tabs in user settings #91

This commit is contained in:
rimu 2024-03-11 21:17:18 +13:00
parent 7c520c556c
commit 4a1c4e2d08
3 changed files with 101 additions and 8 deletions

View file

@ -50,10 +50,92 @@
{% endif %}
<h5>Blocks</h5>
<p class="card-text">Manage what users, communities, domains or instances you want to block. Blocking them means you will no longer see any posts associated with them.</p>
<a class="btn btn-primary" href="">Manage User Blocks</a>
<a class="btn btn-primary" href="">Manage Communities Blocks</a>
<a class="btn btn-primary" href="">Manage Domain Blocks</a>
<a class="btn btn-primary" href="">Manage Instance Blocks</a>
<nav id="block_chooser">
<div class="nav nav-tabs nav-justified" id="typeTab" role="tablist">
<button class="nav-link active" id="discussion-tab" data-bs-toggle="tab" data-bs-target="#people-tab-pane"
type="button" role="tab" aria-controls="discussion-tab-pane" aria-selected="true">{{ _('People') }}</button>
<button class="nav-link" id="link-tab" data-bs-toggle="tab" data-bs-target="#communities-tab-pane"
type="button" role="tab" aria-controls="link-tab-pane" aria-selected="false">{{ _('Communities') }}</button>
<button class="nav-link" id="image-tab" data-bs-toggle="tab" data-bs-target="#domains-tab-pane"
type="button" role="tab" aria-controls="image-tab-pane" aria-selected="false">{{ _('Domains') }}</button>
<button class="nav-link" id="poll-tab" data-bs-toggle="tab" data-bs-target="#instances-tab-pane"
type="button" role="tab" aria-controls="poll-tab-pane" aria-selected="false">{{ _('Instances') }}</button>
</div>
</nav>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="people-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
{% if blocked_users %}
<table class="table table-responsive">
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Unblock') }}</th>
</tr>
{% for user in blocked_users %}
<tr>
<td><a href="{{ url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not none else user.user_name) }}">{{ user.display_name() }}</a></td>
<td><a class="no-underline confirm_first" href="{{ url_for('user.unblock_profile', actor=user.link()) }}" rel="nofollow"><span class="fe fe-delete"> {{ _('Unblock') }}</span></a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{{ _('No blocked people') }}</p>
{% endif %}
</div>
<div class="tab-pane fade show" id="communities-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
{% if blocked_communities %}
<table class="table table-responsive">
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Unblock') }}</th>
</tr>
{% for community in blocked_communities %}
<tr>
<td><a href="{{ url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not none else community.name) }}">{{ community.title }}</a></td>
<td><a class="no-underline confirm_first" href="#" rel="nofollow"><span class="fe fe-delete"> {{ _('Unblock') }}</span></a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{{ _('No blocked communities') }}</p>
{% endif %}
</div>
<div class="tab-pane fade show" id="domains-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
{% if blocked_domains %}
<table class="table table-responsive">
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Unblock') }}</th>
</tr>
{% for domain in blocked_domains %}
<tr>
<td><a href="{{ url_for('domain.show_domain', domain_id=domain.id) }}">{{ domain.name }}</a></td>
<td><a class="no-underline confirm_first" href="{{ url_for('domain.domain_unblock', domain_id=domain.id) }}" rel="nofollow"><span class="fe fe-delete"> {{ _('Unblock') }}</span></a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{{ _('No blocked domains') }}</p>
{% endif %}
</div>
<div class="tab-pane fade show" id="instances-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
{% if blocked_instances %}
<table class="table table-responsive">
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Unblock') }}</th>
</tr>
{% for instance in blocked_instances %}
<tr>
<td><a href="#">{{ instance.domain }}</a></td>
<td><a class="no-underline confirm_first" href="#" rel="nofollow"><span class="fe fe-delete"> {{ _('Unblock') }}</span></a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>{{ _('No blocked instances') }}</p>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -49,11 +49,11 @@
<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 user') }}</a>
<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 user') }}</a>
<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 user') }}</a>
<a class="btn btn-primary" href="{{ url_for('user.report_profile', actor=user.link()) }}" rel="nofollow">{{ _('Report') }}</a>
</div>
{% endif %}
<p class="small">{{ _('Joined') }}: {{ moment(user.created).fromNow(refresh=True) }}<br />

View file

@ -11,7 +11,8 @@ from app.activitypub.util import default_context, find_actor_or_create
from app.community.util import save_icon_file, save_banner_file, retrieve_mods_and_backfill
from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_PENDING
from app.models import Post, Community, CommunityMember, User, PostReply, PostVote, Notification, utcnow, File, Site, \
Instance, Report, UserBlock, CommunityBan, CommunityJoinRequest, CommunityBlock, Filter
Instance, Report, UserBlock, CommunityBan, CommunityJoinRequest, CommunityBlock, Filter, Domain, DomainBlock, \
InstanceBlock
from app.user import bp
from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, FilterEditForm
from app.user.utils import purge_user_then_delete
@ -614,7 +615,17 @@ def import_settings_task(user_id, filename):
@login_required
def user_settings_filters():
filters = Filter.query.filter_by(user_id=current_user.id).order_by(Filter.title).all()
blocked_users = User.query.join(UserBlock, UserBlock.blocked_id == User.id).\
filter(UserBlock.blocker_id == current_user.id).order_by(User.user_name).all()
blocked_communities = Community.query.join(CommunityBlock, CommunityBlock.community_id == Community.id).\
filter(CommunityBlock.user_id == current_user.id).order_by(Community.title).all()
blocked_domains = Domain.query.join(DomainBlock, DomainBlock.domain_id == Domain.id).\
filter(DomainBlock.user_id == current_user.id).order_by(Domain.name).all()
blocked_instances = Instance.query.join(InstanceBlock, InstanceBlock.instance_id == Instance.id).\
filter(InstanceBlock.user_id == current_user.id).order_by(Instance.domain).all()
return render_template('user/filters.html', filters=filters, user=current_user,
blocked_users=blocked_users, blocked_communities=blocked_communities,
blocked_domains=blocked_domains, blocked_instances=blocked_instances,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id())
)