diff --git a/geonode/layers/api/tests.py b/geonode/layers/api/tests.py index 79b4330977b..ed72c5053a5 100644 --- a/geonode/layers/api/tests.py +++ b/geonode/layers/api/tests.py @@ -660,7 +660,7 @@ def test_valid_metadata_file_with_different_uuid(self): f = open(self.exml_path, "r") put_data = {"metadata_file": f} response = self.client.put(url, data=put_data) - self.assertEqual(500, response.status_code) + self.assertEqual(200, response.status_code) def test_permissions_for_not_permitted_user(self): get_user_model().objects.create_user( diff --git a/geonode/layers/api/views.py b/geonode/layers/api/views.py index 218216a17bd..629367c3440 100644 --- a/geonode/layers/api/views.py +++ b/geonode/layers/api/views.py @@ -141,17 +141,16 @@ def metadata(self, request, pk=None, *args, **kwargs): dataset_uuid, vals, regions, keywords, _ = parse_metadata(open(metadata_file).read()) except Exception: raise InvalidMetadataException(detail="Unsupported metadata format") - if dataset_uuid and dataset.uuid != dataset_uuid: - raise InvalidMetadataException( - detail="The UUID identifier from the XML Metadata, is different from the one saved" - ) try: updated_dataset = update_resource(dataset, metadata_file, regions, keywords, vals) updated_dataset.save() # This also triggers the recreation of the XML metadata file according to the updated values except Exception: raise GeneralDatasetException(detail="Failed to update metadata") out["success"] = True - out["message"] = ["Metadata successfully updated"] + out_message = "Metadata successfully updated" + if dataset_uuid and dataset.uuid != dataset_uuid: + out_message += " The UUID identifier from the XML Metadata is different from the one saved" + out["message"] = [out_message] return Response(out) except Exception as e: raise e diff --git a/geonode/layers/templates/datasets/dataset_metadata_upload.html b/geonode/layers/templates/datasets/dataset_metadata_upload.html index 37a737436cd..ba0f8b011b7 100644 --- a/geonode/layers/templates/datasets/dataset_metadata_upload.html +++ b/geonode/layers/templates/datasets/dataset_metadata_upload.html @@ -62,6 +62,7 @@

{% trans "Files to be uploaded" %}

+
{% trans "WARNING" %}: {% trans "This will most probably overwrite the current metadata!" %}
{% trans "Clear" %} {% trans "Upload files" %}
diff --git a/geonode/layers/tests.py b/geonode/layers/tests.py index e9855de6e67..6366e69b503 100644 --- a/geonode/layers/tests.py +++ b/geonode/layers/tests.py @@ -984,9 +984,10 @@ def test_xml_should_update_the_dataset_with_the_expected_values(self): prev_dataset = Dataset.objects.get(typename="geonode:single_point") self.assertEqual(0, prev_dataset.keywords.count()) resp = self.client.post(reverse("dataset_upload"), params) - self.assertEqual(404, resp.status_code) + self.assertEqual(200, resp.status_code) self.assertEqual( - resp.json()["errors"], "The UUID identifier from the XML Metadata, is different from the one saved" + resp.json()["warning"], + "WARNING: The XML's UUID was ignored while updating this dataset's metadata because that UUID is already present in this system. The rest of the XML's metadata was applied.", ) def test_sld_should_raise_500_if_is_invalid(self): @@ -1034,10 +1035,10 @@ def test_sld_should_update_the_dataset_with_the_expected_values(self): self.assertIsNotNone(updated_dataset.styles.first()) self.assertEqual(layer.styles.first().sld_title, updated_dataset.styles.first().sld_title) - def test_xml_should_raise_an_error_if_the_uuid_is_changed(self): + def test_xml_should_not_raise_an_error_if_the_uuid_is_changed(self): """ If the UUID coming from the XML and the one saved in the DB are different - The system should raise an error + The system should not raise an error, instead it should simply update the values """ params = { "permissions": '{ "users": {"AnonymousUser": ["view_resourcebase"]} , "groups":{}}', @@ -1053,12 +1054,11 @@ def test_xml_should_raise_an_error_if_the_uuid_is_changed(self): prev_dataset = Dataset.objects.get(typename="geonode:single_point") self.assertEqual(0, prev_dataset.keywords.count()) resp = self.client.post(reverse("dataset_upload"), params) - self.assertEqual(404, resp.status_code) - expected = { - "success": False, - "errors": "The UUID identifier from the XML Metadata, is different from the one saved", - } - self.assertDictEqual(expected, resp.json()) + self.assertEqual(200, resp.status_code) + self.assertEqual( + resp.json()["warning"], + "WARNING: The XML's UUID was ignored while updating this dataset's metadata because that UUID is already present in this system. The rest of the XML's metadata was applied.", + ) def test_will_raise_exception_for_replace_vector_dataset_with_raster(self): layer = Dataset.objects.get(name="single_point") diff --git a/geonode/layers/views.py b/geonode/layers/views.py index cbb434d1879..1b73d95cba3 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -171,10 +171,6 @@ def dataset_upload_metadata(request): ) if layer: dataset_uuid, vals, regions, keywords, _ = parse_metadata(open(base_file).read()) - if dataset_uuid and layer.uuid != dataset_uuid: - out["success"] = False - out["errors"] = "The UUID identifier from the XML Metadata, is different from the one saved" - return HttpResponse(json.dumps(out), content_type="application/json", status=404) updated_dataset = update_resource(layer, base_file, regions, keywords, vals) updated_dataset.save() out["status"] = ["finished"] @@ -188,6 +184,11 @@ def dataset_upload_metadata(request): upload_session.save() status_code = 200 out["success"] = True + if dataset_uuid and layer.uuid != dataset_uuid: + out["warning"] = (" ").join( + "WARNING: The XML's UUID was ignored while updating this dataset's metadata because \ + that UUID is already present in this system. The rest of the XML's metadata was applied.".split() + ) return HttpResponse(json.dumps(out), content_type="application/json", status=status_code) else: out["success"] = False diff --git a/geonode/locale/en/LC_MESSAGES/django.po b/geonode/locale/en/LC_MESSAGES/django.po index 1e094b47828..8b75867f235 100644 --- a/geonode/locale/en/LC_MESSAGES/django.po +++ b/geonode/locale/en/LC_MESSAGES/django.po @@ -1168,6 +1168,9 @@ msgstr "Files to be uploaded" msgid "Is Upload Metadata XML Form" msgstr "Is Upload Metadata XML Form" +msgid "This will most probably overwrite the current metadata!" +msgstr "This will most probably overwrite the current metadata!" + msgid "Upload files" msgstr "Upload files" diff --git a/geonode/static/geonode/js/upload/LayerInfo.js b/geonode/static/geonode/js/upload/LayerInfo.js index 4d4c4385172..574776a8977 100644 --- a/geonode/static/geonode/js/upload/LayerInfo.js +++ b/geonode/static/geonode/js/upload/LayerInfo.js @@ -458,7 +458,15 @@ define(function (require, exports) { } catch (err) { // pass } - var info_message = gettext('Your ' + resourceType +' was successfully created.'); + var info_message = '' + var level = 'alert-success' + if (resp.warning){ + info_message = resp.warning + level = 'alert-warning' + } + else{ + info_message = gettext('Your ' + resourceType +' was successfully created.'); + } var a = '' + gettext(resourceType.capitalize() + ' Info') + '   '; if(resourceType == 'dataset') { // Only Layers have Metadata and SLD Upload features for the moment @@ -474,7 +482,7 @@ define(function (require, exports) { } self.logStatus({ msg: '

' + info_message + '
' + msg_col + '
' + a + '

', - level: 'alert-success', + level: level, empty: 'true' }); };