Repository: hydroshare/hydroshare

Issue:
Version messages are incorrect for some published resources
**Description of the bug**
The following resources have incorrect version messages.  I suspect this may relate to the changes/hotfix done to address #4605 

Go to 
https://www.hydroshare.org/resource/24f8275d882e4d40809ba901258c17ad/
At the top it says "An older version of this resource **DOI for this published resource is pending activation. is available**."  This makes no sense.  How can a resource be published, but the older version still have DOI pending.

In related resources it says
This resource updates and replaces a previous version. Rosenberg, D. E. (2022). Colorado River Basin Accounts: Provoke discussion about more flexible and sustainable operations, HydroShare, https://doi.org/10.4211/hs.f085afcf710744898f38b64c00e22a5b, **DOI for this published resource is pending activation.**

On the older resource it is indicated as being published, but at the top 
A newer version of this resource DOI for this published resource **is pending activation. is available that replaces this version.**
An older version of this resource https://doi.org/10.4211/hs.57ad7df425b84da2874e9c19e7b34aad is available.




Discussion:

Resolving patch:
diff --git a/hs_core/migrations/0063_auto_20220601_2014.py b/hs_core/migrations/0063_auto_20220601_2014.py
new file mode 100644
--- /dev/null
+++ b/hs_core/migrations/0063_auto_20220601_2014.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2022-06-01 20:14
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+def remove_pending_citations_from_relations(apps, schema_editor):
+    Relation = apps.get_model("hs_core", "Relation")
+    for relation in Relation.objects.all():
+        if relation.value:
+            sep = ', DOI for this published resource is pending activation'
+            head, _, _ = relation.value.partition(sep)
+            relation.value = head
+            relation.save()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('hs_core', '0062_auto_20220520_1449'),
+    ]
+
+    operations = [
+        migrations.RunPython(remove_pending_citations_from_relations),
+    ]
diff --git a/hs_core/models.py b/hs_core/models.py
--- a/hs_core/models.py
+++ b/hs_core/models.py
@@ -2426,7 +2426,7 @@ def get_custom_citation(self):
             return ''
         return str(self.metadata.citation.first())
 
-    def get_citation(self):
+    def get_citation(self, includePendingMessage=True):
         """Get citation or citations from resource metadata."""
 
         citation_str_lst = []
@@ -2474,7 +2474,7 @@ def get_citation(self):
 
         citation_str_lst.append(", HydroShare, {url}".format(url=hs_identifier.url))
 
-        if isPendingActivation:
+        if isPendingActivation and includePendingMessage:
             citation_str_lst.append(", DOI for this published resource is pending activation.")
 
         return ''.join(citation_str_lst)
diff --git a/hs_core/tasks.py b/hs_core/tasks.py
--- a/hs_core/tasks.py
+++ b/hs_core/tasks.py
@@ -499,8 +499,8 @@ def create_new_version_resource_task(ori_res_id, username, new_res_id=None):
             # element is copied over to this new version resource, needs to delete this element so
             # it can be created to link to its original resource correctly
             new_res.metadata.relations.all().filter(type=RelationTypes.isVersionOf).first().delete()
-
-        new_res.metadata.create_element('relation', type=RelationTypes.isVersionOf, value=ori_res.get_citation())
+        new_res.metadata.create_element('relation', type=RelationTypes.isVersionOf,
+                                        value=ori_res.get_citation(includePendingMessage=False))
 
         if ori_res.resource_type.lower() == "collectionresource":
             # clone contained_res list of original collection and add to new collection


Test patch: