Skip to content

Commit

Permalink
Check for raster layer using AuthDB if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Nov 25, 2024
1 parent e3f37a2 commit afc43c8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
27 changes: 19 additions & 8 deletions lizmap/project_checker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ def project_safeguards_checks(
if layer.source().lower().endswith('ecw') and prevent_ecw:
results[SourceLayer(layer.name(), layer.id())] = checks.PreventEcw

if french_geopf_authcfg_url_parameters(layer.source()) and prevent_auth_id:
results[SourceLayer(layer.name(), layer.id())] = checks.FrenchGeoPlateformeUrl
if prevent_auth_id:
if french_geopf_authcfg_url_parameters(layer.source()):
results[SourceLayer(layer.name(), layer.id())] = checks.FrenchGeoPlateformeUrl
elif authcfg_url_parameters(layer.source()):
results[SourceLayer(layer.name(), layer.id())] = checks.RasterAuthenticationDb

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


def french_geopf_authcfg_url_parameters(datasource: str) -> bool:
def authcfg_url_parameters(datasource: str) -> bool:
""" Check for authcfg in a datasource, using a plain string.
This function is not using QgsDataSourceUri::authConfigId()
"""
if 'data.geopf.fr' not in datasource.lower():
return False

url_param = QUrlQuery(html.unescape(datasource))
for param in url_param.queryItems():
if param[0].lower() == 'authcfg' and param[1] != '':
return True
# if param[0].lower().startswith("http-header:"):
# return True

return False


def french_geopf_authcfg_url_parameters(datasource: str) -> bool:
""" Check for authcfg in a datasource, using a plain string.
This function is not using QgsDataSourceUri::authConfigId()
"""
if 'data.geopf.fr' not in datasource.lower():
return False
# if param[0].lower().startswith("http-header:"):
# return True
return authcfg_url_parameters(datasource)


def duplicated_rule_key_legend(project: QgsProject, filter_data: bool = True) -> Dict[str, Dict[str, int]]:
""" Check for all duplicated rule keys in the legend. """
results = {}
Expand Down
4 changes: 4 additions & 0 deletions lizmap/test/test_project_checker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from lizmap.project_checker_tools import (
_duplicated_label_legend_layer,
_split_layer_uri,
authcfg_url_parameters,
duplicated_layer_with_filter,
duplicated_layer_with_filter_legend,
duplicated_rule_key_legend,
Expand Down Expand Up @@ -169,6 +170,7 @@ def test_french_raster_datasource_authcfg(self):
"&authCFG=x3rzac9"
)
self.assertFalse(french_geopf_authcfg_url_parameters(raster))
self.assertTrue(authcfg_url_parameters(raster))

# data.GEOPF.fr
raster = (
Expand All @@ -177,13 +179,15 @@ def test_french_raster_datasource_authcfg(self):
"&authCFG=x3rzac9"
)
self.assertTrue(french_geopf_authcfg_url_parameters(raster))
self.assertTrue(authcfg_url_parameters(raster))

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

# http-header
# raster = (
Expand Down
35 changes: 34 additions & 1 deletion lizmap/widgets/check_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def __init__(self):
other_auth = tr('Either switch to another authentication mechanism')
safeguard = tr('Or disable this safeguard in your Lizmap plugin settings')
global_connection = tr(
'To fix layers loaded <b>later</b>, edit your global PostgreSQL connection to enable this option, then '
'To fix layers loaded <b>later</b>, edit your global PostgreSQL/raster connection to enable this option, then '
'change the datasource by right clicking on each layer above, then click "Change datasource" in the menu. '
'Finally reselect your layer in the new dialog with the updated connection. When opening a QGIS project in '
'your computer, with a fresh launched QGIS software, you mustn\'t have any prompt for a user or password. '
Expand Down Expand Up @@ -799,6 +799,39 @@ def __init__(self):
'</ul>'
).format(help=tr('Switch to a COG format'))
)
self.RasterAuthenticationDb = Check(
f"{Settings.PreventPgAuthDb}_raster",
tr('QGIS Authentication database'),
tr(
'The layer is using the QGIS authentication database. You have activated a safeguard preventing you '
'using the QGIS authentication database.'
),
(
'<ul>'
'<li>{help}</li>'
'<li>{other}</li>'
'<li>{global_connection}</li>'
'</ul>'.format(
help=other_auth,
other=safeguard,
global_connection=global_connection,
)
),
Levels.Layer,
Severities().unknown,
QIcon(':/images/themes/default/mIconPostgis.svg'),
tr('The layer is using the QGIS authentication database. This is not compatible with {}').format(CLOUD_NAME),
(
'<ul>'
'<li>{login_pass}</li>'
'</ul>'
).format(
login_pass=tr(
'Store the login and password in the layer by editing the global connection and do the '
'"Change datasource" on each layer.'
)
)
)
self.AuthenticationDb = Check(
Settings.PreventPgAuthDb,
tr('QGIS Authentication database'),
Expand Down

0 comments on commit afc43c8

Please sign in to comment.