better ban message #78

This commit is contained in:
rimu 2024-04-03 20:48:39 +13:00
parent 7dd5c61bc7
commit e6431584ab
4 changed files with 32 additions and 11 deletions

View file

@ -28,7 +28,7 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_
shorten_string, gibberish, community_membership, ap_datetime, \
request_etag_matches, return_304, instance_banned, can_create_post, can_upvote, can_downvote, user_filters_posts, \
joined_communities, moderating_communities, blocked_domains, mimetype_from_url, blocked_instances, \
community_moderators, communities_banned_from
community_moderators, communities_banned_from, show_ban_message
from feedgen.feed import FeedGenerator
from datetime import timezone, timedelta
@ -36,6 +36,8 @@ from datetime import timezone, timedelta
@bp.route('/add_local', methods=['GET', 'POST'])
@login_required
def add_local():
if current_user.banned:
return show_ban_message()
flash('PieFed is still being tested so hosting communities on piefed.social is not advised except for testing purposes.', 'warning')
form = AddCommunityForm()
if g.site.enable_nsfw is False:
@ -84,6 +86,8 @@ def add_local():
@bp.route('/add_remote', methods=['GET', 'POST'])
@login_required
def add_remote():
if current_user.banned:
return show_ban_message()
form = SearchRemoteCommunity()
new_community = None
if form.validate_on_submit():
@ -438,6 +442,8 @@ def join_then_add(actor):
@login_required
@validation_required
def add_post(actor):
if current_user.banned:
return show_ban_message()
community = actor_to_community(actor)
form = CreatePostForm()
if g.site.enable_nsfl is False:
@ -580,7 +586,7 @@ def add_post(actor):
form.notify_author.data = True
return render_template('community/add_post.html', title=_('Add post to community'), form=form, community=community,
markdown_editor=current_user.markdown_editor, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1',
markdown_editor=current_user.markdown_editor, low_bandwidth=False,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.id),
inoculation=inoculation[randint(0, len(inoculation) - 1)]
@ -622,6 +628,8 @@ def community_report(community_id: int):
@login_required
def community_edit(community_id: int):
from app.admin.util import topics_for_form
if current_user.banned:
return show_ban_message()
community = Community.query.get_or_404(community_id)
if community.is_owner() or current_user.is_admin():
form = EditCommunityForm()
@ -681,6 +689,8 @@ def community_edit(community_id: int):
@bp.route('/community/<int:community_id>/delete', methods=['GET', 'POST'])
@login_required
def community_delete(community_id: int):
if current_user.banned:
return show_ban_message()
community = Community.query.get_or_404(community_id)
if community.is_owner() or current_user.is_admin():
form = DeleteCommunityForm()
@ -704,6 +714,8 @@ def community_delete(community_id: int):
@bp.route('/community/<int:community_id>/moderators', methods=['GET', 'POST'])
@login_required
def community_mod_list(community_id: int):
if current_user.banned:
return show_ban_message()
community = Community.query.get_or_404(community_id)
if community.is_owner() or current_user.is_admin():
@ -720,6 +732,8 @@ def community_mod_list(community_id: int):
@bp.route('/community/<int:community_id>/moderators/add', methods=['GET', 'POST'])
@login_required
def community_add_moderator(community_id: int):
if current_user.banned:
return show_ban_message()
community = Community.query.get_or_404(community_id)
if community.is_owner() or current_user.is_admin():
form = AddModeratorForm()
@ -774,6 +788,8 @@ def community_add_moderator(community_id: int):
@bp.route('/community/<int:community_id>/moderators/remove/<int:user_id>', methods=['GET', 'POST'])
@login_required
def community_remove_moderator(community_id: int, user_id: int):
if current_user.banned:
return show_ban_message()
community = Community.query.get_or_404(community_id)
if community.is_owner() or current_user.is_admin():
@ -929,6 +945,8 @@ def community_notification(community_id: int):
@bp.route('/<actor>/moderate', methods=['GET'])
@login_required
def community_moderate(actor):
if current_user.banned:
return show_ban_message()
community = actor_to_community(actor)
if community is not None:

View file

@ -405,7 +405,7 @@ class Community(db.Model):
(or_(
CommunityMember.is_owner,
CommunityMember.is_moderator
))
)) & CommunityMember.is_banned == False
).all()
def is_moderator(self, user=None):

View file

@ -24,7 +24,7 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_
shorten_string, markdown_to_text, gibberish, ap_datetime, return_304, \
request_etag_matches, ip_address, user_ip_banned, instance_banned, can_downvote, can_upvote, post_ranking, \
reply_already_exists, reply_is_just_link_to_gif_reaction, confidence, moderating_communities, joined_communities, \
blocked_instances, blocked_domains, community_moderators, blocked_phrases
blocked_instances, blocked_domains, community_moderators, blocked_phrases, show_ban_message
def show_post(post_id: int):
@ -456,11 +456,7 @@ def continue_discussion(post_id, comment_id):
@login_required
def add_reply(post_id: int, comment_id: int):
if current_user.banned:
flash('You have been banned.', 'error')
logout_user()
resp = make_response(redirect(url_for('main.index')))
resp.set_cookie('sesion', '17489047567495', expires=datetime(year=2099, month=12, day=30))
return resp
return show_ban_message()
post = Post.query.get_or_404(post_id)
if not post.comments_enabled:

View file

@ -18,8 +18,8 @@ import warnings
warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning)
import requests
import os
from flask import current_app, json, redirect, url_for, request, make_response, Response, g
from flask_login import current_user
from flask import current_app, json, redirect, url_for, request, make_response, Response, g, flash
from flask_login import current_user, logout_user
from sqlalchemy import text, or_
from wtforms.fields import SelectField, SelectMultipleField
from wtforms.widgets import Select, html_params, ListWidget, CheckboxInput
@ -829,3 +829,10 @@ def remove_tracking_from_link(url):
else:
return url
def show_ban_message():
flash('You have been banned.', 'error')
logout_user()
resp = make_response(redirect(url_for('main.index')))
resp.set_cookie('sesion', '17489047567495', expires=datetime(year=2099, month=12, day=30))
return resp