Merge pull request #1900 from willhoh/main

Added check for bocked or pending domains. Fixes #1850
This commit is contained in:
Mouse Reeve 2022-02-04 12:11:41 -08:00 committed by GitHub
commit 0c3b6e6938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 30 deletions

View file

@ -1,6 +1,7 @@
""" using django model forms """
import datetime
from collections import defaultdict
from urllib.parse import urlparse
from django import forms
from django.forms import ModelForm, PasswordInput, widgets, ChoiceField
@ -227,6 +228,34 @@ class FileLinkForm(CustomForm):
model = models.FileLink
fields = ["url", "filetype", "availability", "book", "added_by"]
def clean(self):
"""make sure the domain isn't blocked or pending"""
cleaned_data = super().clean()
url = cleaned_data.get("url")
filetype = cleaned_data.get("filetype")
book = cleaned_data.get("book")
domain = urlparse(url).netloc
if models.LinkDomain.objects.filter(domain=domain).exists():
status = models.LinkDomain.objects.get(domain=domain).status
if status == "blocked":
# pylint: disable=line-too-long
self.add_error(
"url",
_(
"This domain is blocked. Please contact your administrator if you think this is an error."
),
)
elif models.FileLink.objects.filter(
url=url, book=book, filetype=filetype
).exists():
# pylint: disable=line-too-long
self.add_error(
"url",
_(
"This link with file type has already been added for this book. If it is not visible, the domain is still pending."
),
)
class EditionForm(CustomForm):
class Meta:

View file

@ -17,62 +17,70 @@ msgstr ""
"X-Crowdin-File: /[bookwyrm-social.bookwyrm] main/locale/en_US/LC_MESSAGES/django.po\n"
"X-Crowdin-File-ID: 1553\n"
#: bookwyrm/forms.py:365
#: bookwyrm/forms.py:239
msgid "Domain is blocked. Don't try this url again."
msgstr "Die Domäne ist blockiert. Versuchen Sie diese Url nicht mehr."
#: bookwyrm/forms.py:241
msgid "Domain already pending. Please try later."
msgstr "Die Domain ist bereits in Bearbeitung. Bitte versuchen Sie es später."
#: bookwyrm/forms.py:378
msgid "A user with this email already exists."
msgstr "Es existiert bereits ein Benutzer*inkonto mit dieser E-Mail-Adresse."
#: bookwyrm/forms.py:379
#: bookwyrm/forms.py:392
msgid "One Day"
msgstr "Ein Tag"
#: bookwyrm/forms.py:380
#: bookwyrm/forms.py:393
msgid "One Week"
msgstr "Eine Woche"
#: bookwyrm/forms.py:381
#: bookwyrm/forms.py:394
msgid "One Month"
msgstr "Ein Monat"
#: bookwyrm/forms.py:382
#: bookwyrm/forms.py:395
msgid "Does Not Expire"
msgstr "Läuft nicht ab"
#: bookwyrm/forms.py:386
#: bookwyrm/forms.py:399
#, python-brace-format
msgid "{i} uses"
msgstr "{i}-mal verwendbar"
#: bookwyrm/forms.py:387
#: bookwyrm/forms.py:400
msgid "Unlimited"
msgstr "Unbegrenzt"
#: bookwyrm/forms.py:489
#: bookwyrm/forms.py:502
msgid "List Order"
msgstr "Reihenfolge der Liste"
#: bookwyrm/forms.py:490
#: bookwyrm/forms.py:503
msgid "Book Title"
msgstr "Buchtitel"
#: bookwyrm/forms.py:491 bookwyrm/templates/shelf/shelf.html:155
#: bookwyrm/forms.py:504 bookwyrm/templates/shelf/shelf.html:155
#: bookwyrm/templates/shelf/shelf.html:187
#: bookwyrm/templates/snippets/create_status/review.html:32
msgid "Rating"
msgstr "Bewertung"
#: bookwyrm/forms.py:493 bookwyrm/templates/lists/list.html:177
#: bookwyrm/forms.py:506 bookwyrm/templates/lists/list.html:177
msgid "Sort By"
msgstr "Sortieren nach"
#: bookwyrm/forms.py:497
#: bookwyrm/forms.py:510
msgid "Ascending"
msgstr "Aufsteigend"
#: bookwyrm/forms.py:498
#: bookwyrm/forms.py:511
msgid "Descending"
msgstr "Absteigend"
#: bookwyrm/forms.py:511
#: bookwyrm/forms.py:524
msgid "Reading finish date cannot be before start date."
msgstr "Enddatum darf nicht vor dem Startdatum liegen."
@ -284,7 +292,7 @@ msgstr "Português Europeu (Portugiesisch)"
#: bookwyrm/settings.py:258
msgid "Swedish (Svenska)"
msgstr ""
msgstr "Swedish (Schwedisch)"
#: bookwyrm/settings.py:259
msgid "简体中文 (Simplified Chinese)"
@ -4677,4 +4685,3 @@ msgid "Load %(count)d unread status"
msgid_plural "Load %(count)d unread statuses"
msgstr[0] "Lade %(count)d ungelesene Statusmeldung"
msgstr[1] "Lade %(count)d ungelesene Statusmeldungen"

View file

@ -18,62 +18,70 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: bookwyrm/forms.py:365
#: bookwyrm/forms.py:239
msgid "Domain is blocked. Don't try this url again."
msgstr ""
#: bookwyrm/forms.py:241
msgid "Domain already pending. Please try later."
msgstr ""
#: bookwyrm/forms.py:378
msgid "A user with this email already exists."
msgstr ""
#: bookwyrm/forms.py:379
#: bookwyrm/forms.py:392
msgid "One Day"
msgstr ""
#: bookwyrm/forms.py:380
#: bookwyrm/forms.py:393
msgid "One Week"
msgstr ""
#: bookwyrm/forms.py:381
#: bookwyrm/forms.py:394
msgid "One Month"
msgstr ""
#: bookwyrm/forms.py:382
#: bookwyrm/forms.py:395
msgid "Does Not Expire"
msgstr ""
#: bookwyrm/forms.py:386
#: bookwyrm/forms.py:399
#, python-brace-format
msgid "{i} uses"
msgstr ""
#: bookwyrm/forms.py:387
#: bookwyrm/forms.py:400
msgid "Unlimited"
msgstr ""
#: bookwyrm/forms.py:489
#: bookwyrm/forms.py:502
msgid "List Order"
msgstr ""
#: bookwyrm/forms.py:490
#: bookwyrm/forms.py:503
msgid "Book Title"
msgstr ""
#: bookwyrm/forms.py:491 bookwyrm/templates/shelf/shelf.html:155
#: bookwyrm/forms.py:504 bookwyrm/templates/shelf/shelf.html:155
#: bookwyrm/templates/shelf/shelf.html:187
#: bookwyrm/templates/snippets/create_status/review.html:32
msgid "Rating"
msgstr ""
#: bookwyrm/forms.py:493 bookwyrm/templates/lists/list.html:177
#: bookwyrm/forms.py:506 bookwyrm/templates/lists/list.html:177
msgid "Sort By"
msgstr ""
#: bookwyrm/forms.py:497
#: bookwyrm/forms.py:510
msgid "Ascending"
msgstr ""
#: bookwyrm/forms.py:498
#: bookwyrm/forms.py:511
msgid "Descending"
msgstr ""
#: bookwyrm/forms.py:511
#: bookwyrm/forms.py:524
msgid "Reading finish date cannot be before start date."
msgstr ""