change instance settings #255

This commit is contained in:
rimu 2024-09-24 11:33:49 +12:00
parent 8fcd4c7de7
commit b0e478b335
4 changed files with 92 additions and 24 deletions

View file

@ -1,8 +1,8 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired, FileAllowed
from sqlalchemy import func
from wtforms import StringField, PasswordField, SubmitField, EmailField, HiddenField, BooleanField, TextAreaField, SelectField, \
FileField, IntegerField
from wtforms import StringField, PasswordField, SubmitField, EmailField, HiddenField, BooleanField, TextAreaField, \
SelectField, FileField, IntegerField, FloatField
from wtforms.fields.choices import SelectMultipleField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length, Optional
from flask_babel import _, lazy_gettext as _l
@ -116,6 +116,15 @@ class EditTopicForm(FlaskForm):
submit = SubmitField(_l('Save'))
class EditInstanceForm(FlaskForm):
vote_weight = FloatField(_l('Vote weight'))
dormant = BooleanField(_l('Dormant'))
gone_forever = BooleanField(_l('Gone forever'))
trusted = BooleanField(_l('Trusted'))
posting_warning = TextAreaField(_l('Posting warning'))
submit = SubmitField(_l('Save'))
class AddUserForm(FlaskForm):
user_name = StringField(_l('User name'), validators=[DataRequired()],
render_kw={'autofocus': True, 'autocomplete': 'off'})

View file

@ -14,7 +14,7 @@ from app.activitypub.routes import process_inbox_request, process_delete_request
from app.activitypub.signature import post_request, default_context
from app.activitypub.util import instance_allowed, instance_blocked, extract_domain_and_actor
from app.admin.forms import FederationForm, SiteMiscForm, SiteProfileForm, EditCommunityForm, EditUserForm, \
EditTopicForm, SendNewsletterForm, AddUserForm, PreLoadCommunitiesForm
EditTopicForm, SendNewsletterForm, AddUserForm, PreLoadCommunitiesForm, EditInstanceForm
from app.admin.util import unsubscribe_from_everything_then_delete, unsubscribe_from_community, send_newsletter, \
topics_for_form
from app.community.util import save_icon_file, save_banner_file, search_for_community
@ -1123,3 +1123,35 @@ def admin_instances():
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site)
@bp.route('/instance/<int:instance_id>/edit', methods=['GET', 'POST'])
@login_required
@permission_required('administer all communities')
def admin_instance_edit(instance_id):
form = EditInstanceForm()
instance = Instance.query.get_or_404(instance_id)
if form.validate_on_submit():
instance.vote_weight = form.vote_weight.data
instance.dormant = form.dormant.data
instance.gone_forever = form.gone_forever.data
instance.trusted = form.trusted.data
instance.posting_warning = form.posting_warning.data
db.session.commit()
flash(_('Saved'))
return redirect(url_for('admin.admin_instances'))
else:
form.vote_weight.data = instance.vote_weight
form.dormant.data = instance.dormant
form.gone_forever.data = instance.gone_forever
form.trusted.data = instance.trusted
form.posting_warning.data = instance.posting_warning
return render_template('admin/edit_instance.html', title=_('Edit instance'), form=form, instance=instance,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(),
site=g.site
)

View file

@ -0,0 +1,25 @@
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
{% extends 'themes/' + theme() + '/base.html' %}
{% else %}
{% extends "base.html" %}
{% endif %} %}
{% from 'bootstrap/form.html' import render_form %}
{% set active_child = 'admin_instances' %}
{% block app_content %}
<div class="row">
<div class="col col-login mx-auto">
{% if topic %}
<h1>{{ _('Edit %(instance_name)s', instance_name=instance.domain) }}</h1>
{% endif %}
{{ render_form(form) }}
</div>
</div>
<hr />
<div class="row">
<div class="col">
{% include 'admin/_nav.html' %}
</div>
</div>
<hr />
{% endblock %}

View file

@ -14,25 +14,26 @@
<input type="search" name="search"> <input type="submit" name="submit" value="Search">
</form>
Status Filter:
<a href="{{ url_for('admin.admin_instances', filter='online') }}">Online</a> |
<a href="{{ url_for('admin.admin_instances', filter='dormant') }}">Dormant</a> |
<a href="{{ url_for('admin.admin_instances', filter='gone_forever') }}">Gone Forever</a> |
<a href="{{ url_for('admin.admin_instances', filter='trusted') }}">Trusted</a>
<a href="{{ url_for('admin.admin_instances', filter='online') }}">{{ _('Online') }}</a> |
<a href="{{ url_for('admin.admin_instances', filter='dormant') }}">{{ _('Dormant') }}</a> |
<a href="{{ url_for('admin.admin_instances', filter='gone_forever') }}">{{ _('Gone forever') }}</a> |
<a href="{{ url_for('admin.admin_instances', filter='trusted') }}">{{ _('Trusted') }}</a>
<table class="table table-striped">
<tr>
<th>Domain</th>
<th>Software</th>
<th>Version</th>
<th title="{{ _('Known Communities') }}">Communities</th>
<th title="{{ _('Known Users') }}">Users</th>
<th>Posts</th>
<th>Post Replies</th>
<th>Vote Weight</th>
<th>Trusted</th>
<th title="{{ _('When an Activity was received from them') }}">Seen</th>
<th title="{{ _('When we successfully sent them an Activity') }}">Sent</th>
<th title="{{ _('How many times we failed to send (reset to 0 after every successful send)') }}">Failed</th>
<th title="{{ _('Instance Status - Online/Dormant/Gone Forever') }}">Status</th>
<th>{{ _('Domain') }}</th>
<th>{{ _('Software') }}</th>
<th>{{ _('Version') }}</th>
<th title="{{ _('Known Communities') }}">{{ _('Communities') }}</th>
<th title="{{ _('Known Users') }}">{{ _('Users') }}</th>
<th>{{ _('Posts') }}</th>
<th>{{ _('Post Replies') }}</th>
<th>{{ _('Vote Weight') }}</th>
<th>{{ _('Trusted') }}</th>
<th title="{{ _('When an Activity was received from them') }}">{{ _('Seen') }}</th>
<th title="{{ _('When we successfully sent them an Activity') }}">{{ _('Sent') }}</th>
<th title="{{ _('How many times we failed to send (reset to 0 after every successful send)') }}">{{ _('Failed') }}</th>
<th title="{{ _('Instance Status - Online/Dormant/Gone Forever') }}">{{ _('Status') }}</th>
<th> </th>
</tr>
{% for instance in instances.items %}
<tr>
@ -44,17 +45,18 @@
<td>{{ instance.post_count() }}</td>
<td>{{ instance.post_replies_count() }}</td>
<td>{{ instance.vote_weight }}</td>
<td>{{ 'Yes' if instance.trusted }}</td>
<td>{{ _('Yes') if instance.trusted }}</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>{{ instance.failures }}</td>
{% if instance.gone_forever %}
<td>Gone Forever</td>
<td>{{ _('Gone forever') }}</td>
{% elif instance.dormant %}
<td>Dormant</td>
<td>{{ _('Dormant') }}</td>
{% else %}
<td>Online</td>
<td>{{ _('Online') }}</td>
{% endif %}
<td><a href="{{ url_for('admin.admin_instance_edit', instance_id=instance.id) }}">{{ _('Edit') }}</a></td>
</tr>
{% endfor %}
</table>