Skip to content

Commit

Permalink
Merge pull request #3031 from internetarchive/featue/2107-no-more-sys…
Browse files Browse the repository at this point in the history
…tem-subject-protection

Don't protect deprecated system subjects
  • Loading branch information
cdrini committed Feb 18, 2020
2 parents 0780ee6 + d57a63a commit 0eecf29
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

logger = logging.getLogger("openlibrary.book")

SYSTEM_SUBJECTS = ["Accessible Book", "Lending Library", "In Library", "Protected DAISY"]


def get_solr():
base_url = "http://%s/solr" % config.plugin_worksearch.get('solr')
Expand Down Expand Up @@ -671,29 +669,8 @@ def read_subject(subjects):
# ignore empty authors
work.authors = [a for a in work.get('authors', []) if a.get('author', {}).get('key', '').strip()]

self._prevent_system_subjects_deletion(work)
return trim_doc(work)

def _prevent_system_subjects_deletion(self, work):
# Allow admins to modify system systems
user = accounts.get_current_user()
if user and user.is_admin():
return

# Note: work is the new work object from the formdata and self.work is the work doc from the database.
old_subjects = self.work and self.work.get("subjects") or []

# If condition is added to handle the possibility of bad data
set_old_subjects = set(s.lower() for s in old_subjects if isinstance(s, six.string_types))
set_new_subjects = set(s.lower() for s in work.subjects)

for s in SYSTEM_SUBJECTS:
# if a system subject has been removed
if s.lower() in set_old_subjects and s.lower() not in set_new_subjects:
work_key = self.work and self.work.key
logger.warn("Prevented removal of system subject %r from %s.", s, work_key)
work.subjects.append(s)

def _prevent_ocaid_deletion(self, edition):
# Allow admins to modify ocaid
user = accounts.get_current_user()
Expand Down

0 comments on commit 0eecf29

Please sign in to comment.