mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
ensure local communities have lowercase machine name
This commit is contained in:
parent
7805563b0f
commit
76d228f5fa
6 changed files with 28 additions and 31 deletions
|
@ -12,7 +12,7 @@ from app.models import Community, User
|
|||
class SiteProfileForm(FlaskForm):
|
||||
name = StringField(_l('Site Name'))
|
||||
description = StringField(_l('Tagline'))
|
||||
icon = FileField(_('Icon'), validators=[
|
||||
icon = FileField(_l('Icon'), validators=[
|
||||
FileAllowed(['jpg', 'jpeg', 'png', 'webp'], 'Images only!')
|
||||
])
|
||||
sidebar = TextAreaField(_l('Sidebar'))
|
||||
|
@ -52,8 +52,8 @@ class EditCommunityForm(FlaskForm):
|
|||
title = StringField(_l('Title'), validators=[DataRequired()])
|
||||
url = StringField(_l('Url'), validators=[DataRequired()])
|
||||
description = TextAreaField(_l('Description'))
|
||||
icon_file = FileField(_('Icon image'))
|
||||
banner_file = FileField(_('Banner image'))
|
||||
icon_file = FileField(_l('Icon image'))
|
||||
banner_file = FileField(_l('Banner image'))
|
||||
rules = TextAreaField(_l('Rules'))
|
||||
nsfw = BooleanField(_l('Porn community'))
|
||||
banned = BooleanField(_l('Banned - no new posts accepted'))
|
||||
|
@ -82,18 +82,18 @@ 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'), validators=[Optional(), Length(min=3, max=512)])
|
||||
posting_warning = StringField(_l('Posting warning'), validators=[Optional(), Length(min=3, max=512)])
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
||||
def validate(self, extra_validators=None):
|
||||
if not super().validate():
|
||||
return False
|
||||
if self.url.data.strip() == '':
|
||||
self.url.errors.append(_('Url is required.'))
|
||||
self.url.errors.append(_l('Url is required.'))
|
||||
return False
|
||||
else:
|
||||
if '-' in self.url.data.strip():
|
||||
self.url.errors.append(_('- cannot be in Url. Use _ instead?'))
|
||||
self.url.errors.append(_l('- cannot be in Url. Use _ instead?'))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class RegistrationForm(FlaskForm):
|
|||
password2 = PasswordField(
|
||||
_l('Repeat password'), validators=[DataRequired(),
|
||||
EqualTo('password')])
|
||||
question = StringField(_('Why would you like to join this site?'), validators=[DataRequired(), Length(min=1, max=512)])
|
||||
question = StringField(_l('Why would you like to join this site?'), validators=[DataRequired(), Length(min=1, max=512)])
|
||||
recaptcha = RecaptchaField()
|
||||
|
||||
submit = SubmitField(_l('Register'))
|
||||
|
|
|
@ -18,8 +18,8 @@ class AddCommunityForm(FlaskForm):
|
|||
community_name = StringField(_l('Name'), validators=[DataRequired()])
|
||||
url = StringField(_l('Url'))
|
||||
description = TextAreaField(_l('Description'))
|
||||
icon_file = FileField(_('Icon image'))
|
||||
banner_file = FileField(_('Banner image'))
|
||||
icon_file = FileField(_l('Icon image'))
|
||||
banner_file = FileField(_l('Banner image'))
|
||||
rules = TextAreaField(_l('Rules'))
|
||||
nsfw = BooleanField('NSFW')
|
||||
local_only = BooleanField('Local only')
|
||||
|
@ -29,11 +29,15 @@ class AddCommunityForm(FlaskForm):
|
|||
if not super().validate():
|
||||
return False
|
||||
if self.url.data.strip() == '':
|
||||
self.url.errors.append(_('Url is required.'))
|
||||
self.url.errors.append(_l('Url is required.'))
|
||||
return False
|
||||
else:
|
||||
if '-' in self.url.data.strip():
|
||||
self.url.errors.append(_('- cannot be in Url. Use _ instead?'))
|
||||
self.url.errors.append(_l('- cannot be in Url. Use _ instead?'))
|
||||
return False
|
||||
community = Community.query.filter(Community.name == self.url.data.strip().lower(), Community.ap_id == None).first()
|
||||
if community is not None:
|
||||
self.url.errors.append(_l('A community with this url already exists.'))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -41,8 +45,8 @@ class AddCommunityForm(FlaskForm):
|
|||
class EditCommunityForm(FlaskForm):
|
||||
title = StringField(_l('Title'), validators=[DataRequired()])
|
||||
description = TextAreaField(_l('Description'))
|
||||
icon_file = FileField(_('Icon image'))
|
||||
banner_file = FileField(_('Banner image'))
|
||||
icon_file = FileField(_l('Icon image'))
|
||||
banner_file = FileField(_l('Banner image'))
|
||||
rules = TextAreaField(_l('Rules'))
|
||||
nsfw = BooleanField(_l('Porn community'))
|
||||
local_only = BooleanField(_l('Only accept posts from current instance'))
|
||||
|
@ -111,7 +115,7 @@ class CreateLinkForm(FlaskForm):
|
|||
def validate(self, extra_validators=None) -> bool:
|
||||
domain = domain_from_url(self.link_url.data, create=False)
|
||||
if domain and domain.banned:
|
||||
self.link_url.errors.append(_("Links to %(domain)s are not allowed.", domain=domain.name))
|
||||
self.link_url.errors.append(_l("Links to %(domain)s are not allowed.", domain=domain.name))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -131,7 +135,7 @@ class CreateVideoForm(FlaskForm):
|
|||
def validate(self, extra_validators=None) -> bool:
|
||||
domain = domain_from_url(self.video_url.data, create=False)
|
||||
if domain and domain.banned:
|
||||
self.video_url.errors.append(_("Videos from %(domain)s are not allowed.", domain=domain.name))
|
||||
self.video_url.errors.append(_l("Videos from %(domain)s are not allowed.", domain=domain.name))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -141,7 +145,7 @@ class CreateImageForm(FlaskForm):
|
|||
image_title = StringField(_l('Title'), validators=[DataRequired(), 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)], render_kw={'rows': 5})
|
||||
image_file = FileField(_('Image'), validators=[DataRequired()])
|
||||
image_file = FileField(_l('Image'), validators=[DataRequired()])
|
||||
sticky = BooleanField(_l('Sticky'))
|
||||
nsfw = BooleanField(_l('NSFW'))
|
||||
nsfl = BooleanField(_l('Gore/gross'))
|
||||
|
@ -167,7 +171,7 @@ class CreateImageForm(FlaskForm):
|
|||
if self.communities:
|
||||
community = Community.query.get(self.communities.data)
|
||||
if community.is_local() and g.site.allow_local_image_posts is False:
|
||||
self.communities.errors.append(_('Images cannot be posted to local communities.'))
|
||||
self.communities.errors.append(_l('Images cannot be posted to local communities.'))
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ from app.community.forms import SearchRemoteCommunity, CreateDiscussionForm, Cre
|
|||
ReportCommunityForm, \
|
||||
DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm, \
|
||||
EscalateReportForm, ResolveReportForm, CreateVideoForm
|
||||
from app.community.util import search_for_community, community_url_exists, actor_to_community, \
|
||||
from app.community.util import search_for_community, actor_to_community, \
|
||||
opengraph_parse, url_to_thumbnail_file, save_post, save_icon_file, save_banner_file, send_to_remote_instance, \
|
||||
delete_post_from_community, delete_post_reply_from_community
|
||||
from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LINK, POST_TYPE_ARTICLE, POST_TYPE_IMAGE, \
|
||||
|
@ -43,16 +43,14 @@ from datetime import timezone, timedelta
|
|||
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:
|
||||
form.nsfw.render_kw = {'disabled': True}
|
||||
|
||||
if form.validate_on_submit() and not community_url_exists(form.url.data):
|
||||
# todo: more intense data validation
|
||||
if form.validate_on_submit():
|
||||
if form.url.data.strip().lower().startswith('/c/'):
|
||||
form.url.data = form.url.data[3:]
|
||||
form.url.data = slugify(form.url.data.strip(), separator='_')
|
||||
form.url.data = slugify(form.url.data.strip(), separator='_').lower()
|
||||
private_key, public_key = RsaKeys.generate_keypair()
|
||||
community = Community(title=form.community_name.data, name=form.url.data, description=form.description.data,
|
||||
rules=form.rules.data, nsfw=form.nsfw.data, private_key=private_key,
|
||||
|
|
|
@ -167,11 +167,6 @@ def retrieve_mods_and_backfill(community_id: int):
|
|||
db.session.commit()
|
||||
|
||||
|
||||
def community_url_exists(url) -> bool:
|
||||
community = Community.query.filter(Community.ap_profile_id == url.lower()).first()
|
||||
return community is not None
|
||||
|
||||
|
||||
def actor_to_community(actor) -> Community:
|
||||
actor = actor.strip()
|
||||
if '@' in actor:
|
||||
|
|
|
@ -16,8 +16,8 @@ class ProfileForm(FlaskForm):
|
|||
render_kw={"autocomplete": 'new-password'})
|
||||
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)], render_kw={'rows': 5})
|
||||
matrixuserid = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)], render_kw={'autocomplete': 'off'})
|
||||
profile_file = FileField(_('Avatar image'))
|
||||
banner_file = FileField(_('Top banner image'))
|
||||
profile_file = FileField(_l('Avatar image'))
|
||||
banner_file = FileField(_l('Top banner image'))
|
||||
bot = BooleanField(_l('This profile is a bot'))
|
||||
submit = SubmitField(_l('Save profile'))
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ProfileForm(FlaskForm):
|
|||
|
||||
def validate_matrix_user_id(self, matrix_user_id):
|
||||
if not matrix_user_id.data.strip().startswith('@'):
|
||||
raise ValidationError(_('Matrix user ids start with @'))
|
||||
raise ValidationError(_l('Matrix user ids start with @'))
|
||||
|
||||
|
||||
class SettingsForm(FlaskForm):
|
||||
|
@ -40,7 +40,7 @@ class SettingsForm(FlaskForm):
|
|||
searchable = BooleanField(_l('Show profile in user list'))
|
||||
indexable = BooleanField(_l('My posts appear in search results'))
|
||||
manually_approves_followers = BooleanField(_l('Manually approve followers'))
|
||||
import_file = FileField(_('Import community subscriptions and user blocks from Lemmy'))
|
||||
import_file = FileField(_l('Import community subscriptions and user blocks from Lemmy'))
|
||||
sorts = [('hot', _l('Hot')),
|
||||
('top', _l('Top')),
|
||||
('new', _l('New')),
|
||||
|
|
Loading…
Add table
Reference in a new issue