Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #12526] Expose the metadata_uploaded_preserve property over th… #12527

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ class Meta:
"thumbnail_url",
"links",
"link",
"metadata_uploaded_preserve",
# TODO
# csw_typename, csw_schema, csw_mdsource, csw_insert_date, csw_type, csw_anytext, csw_wkt_geometry,
# metadata_uploaded, metadata_uploaded_preserve, metadata_xml,
Expand Down
27 changes: 27 additions & 0 deletions geonode/base/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
create_single_geoapp,
)
from geonode.resource.api.tasks import resouce_service_dispatcher
from guardian.shortcuts import assign_perm

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -2725,6 +2726,32 @@ def test_api_should_filter_by_advertised_param(self):

Dataset.objects.update(advertised=True)

def test_metadata_uploaded_preserve_can_be_updated(self):
doc = Document.objects.first()
user = get_user_model().objects.get(username="bobby")
url = reverse("base-resources-detail", kwargs={"pk": doc.pk})
self.assertTrue(self.client.login(username="bobby", password="bob"))

payload = json.dumps({"metadata_uploaded_preserve": True})
# should return 403 since bobby doesn't have the perms to update the metadata
# on this resource
response = self.client.patch(url, data=payload, content_type="application/json")
self.assertEqual(403, response.status_code)
doc.refresh_from_db()
# the original value should be kept
self.assertFalse(doc.metadata_uploaded_preserve)

# let's give to bobby the perms for update the metadata
assign_perm("base.change_resourcebase_metadata", user, doc.get_self_resource())

# let's call the API again
response = self.client.patch(url, data=payload, content_type="application/json")
self.assertEqual(200, response.status_code)
doc.refresh_from_db()
# the value should be updated
self.assertTrue(doc.metadata_uploaded_preserve)
self.assertTrue(response.json()["resource"]["metadata_uploaded_preserve"])


class TestExtraMetadataBaseApi(GeoNodeBaseTestSupport):
def setUp(self):
Expand Down
Loading