Skip to content

Commit

Permalink
Merge pull request #972 from opengisch/account-username
Browse files Browse the repository at this point in the history
If no user name (or auth config) is chosen, we fill up the user name …
  • Loading branch information
signedav authored Nov 4, 2024
2 parents 5a191a7 + e272c85 commit 67392c1
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 26 deletions.
1 change: 0 additions & 1 deletion QgisModelBaker/gui/dataset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<body><p>It's the datasource of the current project, evaluated by layer <b>{}</b>.</p>"
).format(layer.name())
Expand Down
7 changes: 2 additions & 5 deletions QgisModelBaker/gui/panel/dataset_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions QgisModelBaker/gui/panel/pg_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion QgisModelBaker/gui/panel/session_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions QgisModelBaker/gui/panel/tid_configurator_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion QgisModelBaker/gui/topping_wizard/layers_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion QgisModelBaker/gui/topping_wizard/models_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion QgisModelBaker/gui/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -349,6 +348,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 = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions QgisModelBaker/gui/workflow_wizard/project_creation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -349,7 +349,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,
Expand Down Expand Up @@ -393,7 +396,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)
Expand Down

0 comments on commit 67392c1

Please sign in to comment.