-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix issue #603 * Backport tests. * Backport tests. --------- Co-authored-by: wlorenzetti <[email protected]>
- Loading branch information
1 parent
4936c7e
commit 2dbbf1a
Showing
5 changed files
with
185 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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
# 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, get_anonymous_user | ||
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 = list( | ||
set(get_perms(QGS_SERVER.user, qdjango_layer)) | | ||
set(get_perms(get_anonymous_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) |
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