diff --git a/app/admin/forms.py b/app/admin/forms.py index a0d6c009..17113355 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -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'}) diff --git a/app/admin/routes.py b/app/admin/routes.py index 79ad58a0..f1ad8fc4 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -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//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 + ) \ No newline at end of file diff --git a/app/templates/admin/edit_instance.html b/app/templates/admin/edit_instance.html new file mode 100644 index 00000000..2f9bc874 --- /dev/null +++ b/app/templates/admin/edit_instance.html @@ -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 %} +
+ +
+
+
+
+ {% include 'admin/_nav.html' %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/admin/instances.html b/app/templates/admin/instances.html index 41c06575..a97343c6 100644 --- a/app/templates/admin/instances.html +++ b/app/templates/admin/instances.html @@ -14,25 +14,26 @@ Status Filter: - Online | - Dormant | - Gone Forever | - Trusted + {{ _('Online') }} | + {{ _('Dormant') }} | + {{ _('Gone forever') }} | + {{ _('Trusted') }} - - - - - - - - - - - - - + + + + + + + + + + + + + + {% for instance in instances.items %} @@ -44,17 +45,18 @@ - + {% if instance.gone_forever %} - + {% elif instance.dormant %} - + {% else %} - + {% endif %} + {% endfor %}
DomainSoftwareVersionCommunitiesUsersPostsPost RepliesVote WeightTrustedSeenSentFailedStatus{{ _('Domain') }}{{ _('Software') }}{{ _('Version') }}{{ _('Communities') }}{{ _('Users') }}{{ _('Posts') }}{{ _('Post Replies') }}{{ _('Vote Weight') }}{{ _('Trusted') }}{{ _('Seen') }}{{ _('Sent') }}{{ _('Failed') }}{{ _('Status') }}
{{ instance.post_count() }} {{ instance.post_replies_count() }} {{ instance.vote_weight }}{{ 'Yes' if instance.trusted }}{{ _('Yes') if instance.trusted }} {{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }} {{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }} {{ instance.failures }}Gone Forever{{ _('Gone forever') }}Dormant{{ _('Dormant') }}Online{{ _('Online') }}{{ _('Edit') }}