Merge pull request 'small fixes' (#123) from rscmbbng/pyfedi:small-fixes into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/123
This commit is contained in:
rimu 2024-03-27 02:28:30 +00:00
commit 0cf0238756
10 changed files with 40 additions and 24 deletions

View file

@ -3,7 +3,7 @@ from flask_login import current_user
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField, BooleanField, HiddenField, SelectField, FileField, \ from wtforms import StringField, SubmitField, TextAreaField, BooleanField, HiddenField, SelectField, FileField, \
DateField DateField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length, Optional from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length, Regexp, Optional
from flask_babel import _, lazy_gettext as _l from flask_babel import _, lazy_gettext as _l
from app import db from app import db
@ -82,7 +82,7 @@ class CreatePostForm(FlaskForm):
link_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) link_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)})
link_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)}, link_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)},
render_kw={'placeholder': 'Text (optional)'}) render_kw={'placeholder': 'Text (optional)'})
link_url = StringField(_l('URL'), render_kw={'placeholder': 'https://...'}) link_url = StringField(_l('URL'), validators=[Regexp(r'^https?://', message='Submitted links need to start with "http://"" or "https://"')], render_kw={'placeholder': 'https://...'})
image_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) image_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)})
image_alt_text = StringField(_l('Alt text'), validators={Optional(), Length(min=3, max=255)}) image_alt_text = StringField(_l('Alt text'), validators={Optional(), Length(min=3, max=255)})
image_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)}, image_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)},

View file

@ -639,7 +639,8 @@ def community_edit(community_id: int):
community.image = file community.image = file
db.session.commit() db.session.commit()
community.topic.num_communities = community.topic.communities.count() if community.topic:
community.topic.num_communities = community.topic.communities.count()
db.session.commit() db.session.commit()
flash(_('Saved')) flash(_('Saved'))
return redirect(url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not None else community.name)) return redirect(url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not None else community.name))
@ -654,7 +655,7 @@ def community_edit(community_id: int):
form.topic.data = community.topic_id if community.topic_id else None form.topic.data = community.topic_id if community.topic_id else None
form.default_layout.data = community.default_layout form.default_layout.data = community.default_layout
return render_template('community/community_edit.html', title=_('Edit community'), form=form, return render_template('community/community_edit.html', title=_('Edit community'), form=form,
current_app=current_app, current_app=current_app, current="edit_settings",
community=community, moderating_communities=moderating_communities(current_user.get_id()), community=community, moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id())) joined_communities=joined_communities(current_user.get_id()))
else: else:
@ -695,7 +696,7 @@ def community_mod_list(community_id: int):
filter(CommunityMember.community_id == community_id, or_(CommunityMember.is_moderator == True, CommunityMember.is_owner == True)).all() filter(CommunityMember.community_id == community_id, or_(CommunityMember.is_moderator == True, CommunityMember.is_owner == True)).all()
return render_template('community/community_mod_list.html', title=_('Moderators for %(community)s', community=community.display_name()), return render_template('community/community_mod_list.html', title=_('Moderators for %(community)s', community=community.display_name()),
moderators=moderators, community=community, moderators=moderators, community=community, current="moderators",
moderating_communities=moderating_communities(current_user.get_id()), moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()) joined_communities=joined_communities(current_user.get_id())
) )

View file

