Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override spam checks when adding or editing books #6419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def POST(self):
_test="false",
)

if spamcheck.is_spam(i):
if spamcheck.is_spam(i, allow_privileged_edits=True):
return render_template(
"message.html", "Oops", 'Something went wrong. Please try again later.'
)
Expand Down Expand Up @@ -837,7 +837,7 @@ def GET(self, key):
def POST(self, key):
i = web.input(v=None, _method="GET")

if spamcheck.is_spam():
if spamcheck.is_spam(allow_privileged_edits=True):
return render_template(
"message.html", "Oops", 'Something went wrong. Please try again later.'
)
Expand Down Expand Up @@ -907,7 +907,7 @@ def GET(self, key):
def POST(self, key):
i = web.input(v=None, _method="GET")

if spamcheck.is_spam():
if spamcheck.is_spam(allow_privileged_edits=True):
return render_template(
"message.html", "Oops", 'Something went wrong. Please try again later.'
)
Expand Down
12 changes: 8 additions & 4 deletions openlibrary/plugins/upstream/spamcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ def _update_spam_doc(**kwargs):
web.ctx.site.store["spamwords"] = doc


def is_spam(i=None):
def is_spam(i=None, allow_privileged_edits=False):
user = web.ctx.site.get_user()

# Prevent deleted users from making edits.
if user and user.type.key == '/type/delete':
return True
if user:
# Allow admins and librarians to make edits:
if allow_privileged_edits and (user.is_admin() or user.is_librarian()):
return False
# Prevent deleted users from making edits:
if user.type.key == '/type/delete':
return True

email = user and user.get_email() or ""
if is_spam_email(email):
Expand Down