-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a QGIS server QgsAccessControlFilter for check the layer ACL. * Fix test for layer acl QGIS server filter. * Restyling code. * Add tests for WFS service. --------- Co-authored-by: wlorenzetti <[email protected]>
- Loading branch information
1 parent
6963b6a
commit a311932
Showing
6 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
g3w-admin/qdjango/server_filters/accesscontrol/layer_acl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# coding=utf-8 | ||
"""" Che layer acl | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the Mozilla Public License 2.0. | ||
""" | ||
|
||
__author__ = "[email protected]" | ||
__date__ = "2023-09-25" | ||
__copyright__ = "Copyright 2015 - 2023, Gis3w" | ||
__license__ = "MPL 2.0" | ||
|
||
from guardian.shortcuts import get_perms | ||
from qgis.server import QgsAccessControlFilter | ||
from qgis.core import QgsMessageLog, Qgis | ||
from qdjango.apps import QGS_SERVER | ||
from qdjango.models import Layer | ||
|
||
|
||
class LayerAclAccessControlFilter(QgsAccessControlFilter): | ||
"""Filter layer by ACL properties""" | ||
|
||
def __init__(self, server_iface): | ||
super().__init__(server_iface) | ||
|
||
def layerPermissions(self, layer): | ||
|
||
rights = QgsAccessControlFilter.LayerPermissions() | ||
|
||
try: | ||
qdjango_layer = Layer.objects.get( | ||
project=QGS_SERVER.project, qgs_layer_id=layer.id()) | ||
|
||
# Check permission | ||
perms = get_perms(QGS_SERVER.user, qdjango_layer) | ||
rights.canRead = "view_layer" in perms | ||
rights.canInsert = "add_layer" in perms | ||
rights.canUpdate = "change_layer" in perms | ||
rights.canDelete = "delete_layer" in perms | ||
|
||
except Layer.DoesNotExist: | ||
pass | ||
|
||
return rights | ||
|
||
|
||
# Register the filter, keep a reference because of the garbage collector | ||
layeracl_filter = LayerAclAccessControlFilter(QGS_SERVER.serverInterface()) | ||
# Note: this should be the last filter, set the priority to 10000 | ||
QGS_SERVER.serverInterface().registerAccessControl(layeracl_filter, 10010) |
Binary file modified
BIN
+0 Bytes
(100%)
g3w-admin/qdjango/tests/data/geodata/qgis_widget_test_data.gpkg
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters