Skip to content

Commit

Permalink
Fix compatibility and Python error with QGIS < 3.22
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Oct 19, 2023
1 parent 4121611 commit 4cdfb4a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def enabled_ssl_button(self, status: bool):
""" Enable or not the button. """
if Qgis.QGIS_VERSION_INT <= 32200:
self.button_convert_ssl.setToolTip(tr("QGIS 3.22 minimum is required"))
self.button_convert_ssl.setEnbled(False)
self.button_convert_ssl.setEnabled(False)
return

self.button_convert_ssl.setEnabled(status)
Expand Down
2 changes: 1 addition & 1 deletion lizmap/dialogs/server_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def _uri(self) -> QgsDataSourceUri:
self.field("pg_db_name"),
self.field("pg_user"),
self.field("pg_password"),
QgsDataSourceUri.SslMode.SslPrefer,
QgsDataSourceUri.SslPrefer,
)
return uri

Expand Down
6 changes: 3 additions & 3 deletions lizmap/saas.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ def fix_ssl(project: QgsProject, force: bool = True) -> int:
if not datasource.host().endswith(SAAS_DOMAIN):
continue

if datasource.sslMode() in (QgsDataSourceUri.SslMode.SslPrefer, QgsDataSourceUri.SslMode.SslRequire):
if datasource.sslMode() in (QgsDataSourceUri.SslPrefer, QgsDataSourceUri.SslMode.SslRequire):
continue

new_uri = _update_ssl(datasource, QgsDataSourceUri.SslMode.SslPrefer, force=force)
new_uri = _update_ssl(datasource, QgsDataSourceUri.SslPrefer, force=force)
layer.setDataSource(new_uri.uri(True), layer.name(), layer.dataProvider().name())
count += 1

Expand All @@ -178,7 +178,7 @@ def fix_ssl(project: QgsProject, force: bool = True) -> int:

def _update_ssl(
uri: QgsDataSourceUri,
mode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslMode.SslPrefer,
mode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer,
force: bool = False,
) -> QgsDataSourceUri:
""" Update SSL connection for a given URI. """
Expand Down
10 changes: 5 additions & 5 deletions lizmap/test/test_saas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def test_ssl_update(self):
'sslmode=disable key=\'id\' estimatedmetadata=true srid=4326 type=MultiPoint '
'checkPrimaryKeyUnicity=\'1\' table="demo"."point" (geom)'
)
self.assertEqual(QgsDataSourceUri.SslMode.SslDisable, uri.sslMode())
self.assertEqual(QgsDataSourceUri.SslDisable, uri.sslMode())

new_ssl = QgsDataSourceUri.SslMode.SslPrefer
new_ssl = QgsDataSourceUri.SslPrefer
new_uri = _update_ssl(uri, new_ssl)
self.assertEqual(new_ssl, new_uri.sslMode())

new_ssl = QgsDataSourceUri.SslMode.SslRequire
new_ssl = QgsDataSourceUri.SslRequire
new_uri = _update_ssl(uri, new_ssl)
self.assertEqual(new_ssl, new_uri.sslMode())

Expand All @@ -35,8 +35,8 @@ def test_ssl_update_force(self):
'key=\'id\' estimatedmetadata=true srid=4326 type=MultiPoint '
'checkPrimaryKeyUnicity=\'1\' table="demo"."point" (geom)'
)
self.assertEqual(QgsDataSourceUri.SslMode.SslPrefer, uri.sslMode())
self.assertEqual(QgsDataSourceUri.SslPrefer, uri.sslMode())

new_ssl = QgsDataSourceUri.SslMode.SslRequire
new_ssl = QgsDataSourceUri.SslRequire
new_uri = _update_ssl(uri, new_ssl, True)
self.assertEqual(new_ssl, new_uri.sslMode())

0 comments on commit 4cdfb4a

Please sign in to comment.