Repository: internetarchive/openlibrary

Issue:
Spamwords should not block librarian/admin edits
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->
Editing a record with existing spamwords (even when used legitimately) blocks edits from being saved.

### Evidence / Screenshot (if possible)

### Relevant url?
<!-- `https://openlibrary.org/...` -->
https://openlibrary.org/works/OL17513504W/Dvd_Extras_Include_Murder

### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ... https://openlibrary.org/works/OL17513504W/Dvd_Extras_Include_Murder
2. Do ...Try to save an edit.

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual: Error
* Expected: Edit should be saved. At least by librarians or admins.

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->
@mekarpeles 


Discussion:

Resolving patch:
diff --git a/openlibrary/plugins/upstream/addbook.py b/openlibrary/plugins/upstream/addbook.py
--- a/openlibrary/plugins/upstream/addbook.py
+++ b/openlibrary/plugins/upstream/addbook.py
@@ -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.'
             )
@@ -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.'
             )
@@ -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.'
             )
diff --git a/openlibrary/plugins/upstream/spamcheck.py b/openlibrary/plugins/upstream/spamcheck.py
--- a/openlibrary/plugins/upstream/spamcheck.py
+++ b/openlibrary/plugins/upstream/spamcheck.py
@@ -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):


Test patch: