Skip to content

Commit

Permalink
Merge pull request #71 from rldhont/discard-invalid-layer
Browse files Browse the repository at this point in the history
Discard invalid layers and Warning icon
  • Loading branch information
Gustry authored Apr 23, 2024
2 parents 7787d53 + 48a21b4 commit c6c33a5
Show file tree
Hide file tree
Showing 4 changed files with 3,785 additions and 4 deletions.
19 changes: 19 additions & 0 deletions lizmap_server/get_legend_graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from typing import Optional

from qgis.core import Qgis, QgsProject, QgsVectorLayer
from qgis.PyQt.QtCore import QBuffer, QIODevice
from qgis.PyQt.QtGui import QImage
from qgis.server import QgsServerFilter

from lizmap_server.core import find_vector_layer
Expand Down Expand Up @@ -79,6 +81,23 @@ def responseComplete(self):
logger.info("Skipping the layer '{}' because it's not a vector layer".format(layer_name))
return

if not layer.isValid():
buffer = QBuffer()
buffer.open(QIODevice.WriteOnly)
qp = QImage(":/images/themes/default/mIconWarning.svg")
qp.save(buffer, "PNG")
json_data = {
'title': '',
'nodes': [{
'type': 'layer',
'title': layer_name,
'icon': str(buffer.data().toBase64().data()),
}]
}
handler.clearBody()
handler.appendBody(json.dumps(json_data).encode('utf8'))
return

try:
current_style = layer.styleManager().currentStyle()

Expand Down
18 changes: 14 additions & 4 deletions lizmap_server/lizmap_accesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,27 @@ def layerPermissions(self, layer: QgsMapLayer) -> QgsAccessControlFilter.LayerPe
# Get default layer rights
rights = super().layerPermissions(layer)

# Get layer name
layer_name = layer.name()

# Get Project
project = QgsProject.instance()

# Get request handler
request_handler = self.iface.requestHandler()

# Discard invalid layers for other services than WMS
if not layer.isValid() and request_handler.parameter('service').upper() != 'WMS':
Logger.info(f"layerPermission: Layer {layer_name} is invalid in {project.fileName()}!")
rights.canRead = False
rights.canInsert = rights.canUpdate = rights.canDelete = False
return rights

# Get Lizmap user groups provided by the request
groups = get_lizmap_groups(request_handler)

# Set lizmap variables
user_login = get_lizmap_user_login(request_handler)
project = QgsProject.instance()
custom_var = project.customVariables()
if custom_var.get('lizmap_user', None) != user_login:
custom_var['lizmap_user'] = user_login
Expand Down Expand Up @@ -101,9 +114,6 @@ def layerPermissions(self, layer: QgsMapLayer) -> QgsAccessControlFilter.LayerPe
# Default layer rights applied
return rights

# Get layer name
layer_name = layer.name()

# Check lizmap edition config
layer_id = layer.id()
if 'editionLayers' in cfg and cfg['editionLayers']:
Expand Down
Loading

0 comments on commit c6c33a5

Please sign in to comment.