From ccf1eb250632abc21dc21607a6bced9a3e1b8a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Mon, 30 Sep 2024 18:01:31 -0500 Subject: [PATCH] [export] Hide superuser checkbox on PG export and make it possible to run PG export with authConfig and no superuser --- QgisModelBaker/gui/panel/pg_config_panel.py | 10 ++++++++-- QgisModelBaker/utils/globals.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/QgisModelBaker/gui/panel/pg_config_panel.py b/QgisModelBaker/gui/panel/pg_config_panel.py index b2063ba1e..fdf1af403 100644 --- a/QgisModelBaker/gui/panel/pg_config_panel.py +++ b/QgisModelBaker/gui/panel/pg_config_panel.py @@ -29,6 +29,7 @@ from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType from QgisModelBaker.utils import gui_utils +from ...utils.globals import AdministrativeDBActionTypes from .db_config_panel import DbConfigPanel WIDGET_UI = gui_utils.get_ui_class("pg_settings_panel.ui") @@ -78,7 +79,7 @@ def __init__(self, parent, db_action_type): ) self.pg_use_super_login.setToolTip( self.tr( - "Data management tasks are " + "Data management tasks are " ) ) @@ -197,6 +198,7 @@ def _show_panel(self): self.pg_schema_combo_box.lineEdit().setPlaceholderText( self.tr("[Enter a valid schema]") ) + self.pg_use_super_login.setVisible(False) else: logging.error(f"Unknown action type: {self._db_action_type}") @@ -330,8 +332,12 @@ def is_valid(self): ) self.pg_auth_settings.setFocus() elif ( - self.pg_auth_settings.configId() and not self.pg_use_super_login.isChecked() + self.pg_auth_settings.configId() + and not self.pg_use_super_login.isChecked() + and self._db_action_type + in {item.value for item in AdministrativeDBActionTypes} ): + # For Python v3.12+, we can just check like this: self._db_action_type in AdministrativeDBActionTypes message = self.tr( "Use superuser login for data management tasks when you use an authentication configuration." ) diff --git a/QgisModelBaker/utils/globals.py b/QgisModelBaker/utils/globals.py index f3981606d..ab5255a22 100644 --- a/QgisModelBaker/utils/globals.py +++ b/QgisModelBaker/utils/globals.py @@ -17,9 +17,12 @@ ***************************************************************************/ """ +from enum import Enum + from qgis.PyQt.QtCore import QCoreApplication from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode +from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType CRS_PATTERNS = {"LV95": 2056, "LV03": 21781} @@ -41,3 +44,10 @@ "QgisModelBaker", "Interlis (use SQL Server)" ), } + + +class AdministrativeDBActionTypes(Enum): + """Defines constants for modelbaker actions that require superuser login""" + + GENERATE = DbActionType.GENERATE + IMPORT_DATA = DbActionType.IMPORT_DATA