Skip to content

Commit 1ac0076

Browse files
[Fixes #13011] Return edit data permissions for remote layers (#13027)
* [Fixes #13011] Return edit data permissions for remote layers * [Fixes #13011] Return edit data permissions for remote layers * Added comment to new permissions for remote layers --------- Co-authored-by: Giovanni Allegri <[email protected]>
1 parent 984328c commit 1ac0076

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

geonode/security/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,21 @@ def get_user_perms(self, user):
372372
def calculate_perms(instance, user):
373373
# To avoid circular import
374374
from geonode.base.models import Configuration
375+
from geonode.layers.models import Dataset
375376

376377
config = Configuration.load()
377378
ctype = ContentType.objects.get_for_model(instance)
378379
ctype_resource_base = ContentType.objects.get_for_model(instance.get_self_resource())
379380

380381
PERMISSIONS_TO_FETCH = VIEW_PERMISSIONS + DOWNLOAD_PERMISSIONS + ADMIN_PERMISSIONS + SERVICE_PERMISSIONS
381382
# include explicit permissions appliable to "subtype == 'vector'"
382-
if instance.subtype in ["vector", "vector_time"]:
383-
PERMISSIONS_TO_FETCH += DATASET_ADMIN_PERMISSIONS
384-
elif instance.subtype == "raster":
383+
384+
if instance.subtype == "raster":
385385
PERMISSIONS_TO_FETCH += DATASET_EDIT_STYLE_PERMISSIONS
386+
elif isinstance(instance.get_real_instance(), Dataset):
387+
# remote layers are included, since https://github.com/GeoNode/geonode/issues/13011
388+
# introduces an "optimistic" approach to editing remote layers
389+
PERMISSIONS_TO_FETCH += DATASET_ADMIN_PERMISSIONS
386390

387391
resource_perms = Permission.objects.filter(
388392
codename__in=PERMISSIONS_TO_FETCH, content_type_id__in=[ctype.id, ctype_resource_base.id]

geonode/security/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
DOWNLOADABLE_RESOURCES = ["dataset", "document"]
6969

70-
DATA_EDITABLE_RESOURCES_SUBTYPES = ["vector", "vector_time"]
70+
DATA_EDITABLE_RESOURCES_SUBTYPES = ["vector", "vector_time", "remote"]
7171

7272
DATA_STYLABLE_RESOURCES_SUBTYPES = ["raster", "vector", "vector_time"]
7373

geonode/security/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,23 @@ def test_admin_whitelisted_access_middleware(self):
17571757
middleware.process_request(request)
17581758
self.assertTrue(request.user.is_superuser)
17591759

1760+
def test_remote_dataset_must_have_change_dataset_data_permission(self):
1761+
"""
1762+
Ref GeoNode#13011
1763+
Remote dataset should have "change_dataset_data" permission
1764+
"""
1765+
dataset = create_single_dataset("remote_dataset")
1766+
dataset.subtype = "remote"
1767+
dataset.save()
1768+
url = reverse("datasets-detail", args=[dataset.id])
1769+
self.client.force_login(dataset.owner)
1770+
response = self.client.get(url)
1771+
1772+
perms = response.json().get("dataset", {}).get("perms", {})
1773+
self.assertNotEqual(perms, {})
1774+
1775+
self.assertIn("change_dataset_data", perms)
1776+
17601777

17611778
class SecurityRulesTests(TestCase):
17621779
"""

0 commit comments

Comments
 (0)