Skip to content

Commit afc43c8

Browse files
committed
Check for raster layer using AuthDB if needed
1 parent e3f37a2 commit afc43c8

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

lizmap/project_checker_tools.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ def project_safeguards_checks(
7878
if layer.source().lower().endswith('ecw') and prevent_ecw:
7979
results[SourceLayer(layer.name(), layer.id())] = checks.PreventEcw
8080

81-
if french_geopf_authcfg_url_parameters(layer.source()) and prevent_auth_id:
82-
results[SourceLayer(layer.name(), layer.id())] = checks.FrenchGeoPlateformeUrl
81+
if prevent_auth_id:
82+
if french_geopf_authcfg_url_parameters(layer.source()):
83+
results[SourceLayer(layer.name(), layer.id())] = checks.FrenchGeoPlateformeUrl
84+
elif authcfg_url_parameters(layer.source()):
85+
results[SourceLayer(layer.name(), layer.id())] = checks.RasterAuthenticationDb
8386

8487
if is_vector_pg(layer):
8588
# Make a copy by using a string, so we are sure to have user or password
@@ -470,23 +473,31 @@ def trailing_layer_group_name(layer_tree: QgsLayerTreeNode, project, results: Li
470473
return results
471474

472475

473-
def french_geopf_authcfg_url_parameters(datasource: str) -> bool:
476+
def authcfg_url_parameters(datasource: str) -> bool:
474477
""" Check for authcfg in a datasource, using a plain string.
475478
476479
This function is not using QgsDataSourceUri::authConfigId()
477480
"""
478-
if 'data.geopf.fr' not in datasource.lower():
479-
return False
480-
481481
url_param = QUrlQuery(html.unescape(datasource))
482482
for param in url_param.queryItems():
483483
if param[0].lower() == 'authcfg' and param[1] != '':
484484
return True
485-
# if param[0].lower().startswith("http-header:"):
486-
# return True
485+
487486
return False
488487

489488

489+
def french_geopf_authcfg_url_parameters(datasource: str) -> bool:
490+
""" Check for authcfg in a datasource, using a plain string.
491+
492+
This function is not using QgsDataSourceUri::authConfigId()
493+
"""
494+
if 'data.geopf.fr' not in datasource.lower():
495+
return False
496+
# if param[0].lower().startswith("http-header:"):
497+
# return True
498+
return authcfg_url_parameters(datasource)
499+
500+
490501
def duplicated_rule_key_legend(project: QgsProject, filter_data: bool = True) -> Dict[str, Dict[str, int]]:
491502
""" Check for all duplicated rule keys in the legend. """
492503
results = {}

lizmap/test/test_project_checker_tools.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from lizmap.project_checker_tools import (
1212
_duplicated_label_legend_layer,
1313
_split_layer_uri,
14+
authcfg_url_parameters,
1415
duplicated_layer_with_filter,
1516
duplicated_layer_with_filter_legend,
1617
duplicated_rule_key_legend,
@@ -169,6 +170,7 @@ def test_french_raster_datasource_authcfg(self):
169170
"&authCFG=x3rzac9"
170171
)
171172
self.assertFalse(french_geopf_authcfg_url_parameters(raster))
173+
self.assertTrue(authcfg_url_parameters(raster))
172174

173175
# data.GEOPF.fr
174176
raster = (
@@ -177,13 +179,15 @@ def test_french_raster_datasource_authcfg(self):
177179
"&authCFG=x3rzac9"
178180
)
179181
self.assertTrue(french_geopf_authcfg_url_parameters(raster))
182+
self.assertTrue(authcfg_url_parameters(raster))
180183

181184
# Correct
182185
raster = (
183186
"contextualWMSLegend=0&crs=EPSG:2154&dpiMode=7&featureCount=10&format=image/jpeg&"
184187
"layers=SCAN25TOUR_PYR-JPEG_WLD_WM&styles&url=https://data.geopf.fr/private/wms-r?VERSION%3D1.3.0"
185188
)
186189
self.assertFalse(french_geopf_authcfg_url_parameters(raster))
190+
self.assertFalse(authcfg_url_parameters(raster))
187191

188192
# http-header
189193
# raster = (

lizmap/widgets/check_project.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def __init__(self):
251251
other_auth = tr('Either switch to another authentication mechanism')
252252
safeguard = tr('Or disable this safeguard in your Lizmap plugin settings')
253253
global_connection = tr(
254-
'To fix layers loaded <b>later</b>, edit your global PostgreSQL connection to enable this option, then '
254+
'To fix layers loaded <b>later</b>, edit your global PostgreSQL/raster connection to enable this option, then '
255255
'change the datasource by right clicking on each layer above, then click "Change datasource" in the menu. '
256256
'Finally reselect your layer in the new dialog with the updated connection. When opening a QGIS project in '
257257
'your computer, with a fresh launched QGIS software, you mustn\'t have any prompt for a user or password. '
@@ -799,6 +799,39 @@ def __init__(self):
799799
'</ul>'
800800
).format(help=tr('Switch to a COG format'))
801801
)
802+
self.RasterAuthenticationDb = Check(
803+
f"{Settings.PreventPgAuthDb}_raster",
804+
tr('QGIS Authentication database'),
805+
tr(
806+
'The layer is using the QGIS authentication database. You have activated a safeguard preventing you '
807+
'using the QGIS authentication database.'
808+
),
809+
(
810+
'<ul>'
811+
'<li>{help}</li>'
812+
'<li>{other}</li>'
813+
'<li>{global_connection}</li>'
814+
'</ul>'.format(
815+
help=other_auth,
816+
other=safeguard,
817+
global_connection=global_connection,
818+
)
819+
),
820+
Levels.Layer,
821+
Severities().unknown,
822+
QIcon(':/images/themes/default/mIconPostgis.svg'),
823+
tr('The layer is using the QGIS authentication database. This is not compatible with {}').format(CLOUD_NAME),
824+
(
825+
'<ul>'
826+
'<li>{login_pass}</li>'
827+
'</ul>'
828+
).format(
829+
login_pass=tr(
830+
'Store the login and password in the layer by editing the global connection and do the '
831+
'"Change datasource" on each layer.'
832+
)
833+
)
834+
)
802835
self.AuthenticationDb = Check(
803836
Settings.PreventPgAuthDb,
804837
tr('QGIS Authentication database'),

0 commit comments

Comments
 (0)