Skip to content

Commit

Permalink
Add acl check for layers for qploty
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Feb 24, 2025
1 parent af11ed4 commit 5619afe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions g3w-admin/qplotly/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def set_initconfig_value(sender, **kwargs):
layers = project.layer_set.all()

for layer in layers:

# Add check ACL for user
if not hasattr(sender, 'request') or not sender.request.user.has_perm('view_layer', layer):
continue

qplotly_widgets = layer.qplotlywidget_set.all()

for qplotly_widget in qplotly_widgets:
Expand Down
29 changes: 28 additions & 1 deletion g3w-admin/qplotly/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
GeoConstraint, \
GeoConstraintRule
from rest_framework.test import APIClient
from guardian.shortcuts import assign_perm
from guardian.shortcuts import assign_perm, remove_perm
from qplotly.utils import get_qplotlywidget_for_project
from qplotly.models import QplotlyWidget
from qplotly.utils.models import get_qplotlywidgets4layer
Expand Down Expand Up @@ -173,6 +173,33 @@ def test_initconfig_plugin_start(self):
self.assertTrue('layout' in plugin_plot['plot'])
self.assertEqual(plugin_plot['plot']['layout']['title'], {'text': ''})

# Test for users wit not permisions
# ---------------------------------
assign_perm('view_project', self.test_viewer1, self.project.instance)

response = self._testApiCall('group-map-config',
args=[self.project_group.slug, 'qdjango', self.project.instance.pk],
username=self.test_viewer1.username)

jcontent = json.loads(response.content)

self.assertEqual(plugin['plots'][0]['qgs_layer_id'], 'countries_d53dfb9a_98e1_4196_a601_eed9a33f47c3')


# Remove permisssion to layer for viewer1 user
layer = self.project.instance.layer_set.get(qgs_layer_id='countries_d53dfb9a_98e1_4196_a601_eed9a33f47c3')

remove_perm('view_layer', self.test_viewer1, layer)

response = self._testApiCall('group-map-config',
args=[self.project_group.slug, 'qdjango', self.project.instance.pk],
username=self.test_viewer1.username)

jcontent = json.loads(response.content)

self.assertFalse('qplotly' in jcontent['plugins'])


def test_trace_api(self):
"""/qplotly/api/trace API"""

Expand Down

0 comments on commit 5619afe

Please sign in to comment.