From e8a64bcf881adb2b9c877e5fb4f0029d9b616d14 Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Thu, 19 Oct 2023 17:10:19 +0200 Subject: [PATCH 1/5] Fixes #11578: align geoapp metadata update to other resources --- geonode/geoapps/views.py | 31 +++++++++++++++++++------------ geonode/settings.py | 3 +++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/geonode/geoapps/views.py b/geonode/geoapps/views.py index 788dcaccbe1..69d53410e72 100644 --- a/geonode/geoapps/views.py +++ b/geonode/geoapps/views.py @@ -327,21 +327,15 @@ def geoapp_metadata( geoapp_form.cleaned_data.pop("linked_resources") geoapp_obj = geoapp_form.instance + geoapp_obj.keywords.clear() + geoapp_obj.keywords.add(*new_keywords) + geoapp_obj.regions.clear() + geoapp_obj.regions.add(*new_regions) + geoapp_obj.category = new_category _vals = dict(**geoapp_form.cleaned_data, **additional_vals) _vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL}) - resource_manager.update( - geoapp_obj.uuid, - instance=geoapp_obj, - keywords=new_keywords, - regions=new_regions, - vals=_vals, - notify=True, - extra_metadata=json.loads(extra_metadata), - ) - resource_manager.set_thumbnail(geoapp_obj.uuid, instance=geoapp_obj, overwrite=False) - register_event(request, EventType.EVENT_CHANGE_METADATA, geoapp_obj) if not ajax: return HttpResponseRedirect(hookset.geoapp_detail_url(geoapp_obj)) @@ -373,7 +367,20 @@ def geoapp_metadata( if any([x in geoapp_form.changed_data for x in ["is_approved", "is_published"]]): vals["is_approved"] = geoapp_form.cleaned_data.get("is_approved", geoapp_obj.is_approved) vals["is_published"] = geoapp_form.cleaned_data.get("is_published", geoapp_obj.is_published) - resource_manager.update(geoapp_obj.uuid, instance=geoapp_obj, notify=True, vals=vals) + else: + vals.pop("is_approved", None) + vals.pop("is_published", None) + + resource_manager.update( + geoapp_obj.uuid, + instance=geoapp_obj, + notify=True, + vals=vals, + extra_metadata=json.loads(extra_metadata), + ) + + resource_manager.set_thumbnail(geoapp_obj.uuid, instance=geoapp_obj, overwrite=False) + return HttpResponse(json.dumps({"message": message})) elif request.method == "POST" and ( not geoapp_form.is_valid() or not category_form.is_valid() or not tkeywords_form.is_valid() diff --git a/geonode/settings.py b/geonode/settings.py index eae71d843fa..873444f1e16 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -2361,3 +2361,6 @@ def get_geonode_catalogue_service(): DEFAULT_DATASET_DOWNLOAD_HANDLER = "geonode.layers.download_handler.DatasetDownloadHandler" DATASET_DOWNLOAD_HANDLERS = ast.literal_eval(os.getenv("DATASET_DOWNLOAD_HANDLERS", "[]")) + +DEFAULT_ANONYMOUS_VIEW_PERMISSION = False +DEFAULT_ANONYMOUS_DOWNLOAD_PERMISSION = False From 1a53b0ae9a77d0aabf991c9d3d649b0e490ce0e5 Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Thu, 19 Oct 2023 17:11:07 +0200 Subject: [PATCH 2/5] Fixes #11578: align geoapp metadata update to other resources --- geonode/settings.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/geonode/settings.py b/geonode/settings.py index 873444f1e16..eae71d843fa 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -2361,6 +2361,3 @@ def get_geonode_catalogue_service(): DEFAULT_DATASET_DOWNLOAD_HANDLER = "geonode.layers.download_handler.DatasetDownloadHandler" DATASET_DOWNLOAD_HANDLERS = ast.literal_eval(os.getenv("DATASET_DOWNLOAD_HANDLERS", "[]")) - -DEFAULT_ANONYMOUS_VIEW_PERMISSION = False -DEFAULT_ANONYMOUS_DOWNLOAD_PERMISSION = False From 29da59a89fc953f7e48cb43b4e9c09916ebf41e7 Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Thu, 19 Oct 2023 17:12:12 +0200 Subject: [PATCH 3/5] Fixes #11578: align geoapp metadata update to other resources --- geonode/geoapps/views.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/geonode/geoapps/views.py b/geonode/geoapps/views.py index 69d53410e72..4799536871a 100644 --- a/geonode/geoapps/views.py +++ b/geonode/geoapps/views.py @@ -327,11 +327,6 @@ def geoapp_metadata( geoapp_form.cleaned_data.pop("linked_resources") geoapp_obj = geoapp_form.instance - geoapp_obj.keywords.clear() - geoapp_obj.keywords.add(*new_keywords) - geoapp_obj.regions.clear() - geoapp_obj.regions.add(*new_regions) - geoapp_obj.category = new_category _vals = dict(**geoapp_form.cleaned_data, **additional_vals) _vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL}) @@ -374,6 +369,8 @@ def geoapp_metadata( resource_manager.update( geoapp_obj.uuid, instance=geoapp_obj, + keywords=new_keywords, + regions=new_regions, notify=True, vals=vals, extra_metadata=json.loads(extra_metadata), From 2e2fe1603d15124d74a5d0018795da8b1f3b25ce Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Mon, 23 Oct 2023 18:20:50 +0200 Subject: [PATCH 4/5] Fixes #11578: fix broken tests --- geonode/geoapps/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/geonode/geoapps/views.py b/geonode/geoapps/views.py index 4799536871a..91930a90c9e 100644 --- a/geonode/geoapps/views.py +++ b/geonode/geoapps/views.py @@ -314,7 +314,7 @@ def geoapp_metadata( geoapp_form.cleaned_data.pop("ptype") - additional_vals = dict( + vals = dict( poc=new_poc or geoapp_obj.poc, metadata_author=new_author or geoapp_obj.metadata_author, category=new_category, @@ -328,8 +328,7 @@ def geoapp_metadata( geoapp_obj = geoapp_form.instance - _vals = dict(**geoapp_form.cleaned_data, **additional_vals) - _vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL}) + vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL}) register_event(request, EventType.EVENT_CHANGE_METADATA, geoapp_obj) if not ajax: @@ -356,7 +355,6 @@ def geoapp_metadata( tb = traceback.format_exc() logger.error(tb) - vals = {} if "group" in geoapp_form.changed_data: vals["group"] = geoapp_form.cleaned_data.get("group") if any([x in geoapp_form.changed_data for x in ["is_approved", "is_published"]]): From 0020b4f75d96e8e0ef5d411a967c619e6f8a14d3 Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Tue, 24 Oct 2023 10:14:27 +0200 Subject: [PATCH 5/5] fix black format --- geonode/geoapps/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/geonode/geoapps/views.py b/geonode/geoapps/views.py index 5635966e628..f83457ae67e 100644 --- a/geonode/geoapps/views.py +++ b/geonode/geoapps/views.py @@ -292,7 +292,6 @@ def geoapp_metadata( geoapp_form.save_linked_resources() geoapp_form.cleaned_data.pop("linked_resources") - vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL}) register_event(request, EventType.EVENT_CHANGE_METADATA, geoapp_obj)