From 6ea3b6d82bd2f4fb78a0c47149e41650ab03c15b Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 14:09:58 +0100 Subject: [PATCH 1/6] allow connections without username and password --- QgisModelBaker/gui/panel/pg_config_panel.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/QgisModelBaker/gui/panel/pg_config_panel.py b/QgisModelBaker/gui/panel/pg_config_panel.py index b5776ed7..909bc4ff 100644 --- a/QgisModelBaker/gui/panel/pg_config_panel.py +++ b/QgisModelBaker/gui/panel/pg_config_panel.py @@ -327,15 +327,6 @@ def is_valid(self): elif not self.pg_database_line_edit.text().strip(): message = self.tr("Please set a database before creating the project.") self.pg_database_line_edit.setFocus() - elif ( - not self.pg_auth_settings.username() - and not self.pg_auth_settings.configId() - ): - message = self.tr( - "Please set a username or select an authentication configuration before creating the " - "project." - ) - self.pg_auth_settings.setFocus() elif ( self.pg_auth_settings.configId() and not self.pg_use_super_login.isChecked() From 247e0ca45eb5135f3c6759e39b598789cffa96fd Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 14:10:22 +0100 Subject: [PATCH 2/6] in postgres, pass account user name to ili2db command if no user name provided --- QgisModelBaker/gui/panel/session_panel.py | 10 +++++++++- QgisModelBaker/gui/validate.py | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/QgisModelBaker/gui/panel/session_panel.py b/QgisModelBaker/gui/panel/session_panel.py index 2ca63c22..d48913b7 100644 --- a/QgisModelBaker/gui/panel/session_panel.py +++ b/QgisModelBaker/gui/panel/session_panel.py @@ -19,6 +19,7 @@ import os +from qgis.core import QgsApplication from qgis.PyQt.QtCore import Qt, pyqtSignal from qgis.PyQt.QtWidgets import QAction, QApplication, QMessageBox, QWidget @@ -34,7 +35,7 @@ from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbutils import JavaNotFoundError from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType from QgisModelBaker.libs.modelbaker.utils.qt_utils import OverrideCursor -from QgisModelBaker.utils.globals import DEFAULT_DATASETNAME +from QgisModelBaker.utils.globals import DEFAULT_DATASETNAME, DbIliMode from QgisModelBaker.utils.gui_utils import LogLevel WIDGET_UI = gui_utils.get_ui_class("workflow_wizard/session_panel.ui") @@ -108,6 +109,13 @@ def __init__( # set up the values self.configuration = general_configuration + if self.configuration.tool & DbIliMode.pg: + # on pg we should consider the user account name as fallback + if ( + not self.configuration.db_use_super_login + and not self.configuration.dbusr + ): + self.configuration.dbusr = QgsApplication.userLoginName() if self.db_action_type == DbActionType.GENERATE: self.configuration.ilifile = "" if os.path.isfile(self.file): diff --git a/QgisModelBaker/gui/validate.py b/QgisModelBaker/gui/validate.py index 75ed76db..bbf34ad8 100644 --- a/QgisModelBaker/gui/validate.py +++ b/QgisModelBaker/gui/validate.py @@ -349,6 +349,13 @@ def _run(self, edited_command=None): validator.tool = self.current_configuration.tool validator.configuration = self.current_configuration + if validator.configuration.tool & DbIliMode.pg: + # on pg we should consider the user account name as fallback + if ( + not validator.configuration.db_use_super_login + and not validator.configuration.dbusr + ): + validator.configuration.dbusr = QgsApplication.userLoginName() validator.configuration.ilimodels = "" validator.configuration.dataset = "" From b5d41b86c412857dedcd3d45bdac4c73371d979d Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 14:10:43 +0100 Subject: [PATCH 3/6] use default get_db_connector function from utils --- QgisModelBaker/gui/panel/dataset_selector.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/QgisModelBaker/gui/panel/dataset_selector.py b/QgisModelBaker/gui/panel/dataset_selector.py index b9f66f5d..f01ea166 100644 --- a/QgisModelBaker/gui/panel/dataset_selector.py +++ b/QgisModelBaker/gui/panel/dataset_selector.py @@ -26,6 +26,7 @@ ) from QgisModelBaker.libs.modelbaker.utils.db_utils import ( get_configuration_from_sourceprovider, + get_db_connector, get_schema_identificator_from_sourceprovider, ) from QgisModelBaker.libs.modelbaker.utils.qt_utils import slugify @@ -82,12 +83,8 @@ def set_current_layer(self, layer): source_provider, configuration ) if valid and mode: - db_factory = self.db_simple_factory.create_factory(mode) - config_manager = db_factory.get_db_command_config_manager(configuration) try: - db_connector = db_factory.get_db_connector( - config_manager.get_uri(), configuration.dbschema - ) + db_connector = get_db_connector(configuration) if db_connector.get_basket_handling(): self.basket_model.reload_schema_baskets( db_connector, From e5fe013bb6b3b13ea6ad3e1ac449ff18be323b85 Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 14:11:25 +0100 Subject: [PATCH 4/6] for the mgmt_uri pass the account user name to the uri, but otherwise not since it should not be in the layers --- .../gui/workflow_wizard/project_creation_page.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index 013a20e8..1a41f29a 100644 --- a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py +++ b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py @@ -332,7 +332,10 @@ def _create_project(self): self.configuration ) uri = config_manager.get_uri(qgis=True) - mgmt_uri = config_manager.get_uri(self.configuration.db_use_super_login) + mgmt_uri = config_manager.get_uri( + su=self.configuration.db_use_super_login, + fallback_user=QgsApplication.userLoginName(), + ) generator = Generator( self.configuration.tool, uri, @@ -375,7 +378,9 @@ def _create_project(self): self.progress_bar.setValue(0) return - res, message = db_factory.post_generate_project_validations(self.configuration) + res, message = db_factory.post_generate_project_validations( + self.configuration, QgsApplication.userLoginName() + ) if not res: self.workflow_wizard.log_panel.txtStdout.setText(message) From 25c7e951554029f683fbb035a743d7d8270b23ab Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 14:17:32 +0100 Subject: [PATCH 5/6] fix missing import --- QgisModelBaker/gui/workflow_wizard/project_creation_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index 1a41f29a..794dc9d4 100644 --- a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py +++ b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py @@ -22,7 +22,7 @@ import re import yaml -from qgis.core import Qgis, QgsProject +from qgis.core import Qgis, QgsApplication, QgsProject from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QCompleter, QWizardPage From e272c85b5daa5eecafddcf57ac3c748bc4b30a36 Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 29 Oct 2024 21:50:02 +0100 Subject: [PATCH 6/6] Tool (pg/gpkg/mssql) mode is set in the get_configuration_from_sourceprovider function, so redundancy is removed --- QgisModelBaker/gui/dataset_manager.py | 1 - QgisModelBaker/gui/panel/tid_configurator_panel.py | 5 +++-- QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py | 1 - QgisModelBaker/gui/topping_wizard/layers_page.py | 1 - QgisModelBaker/gui/topping_wizard/models_page.py | 1 - QgisModelBaker/gui/validate.py | 1 - .../gui/workflow_wizard/database_selection_page.py | 1 - 7 files changed, 3 insertions(+), 8 deletions(-) diff --git a/QgisModelBaker/gui/dataset_manager.py b/QgisModelBaker/gui/dataset_manager.py index e05f5211..93a570ea 100644 --- a/QgisModelBaker/gui/dataset_manager.py +++ b/QgisModelBaker/gui/dataset_manager.py @@ -199,7 +199,6 @@ def _evaluated_configuration(self): valid, mode = db_utils.get_configuration_from_sourceprovider( source_provider, configuration ) - configuration.tool = mode source_info_text = self.tr( "

It's the datasource of the current project, evaluated by layer {}.

" ).format(layer.name()) diff --git a/QgisModelBaker/gui/panel/tid_configurator_panel.py b/QgisModelBaker/gui/panel/tid_configurator_panel.py index c6bedd9b..c9102a75 100644 --- a/QgisModelBaker/gui/panel/tid_configurator_panel.py +++ b/QgisModelBaker/gui/panel/tid_configurator_panel.py @@ -66,8 +66,9 @@ def setup_dialog(self, qgis_project, configuration=None): valid, mode = db_utils.get_configuration_from_sourceprovider( source_provider, self.configuration ) - if valid: - self.configuration.tool = mode + if not valid: + # invalidate tool + self.configuration.tool = "" if self.configuration and self.configuration.tool: self._reset_tid_configuration() diff --git a/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py b/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py index c0462455..c0a6eba9 100644 --- a/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py +++ b/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py @@ -271,7 +271,6 @@ def _refresh_combobox(self): source_provider, configuration ) if valid and mode: - configuration.tool = mode db_connector = db_utils.get_db_connector(configuration) # only load it when it exists and metadata there (contains interlis data) if ( diff --git a/QgisModelBaker/gui/topping_wizard/layers_page.py b/QgisModelBaker/gui/topping_wizard/layers_page.py index 39a17d9b..e075cdc6 100644 --- a/QgisModelBaker/gui/topping_wizard/layers_page.py +++ b/QgisModelBaker/gui/topping_wizard/layers_page.py @@ -389,7 +389,6 @@ def _load_ili_schema_identificators(self): source_provider, configuration ) if valid and mode: - configuration.tool = mode db_connector = db_utils.get_db_connector(configuration) if ( diff --git a/QgisModelBaker/gui/topping_wizard/models_page.py b/QgisModelBaker/gui/topping_wizard/models_page.py index 12637315..6b046196 100644 --- a/QgisModelBaker/gui/topping_wizard/models_page.py +++ b/QgisModelBaker/gui/topping_wizard/models_page.py @@ -104,7 +104,6 @@ def _load_available_models_and_sources(self): source_provider, current_configuration ) if valid and mode: - current_configuration.tool = mode db_connector = db_utils.get_db_connector(current_configuration) if db_connector: db_connectors.append(db_connector) diff --git a/QgisModelBaker/gui/validate.py b/QgisModelBaker/gui/validate.py index bbf34ad8..2eb6675c 100644 --- a/QgisModelBaker/gui/validate.py +++ b/QgisModelBaker/gui/validate.py @@ -248,7 +248,6 @@ def set_current_layer(self, layer): QStandardPaths.writableLocation(QStandardPaths.TempLocation), f"dataexport_{output_file_name}", ) - self.current_configuration.tool = mode if mode == DbIliMode.gpkg: self.info_label.setText( self.tr( diff --git a/QgisModelBaker/gui/workflow_wizard/database_selection_page.py b/QgisModelBaker/gui/workflow_wizard/database_selection_page.py index 6cd22d52..61cf14ce 100644 --- a/QgisModelBaker/gui/workflow_wizard/database_selection_page.py +++ b/QgisModelBaker/gui/workflow_wizard/database_selection_page.py @@ -104,7 +104,6 @@ def restore_configuration(self, configuration, get_config_from_project=False): if valid and mode: # uses the settings from the project and provides it to the gui configuration = layer_configuration - configuration.tool = mode self._lst_panel[mode].set_fields(configuration) else: # takes settings from QSettings and provides it to the gui