only vote privately with untrusted instances

This commit is contained in:
rimu 2024-09-24 12:04:29 +12:00
parent b0e478b335
commit 7b4cdaf30c
7 changed files with 77 additions and 37 deletions

View file

@ -326,9 +326,26 @@ def list_subscribed_communities():
def list_instances():
page = request.args.get('page', 1, type=int)
search = request.args.get('search', '')
filter = request.args.get('filter', '')
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
instances = Instance.query.order_by(Instance.domain)
if search:
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
title = _('Instances')
if filter:
if filter == 'trusted':
instances = instances.filter(Instance.trusted == True)
title = _('Trusted instances')
elif filter == 'online':
instances = instances.filter(Instance.dormant == False, Instance.gone_forever == False)
title = _('Online instances')
elif filter == 'dormant':
instances = instances.filter(Instance.dormant == True, Instance.gone_forever == False)
title = _('Dormant instances')
elif filter == 'gone_forever':
instances = instances.filter(Instance.gone_forever == True)
title = _('Gone forever instances')
# Pagination
instances = instances.paginate(page=page,
@ -338,7 +355,7 @@ def list_instances():
prev_url = url_for('main.list_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
return render_template('list_instances.html', instances=instances,
title=_('Instances'), search=search,
title=title, search=search, filter=filter,
next_url=next_url, prev_url=prev_url,
low_bandwidth=low_bandwidth,
moderating_communities=moderating_communities(current_user.get_id()),

View file

@ -82,6 +82,8 @@ class Instance(db.Model):
return role and role.role == 'admin'
def votes_are_public(self):
if self.trusted is True: # only vote privately with untrusted instances
return False
return self.software.lower() == 'lemmy' or self.software.lower() == 'mbin' or self.software.lower() == 'kbin'
def post_count(self):

View file

@ -9,43 +9,63 @@
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
{% if search == '' %}
<h1>{{ _('Instances') }}</h1>
<h1>{{ title }}</h1>
{% else %}
<h1>{{ _('Instances containing "%(search)s"', search=search) }}</h1>
<h1>{{ title }}</h1>
{% endif %}
<form method="get">
<input type="search" name="search" value="{{ search }}"> <input type="submit" name="submit" value="{{ _('Search') }}">
</form>
<a href="{{ url_for('main.list_instances', filter='online') }}">{{ _('Online') }}</a> |
<a href="{{ url_for('main.list_instances', filter='dormant') }}">{{ _('Dormant') }}</a> |
<a href="{{ url_for('main.list_instances', filter='gone_forever') }}">{{ _('Gone forever') }}</a> |
<a href="{{ url_for('main.list_instances', filter='trusted') }}">{{ _('Trusted') }}</a>
<div class="table-responsive-sm pt-4">
<table class="table table-striped">
<tr>
<th>{{ _('Instance') }}</th>
<th>{{ _('Software') }}</th>
<th>{{ _('Version') }}</th>
<th>{{ _('Heard from') }}</th>
<th>{{ _('Sent to') }}</th>
</tr>
{% for instance in instances %}
<tr>
<td><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></td>
<td>{{ instance.software }}</td>
<td>{{ instance.version if instance.version }}</td>
<td>{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</td>
<td>{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</td>
</tr>
{% endfor %}
</table>
</div>
<nav aria-label="Pagination" class="mt-4" role="navigation">
{% if prev_url %}
<a href="{{ prev_url }}" class="btn btn-primary" rel="nofollow">
<span aria-hidden="true">&larr;</span> {{ _('Previous page') }}
</a>
{% if instances -%}
<div class="table-responsive-sm pt-4">
<table class="table table-striped">
<tr>
<th>{{ _('Instance') }}</th>
<th>{{ _('Software') }}</th>
<th>{{ _('Version') }}</th>
<th>{{ _('Heard from') }}</th>
<th>{{ _('Sent to') }}</th>
<th>{{ _('Online') }}</th>
</tr>
{% for instance in instances %}
<tr>
<td><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></td>
<td>{{ instance.software }}</td>
<td>{{ instance.version if instance.version }}</td>
<td>{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</td>
<td>{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</td>
<td>{% if instance.dormant and instance.gone_forever -%}
{{ _('Gone') }}
{% elif instance.dormant -%}
{{ _('Dormant') }}
{% else -%}
{{ _('Online') }}
{% endif -%}
</td>
</tr>
{% endfor %}
</table>
</div>
<nav aria-label="Pagination" class="mt-4" role="navigation">
{% if prev_url %}
<a href="{{ prev_url }}" class="btn btn-primary" rel="nofollow">
<span aria-hidden="true">&larr;</span> {{ _('Previous page') }}
</a>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" class="btn btn-primary" rel="nofollow">
{{ _('Next page') }} <span aria-hidden="true">&rarr;</span>
</a>
{% endif %}
</nav>
{% else -%}
<p>{{ _('No results to show.') }}</p>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" class="btn btn-primary" rel="nofollow">
{{ _('Next page') }} <span aria-hidden="true">&rarr;</span>
</a>
{% endif %}
</nav>
</div>
</div>

View file

@ -34,6 +34,7 @@
{{ render_field(form.default_filter) }}
{{ render_field(form.theme) }}
{{ render_field(form.vote_privately) }}
<small class="field_hint">{{ _('Votes will be sent to <a href="/instances?filter=trusted">untrusted instances</a> using an alt') }}</small>
{{ render_field(form.submit) }}
</form>
<p class="mt-4 pt-4">

View file

@ -8,7 +8,7 @@
<div class="card-body p-6">
<div class="card-title text-center">{{ _('Unsubscribed') }}</div>
<p>{{ _('You have unsubscribed from emails about unread notifications. We might email you for other reasons, though.') }}</p>
<p><a href="{{ url_for('user.change_settings') }}">{{ _('More email settings') }}</a></p>
<p><a href="{{ url_for('user.user_settings') }}">{{ _('More email settings') }}</a></p>
</div>
</div>
</div>

View file

@ -8,7 +8,7 @@
<div class="card-body p-6">
<div class="card-title text-center">{{ _('Unsubscribed') }}</div>
<p>{{ _('You have unsubscribed from the email newsletter. We might email you for other reasons, though.') }}</p>
<p><a href="{{ url_for('user.change_settings') }}">{{ _('More email settings') }}</a></p>
<p><a href="{{ url_for('user.user_settings') }}">{{ _('More email settings') }}</a></p>
</div>
</div>
</div>

View file

@ -360,7 +360,7 @@ def export_user_settings(user):
@bp.route('/user/settings', methods=['GET', 'POST'])
@login_required
def change_settings():
def user_settings():
user = User.query.filter_by(id=current_user.id, deleted=False, banned=False, ap_id=None).first()
if user is None:
abort(404)