diff --git a/app/admin/forms.py b/app/admin/forms.py index 59abaac6..c8a4c503 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -81,6 +81,7 @@ class EditCommunityForm(FlaskForm): ('masonry', _l('Masonry')), ('masonry_wide', _l('Wide masonry'))] default_layout = SelectField(_l('Layout'), coerce=str, choices=layouts, validators=[Optional()]) + posting_warning = StringField(_('Posting warning')) submit = SubmitField(_l('Save')) def validate(self, extra_validators=None): diff --git a/app/admin/routes.py b/app/admin/routes.py index 2d3d2030..a54323f3 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -252,6 +252,7 @@ def admin_community_edit(community_id): community.content_retention = form.content_retention.data community.topic_id = form.topic.data if form.topic.data != 0 else None community.default_layout = form.default_layout.data + community.posting_warning = form.posting_warning.data icon_file = request.files['icon_file'] if icon_file and icon_file.filename != '': @@ -293,6 +294,7 @@ def admin_community_edit(community_id): form.content_retention.data = community.content_retention form.topic.data = community.topic_id if community.topic_id else None form.default_layout.data = community.default_layout + form.posting_warning.data = community.posting_warning return render_template('admin/edit_community.html', title=_('Edit community'), form=form, community=community, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), diff --git a/app/community/routes.py b/app/community/routes.py index eb9c3b54..3aea0ba1 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -504,6 +504,8 @@ def add_discussion_post(actor): else: form.communities.data = community.id form.notify_author.data = True + if community.posting_warning: + flash(community.posting_warning) return render_template('community/add_discussion_post.html', title=_('Add post to community'), form=form, community=community, markdown_editor=current_user.markdown_editor, low_bandwidth=False, actor=actor, diff --git a/app/models.py b/app/models.py index 07913593..dde588eb 100644 --- a/app/models.py +++ b/app/models.py @@ -65,6 +65,7 @@ class Instance(db.Model): gone_forever = db.Column(db.Boolean, default=False) # True once this instance is considered offline forever - never start trying again ip_address = db.Column(db.String(50)) trusted = db.Column(db.Boolean, default=False) + posting_warning = db.Column(db.String(512)) posts = db.relationship('Post', backref='instance', lazy='dynamic') post_replies = db.relationship('PostReply', backref='instance', lazy='dynamic') @@ -354,6 +355,7 @@ class Community(db.Model): content_retention = db.Column(db.Integer, default=-1) topic_id = db.Column(db.Integer, db.ForeignKey('topic.id'), index=True) default_layout = db.Column(db.String(15)) + posting_warning = db.Column(db.String(512)) ap_id = db.Column(db.String(255), index=True) ap_profile_id = db.Column(db.String(255), index=True) diff --git a/app/templates/admin/edit_community.html b/app/templates/admin/edit_community.html index 4909ff14..e30987b1 100644 --- a/app/templates/admin/edit_community.html +++ b/app/templates/admin/edit_community.html @@ -47,6 +47,7 @@ {{ render_field(form.content_retention) }} {{ render_field(form.topic) }} {{ render_field(form.default_layout) }} + {{ render_field(form.posting_warning) }} {% if not community.is_local() %} {% endif %} diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 2caa0f4a..8227d604 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -22,8 +22,8 @@ {% if post.community.ap_id and '@beehaw.org' in post.community.ap_id %}

{{ _('This post is hosted on beehaw.org which has higher standards of behaviour than most places. Be nice.') }}

{% endif %} - {% if post.community.ap_id and '@lemmy.ml' in post.community.ap_id %} -

{{ _('This post is hosted on lemmy.ml which will ban you for saying anything negative about China, Russia or Putin. Tread carefully.') }}

+ {% if post.community.posting_warning %} +

{{ post.community.posting_warning|safe }}

{% endif %} {{ render_form(form) }} {% if not low_bandwidth %} diff --git a/migrations/versions/944c5ae8f4ba_posting_warning.py b/migrations/versions/944c5ae8f4ba_posting_warning.py new file mode 100644 index 00000000..85437e1a --- /dev/null +++ b/migrations/versions/944c5ae8f4ba_posting_warning.py @@ -0,0 +1,38 @@ +"""posting warning + +Revision ID: 944c5ae8f4ba +Revises: 980966fba5f4 +Create Date: 2024-04-18 20:42:54.287260 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '944c5ae8f4ba' +down_revision = '980966fba5f4' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('community', schema=None) as batch_op: + batch_op.add_column(sa.Column('posting_warning', sa.String(length=512), nullable=True)) + + with op.batch_alter_table('instance', schema=None) as batch_op: + batch_op.add_column(sa.Column('posting_warning', sa.String(length=512), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('instance', schema=None) as batch_op: + batch_op.drop_column('posting_warning') + + with op.batch_alter_table('community', schema=None) as batch_op: + batch_op.drop_column('posting_warning') + + # ### end Alembic commands ###