@ -1,14 +1,22 @@
<div class="btn-group mt-1 mb-2"> <div class="btn-group mt-1 mb-2">
{% if community.is_owner() or current_user.is_admin() %}
<a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn {{ 'btn-primary' if current == '' or current == 'edit_settings' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Settings') }}
</a>
<a href="{{ url_for('community.community_mod_list', community_id=community.id) }}" class="btn {{ 'btn-primary' if current == 'moderators' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Moderators') }}
</a>
{% endif %}
<a href="/community/{{ community.link() }}/moderate" aria-label="{{ _('Sort by hot') }}" class="btn {{ 'btn-primary' if current == '' or current == 'reports' else 'btn-outline-secondary' }}" rel="nofollow noindex"> <a href="/community/{{ community.link() }}/moderate" aria-label="{{ _('Sort by hot') }}" class="btn {{ 'btn-primary' if current == '' or current == 'reports' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Reports') }} {{ _('Reports') }}
</a> </a>
<a href="/community/{{ community.link() }}/moderate/banned" class="btn {{ 'btn-primary' if current == 'banned' else 'btn-outline-secondary' }}" rel="nofollow noindex"> <a href="/community/{{ community.link() }}/moderate/banned" class="btn {{ 'btn-primary' if current == 'banned' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Banned people') }} {{ _('Banned people') }}
</a> </a>
<a href="/community/{{ community.link() }}/moderate/appeals" class="btn {{ 'btn-primary' if current == 'appeals' else 'btn-outline-secondary' }}" rel="nofollow noindex"> <a href="/community/{{ community.link() }}/moderate/appeals" class="btn {{ 'btn-primary' if current == 'appeals' else 'btn-outline-secondary' }} disabled" rel="nofollow noindex" >
{{ _('Appeals') }} {{ _('Appeals') }}
</a> </a>
<a href="/community/{{ community.link() }}/moderate/modlog" class="btn {{ 'btn-primary' if current == 'modlog' else 'btn-outline-secondary' }}" rel="nofollow noindex"> <a href="/community/{{ community.link() }}/moderate/modlog" class="btn {{ 'btn-primary' if current == 'modlog' else 'btn-outline-secondary' }} disabled" rel="nofollow noindex" >
{{ _('Mod log') }} {{ _('Mod log') }}
</a> </a>
</div> </div>

View file

@ -175,14 +175,10 @@
<h2>{{ _('Community Settings') }}</h2> <h2>{{ _('Community Settings') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
{% if is_moderator or is_owner or is_admin %}
<p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderate') }}</a></p>
{% endif %}
{% if is_owner or is_admin %} {% if is_owner or is_admin %}
<p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings') }}</a></p> <p><a href="{{ url_for('community.community_edit', community_id=community.id) }}" class="btn btn-primary">{{ _('Settings & Moderation') }}</a></p>
{% endif %} {% elif is_moderator %}
{% if community.is_local() and (community.is_owner() or current_user.is_admin()) %} <p><a href="/community/{{ community.link() }}/moderate" class="btn btn-primary">{{ _('Moderation') }}</a></p>
<p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View file

@ -12,7 +12,9 @@
<div class="card-body p-6"> <div class="card-body p-6">
<div class="card-title">{{ _('Delete "%(community_title)s"', community_title=community.title) }}</div> <div class="card-title">{{ _('Delete "%(community_title)s"', community_title=community.title) }}</div>
<div class="card-body"> <div class="card-body">
<p class="card-text"> Are you sure you want to delete this community? This is irreversible and will delete all posts and comments associated with it.</p>
{{ render_form(form) }} {{ render_form(form) }}
<a class="btn btn-primary mt-2" href="/c/{{ community.link() }}">Go back</a>
</div> </div>
</div> </div>
</div> </div>

View file

@ -15,13 +15,17 @@
<li class="breadcrumb-item active">{{ _('Settings') }}</li> <li class="breadcrumb-item active">{{ _('Settings') }}</li>
</ol> </ol>
</nav> </nav>
{% if community %}
{% include "community/_community_moderation_nav.html" %}
{% endif %}
<h1 class="mt-2"> <h1 class="mt-2">
{% if community %} {% if community %}
{{ _('Edit community') }} {{ _('Edit %(community)s', community=community.display_name()) }}
{% else %} {% else %}
{{ _('Create community') }} {{ _('Create community') }}
{% endif %} {% endif %}
</h1> </h1>
<p>{{ _('Edit and configure this community') }}</p>
<form method="post" enctype="multipart/form-data" id="add_local_community_form" role="form"> <form method="post" enctype="multipart/form-data" id="add_local_community_form" role="form">
{{ form.csrf_token() }} {{ form.csrf_token() }}
{{ render_field(form.title) }} {{ render_field(form.title) }}
@ -48,10 +52,12 @@
{{ render_field(form.submit) }} {{ render_field(form.submit) }}
</div> </div>
<div class="col-auto"> <div class="col-auto">
<a class="btn btn-outline-secondary" href="{{ url_for('community.community_mod_list', community_id=community.id) }}">{{ _('Moderators') }}</a> {% if community.is_local() and (community.is_owner() or current_user.is_admin()) %}
</div> <p><a class="btn btn-primary btn-warning" href="{{ url_for('community.community_delete', community_id=community.id) }}" rel="nofollow">Delete community</a></p>
{% endif %}
</div> </div>
</form> </form>
</div> </div>
</div> </div>

View file

@ -16,10 +16,12 @@
<li class="breadcrumb-item active">{{ _('Moderators') }}</li> <li class="breadcrumb-item active">{{ _('Moderators') }}</li>
</ol> </ol>
</nav> </nav>
{% include "community/_community_moderation_nav.html" %}
<div class="row"> <div class="row">
<div class="col-12 col-md-10"> <div class="col-12 col-md-10">
<h1 class="mt-2">{{ _('Moderators for %(community)s', community=community.display_name()) }}</h1> <h1 class="mt-2">{{ _('Moderators for %(community)s', community=community.display_name()) }}</h1>
</div> </div>
<p>{{ _('See and change who moderates this community') }}</p>
<div class="col-12 col-md-2 text-right"> <div class="col-12 col-md-2 text-right">
<a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a> <a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a>
</div> </div>

View file

@ -15,16 +15,16 @@
<li class="breadcrumb-item active">{{ _('Moderation') }}</li> <li class="breadcrumb-item active">{{ _('Moderation') }}</li>
</ol> </ol>
</nav> </nav>
{% include "community/_community_moderation_nav.html" %}
<div class="row"> <div class="row">
<div class="col-12 col-md-10"> <div class="col-12 col-md-10">
<h1 class="mt-2">{{ _('Moderation of %(community)s', community=community.display_name()) }}</h1> <h1 class="mt-2">{{ _('Reports') }}</h1>
</div> </div>
<div class="col-12 col-md-2 text-right"> <div class="col-12 col-md-2 text-right">
<!-- <a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a> --> <!-- <a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a> -->
</div> </div>
</div> </div>
{% include "community/_community_moderation_nav.html" %} <p>{{ _('See and handle all reports made about %(community)s', community=community.display_name()) }}</p>
<h2>{{ _('Reports') }}</h2>
{% if reports.items %} {% if reports.items %}
<form method="get"> <form method="get">
<input type="search" name="search" value="{{ search }}"> <input type="search" name="search" value="{{ search }}">

View file

@ -15,16 +15,17 @@
<li class="breadcrumb-item active">{{ _('Moderation') }}</li> <li class="breadcrumb-item active">{{ _('Moderation') }}</li>
</ol> </ol>
</nav> </nav>
{% include "community/_community_moderation_nav.html" %}
<div class="row"> <div class="row">
<div class="col-12 col-md-10"> <div class="col-12 col-md-10">
<h1 class="mt-2">{{ _('Moderation of %(community)s', community=community.display_name()) }}</h1> <h1 class="mt-2">{{ _('Banned people') }}</h1>
</div> </div>
<div class="col-12 col-md-2 text-right"> <div class="col-12 col-md-2 text-right">
<!-- <a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a> --> <!-- <a class="btn btn-primary" href="{{ url_for('community.community_add_moderator', community_id=community.id) }}">{{ _('Add moderator') }}</a> -->
</div> </div>
</div> </div>
{% include "community/_community_moderation_nav.html" %} <p>{{ _('See and manage who is banned from %(community)s', community=community.display_name()) }}</p>
<h2>{{ _('Banned people') }}</h2> <h2></h2>
{% if banned_people %} {% if banned_people %}
<form method="get"> <form method="get">
<input type="search" name="search" value="{{ search }}"> <input type="search" name="search" value="{{ search }}">

View file

@ -159,7 +159,7 @@
{% if current_user.is_authenticated and (user_access('ban users', current_user.id) or user_access('manage users', current_user.id)) and user.id != current_user.id %} {% if current_user.is_authenticated and (user_access('ban users', current_user.id) or user_access('manage users', current_user.id)) and user.id != current_user.id %}
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<h2>{{ _('Crush') }}</h2> <h2>{{ _('Moderate user') }}</h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">