Repository: hydroshare/hydroshare

Issue:
"pending publication status" have been pending for YEARS
```
>>> for res in BaseResource.objects.filter(raccess__published=False, doi__contains='pending').all():
     print(f"{res.short_id}: {res.title}, {res.raccess.published_or_review_pending}")

d2d2aa2b02d94f10bde859aa2584a423: Blue Nile SWAT models setup using QSWAT Workflow v1.5.8 and QSWAT GUI, False
6923878ec11c4138a12cee1365d3fb8a: Conditioning digital elevation models for use in the evaluation of river networks and height above the nearest drainage for flood inundation mapping, False
4cda7a99dff04474867e336a9ccb7425: api-sd2, False
0be7f3c7b2044fba8f19bfb8e806f1c2: Data for clogging enhancement in rock fractures, False
```
https://www.hydroshare.org/resource/d2d2aa2b02d94f10bde859aa2584a423/
https://www.hydroshare.org/resource/6923878ec11c4138a12cee1365d3fb8a/
https://www.hydroshare.org/resource/4cda7a99dff04474867e336a9ccb7425/

Interesting to see that one of these res hasn't been edited since 2019
![image](https://user-images.githubusercontent.com/17934193/213777993-3009b33d-0b76-432e-920b-79ee552bf567.png)
So this means we have resources lingering with "pending publication status" that have been pending for YEARS...?

_Originally posted by @devincowan in https://github.com/hydroshare/hydroshare/issues/4956#issuecomment-1398777759_
            


Discussion:
we should also make sure that the PUBLISH button is not active when resource has "pending publication"
@ClaraCogswell I checked all three of these resources again just to be sure: confirmed that crossref has no record of publication requests.

So I manually reverted these resources to "Public" and it would be great if you can reach out to the owners and request that they re-submit for publication if that is still their intent. Thanks!
Will do today! Thanks!
Also since we don't know how these resources got into this state, I am going to add a periodic check so that we are notified should this occur again.
Good idea! Thank you!

@devincowan  This resource: https://www.hydroshare.org/resource/4cda7a99dff04474867e336a9ccb7425/
Appears to be potentially inappropriate for HydroShare, certainly not appropriately described to be published, one of the subject keywords is "Rice with eggs" in Portuguese. Could someone more familiar with API's let me know what is contained in this resource? I see 1 qgis file, but the other information here is suspicious to me. 

I won;t email them until we know, and if we find that it is not appropriate for HS I will email them letting htem know we will remove it, and if the content is appropriate I will email them letting them know they must improve their metadata
Thanks @ClaraCogswell good call, I don't think we need to reach out to the owner of https://www.hydroshare.org/resource/4cda7a99dff04474867e336a9ccb7425/ thanks
@devincowan is the move to remove it from HS then?
the contents of the res are a .shp that looks like a river on the Eastern edge of Bolivia
<img width="940" alt="image" src="https://user-images.githubusercontent.com/17934193/214138716-0e1b8607-a1a6-4e11-949a-7e7f05d170ad.png">

So to me, this looks like a resource that falls short of our publication standards, but might well have been a work in progress or a test of our system's capabilities. My vote would be to leave it active but you're correct that it does not meet the HIL standards...
Okay, We'll leave it, thanks for checking it out!

Resolving patch:
diff --git a/hs_core/hydroshare/resource.py b/hs_core/hydroshare/resource.py
--- a/hs_core/hydroshare/resource.py
+++ b/hs_core/hydroshare/resource.py
@@ -1104,6 +1104,7 @@ def publish_resource(user, pk):
         if not response.status_code == status.HTTP_200_OK:
             # resource metadata deposition failed from CrossRef - set failure flag to be retried in a
             # crontab celery task
+            logger.error(f"Received a {response.status_code} from Crossref while depositing metadata for res id {pk}")
             resource.doi = get_resource_doi(pk, 'failure')
             resource.save()
 
diff --git a/hs_core/tasks.py b/hs_core/tasks.py
--- a/hs_core/tasks.py
+++ b/hs_core/tasks.py
@@ -221,6 +221,12 @@ def manage_task_hourly():
             msg_lst.append("{res_id} does not have published date in its metadata.".format(
                 res_id=res.short_id))
 
+    pending_unpublished_resources = BaseResource.objects.filter(raccess__published=False,
+                                                                doi__contains='pending')
+    for res in pending_unpublished_resources:
+        msg_lst.append(f"{res.short_id} has pending in DOI but resource_acceess shows unpublished. "
+                       "This indicates an issue with the resource, please notify a developer")
+
     if msg_lst and not settings.DISABLE_TASK_EMAILS:
         email_msg = '\n'.join(msg_lst)
         subject = 'Notification of pending DOI deposition/activation of published resources'


Test patch: