From 48a02cfff209afcf921042256e77fdb889658b42 Mon Sep 17 00:00:00 2001 From: Ramakrishna Sakhamuru Date: Wed, 21 Aug 2024 10:21:01 +0530 Subject: [PATCH 1/2] Use admin account to update the article --- portality/tasks/harvester_helpers/workflow.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/portality/tasks/harvester_helpers/workflow.py b/portality/tasks/harvester_helpers/workflow.py index d99aa3c423..4ce670c7c0 100644 --- a/portality/tasks/harvester_helpers/workflow.py +++ b/portality/tasks/harvester_helpers/workflow.py @@ -7,6 +7,16 @@ from portality.lib.dataobj import DataObjException +SYSTEM_ACCOUNT = { + "email": "steve@cottagelabs.com", + "name": "harvest_background_job", + "role": ['admin'], + "id": "harvest_background_job" +} + +sys_acc = Account(**SYSTEM_ACCOUNT) + + class DefaultLogger(object): def __init__(self): self._log = [] @@ -110,12 +120,13 @@ def process_article(self, account_id, article): Report.record_error((article.get_identifier("doi") or "< DOI MISSING >") + " - " + str(e)) return False - acc = Account.pull(account_id) try: - id = ArticlesCrudApi.create(article.data, acc).id + # Use the admin account to have sufficient rights to update full text or doi. + # Related github issue #3857 + id = ArticlesCrudApi.create(article.data, sys_acc).id except Exception as e: self._write_to_logger("Article caused DOAJException: {m} ... skipping".format(m=e)) Report.record_error((article.get_identifier("doi") or "< DOI MISSING >")) return False - self._write_to_logger("Created article in DOAJ for Account:{x} with ID: {y}".format(x=account_id, y=id)) + self._write_to_logger("Created article in DOAJ for Account:{x} with ID: {y}".format(x=sys_acc.id, y=id)) return True From 376974d188cb891a90d133b6816625c85fc6825c Mon Sep 17 00:00:00 2001 From: Ramakrishna Sakhamuru Date: Fri, 15 Nov 2024 13:46:26 +0530 Subject: [PATCH 2/2] Added fixes to allow admin to make changes --- portality/bll/services/article.py | 6 +++--- portality/tasks/harvester_helpers/workflow.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/portality/bll/services/article.py b/portality/bll/services/article.py index b5e829cd24..0febeb63a3 100644 --- a/portality/bll/services/article.py +++ b/portality/bll/services/article.py @@ -126,13 +126,13 @@ def _prepare_update_admin(article, duplicate, update_article_id, merge_duplicate is_update = 0 if duplicate is not None: - if duplicate.id != update_article_id: + if update_article_id is not None and duplicate.id != update_article_id: # it means that doi or ft url has been changed so that it duplicates existing article raise exceptions.DuplicateArticleException(Messages.EXCEPTION_IDENTIFIER_CHANGE_CLASH) elif merge_duplicate: is_update += 1 article.merge(duplicate) - elif merge_duplicate: # requested to update article has both url and doi changed to new values - no duplicate detected + elif update_article_id is not None and merge_duplicate: # requested to update article has both url and doi changed to new values - no duplicate detected is_update += 1 art = models.Article.pull(update_article_id) article.merge(art) @@ -227,7 +227,7 @@ def create_article(self, article, account, duplicate_check=True, merge_duplicate # ~~!ArticleCreate:Feature->ArticleDeduplication:Feature~~ duplicate = self.get_duplicate(article) try: - if account.has_role("admin") and update_article_id is not None: # is update_article_id is None then treat as normal publisher upload + if account.has_role("admin"): # is update_article_id is None then treat as normal publisher upload # for testing by admin is_update = self._prepare_update_admin(article, duplicate, update_article_id, merge_duplicate) else: diff --git a/portality/tasks/harvester_helpers/workflow.py b/portality/tasks/harvester_helpers/workflow.py index 4ce670c7c0..1d7147dcb3 100644 --- a/portality/tasks/harvester_helpers/workflow.py +++ b/portality/tasks/harvester_helpers/workflow.py @@ -8,7 +8,7 @@ SYSTEM_ACCOUNT = { - "email": "steve@cottagelabs.com", + "email": app.config['ADMIN_EMAIL'], "name": "harvest_background_job", "role": ['admin'], "id": "harvest_background_job"