From e1067ffe6737f32db3c41c99d9c95191781d534b Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Mon, 7 Jun 2021 22:07:51 +0530 Subject: [PATCH] =?UTF-8?q?Ensure=20that=20the=20Query=20Tool=20connection?= =?UTF-8?q?=C2=A0string=C2=A0should=20not=20be=20changed=20as=20per=20the?= =?UTF-8?q?=20'Query=20Tool=20tab=20title'.=20Fixes=20#6404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en_US/release_notes_5_4.rst | 1 + web/pgadmin/browser/__init__.py | 5 ++-- .../browser/register_browser_preferences.py | 4 +-- .../browser/templates/browser/js/utils.js | 1 + .../js/sqleditor/new_connection_dialog.js | 26 +++++++++++-------- .../static/js/datagrid_panel_title.js | 12 ++++++--- .../tools/sqleditor/static/js/sqleditor.js | 16 ++++++------ web/pgadmin/utils/constants.py | 3 +++ 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/docs/en_US/release_notes_5_4.rst b/docs/en_US/release_notes_5_4.rst index b84b7bed1..02de94aa7 100644 --- a/docs/en_US/release_notes_5_4.rst +++ b/docs/en_US/release_notes_5_4.rst @@ -26,5 +26,6 @@ Bug fixes ********* | `Issue #4203 `_ - Fixed the issue of renaming the database by another user. +| `Issue #6404 `_ - Ensure that the Query Tool connection string should not be changed as per the 'Query Tool tab title'. | `Issue #6478 `_ - Fixed duplicate SQL issue for tables with more than one partition. | `Issue #6482 `_ - Fixed an issue where the Foreground Color property of server dialog does not work. diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index d6cf78cac..06fef52b7 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -50,7 +50,7 @@ from pgadmin.utils.master_password import validate_master_password, \ set_crypt_key, process_masterpass_disabled from pgadmin.model import User from pgadmin.utils.constants import MIMETYPE_APP_JS, PGADMIN_NODE,\ - INTERNAL, KERBEROS, LDAP + INTERNAL, KERBEROS, LDAP, QT_DEFAULT_PLACEHOLDER try: from flask_security.views import default_render_json @@ -852,7 +852,8 @@ def utils(): pg_libpq_version=pg_libpq_version, support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL, logout_url=_get_logout_url(), - platform=sys.platform + platform=sys.platform, + qt_default_placeholder=QT_DEFAULT_PLACEHOLDER ), 200, {'Content-Type': MIMETYPE_APP_JS}) diff --git a/web/pgadmin/browser/register_browser_preferences.py b/web/pgadmin/browser/register_browser_preferences.py index 0e464c066..53d77913c 100644 --- a/web/pgadmin/browser/register_browser_preferences.py +++ b/web/pgadmin/browser/register_browser_preferences.py @@ -10,7 +10,7 @@ import sys from flask_babelex import gettext from pgadmin.utils.constants import PREF_LABEL_DISPLAY,\ PREF_LABEL_KEYBOARD_SHORTCUTS, PREF_LABEL_TABS_SETTINGS, \ - PREF_LABEL_OPTIONS + PREF_LABEL_OPTIONS, QT_DEFAULT_PLACEHOLDER from flask_security import current_user import config @@ -470,7 +470,7 @@ def register_browser_preferences(self): self.qt_tab_title = self.preference.register( 'tab_settings', 'qt_tab_title_placeholder', gettext("Query tool tab title"), - 'text', '%DATABASE%/%USERNAME%@%SERVER%', + 'text', QT_DEFAULT_PLACEHOLDER, category_label=PREF_LABEL_DISPLAY, help_str=gettext( 'Supported placeholders are %DATABASE%, %USERNAME%, and %SERVER%. ' diff --git a/web/pgadmin/browser/templates/browser/js/utils.js b/web/pgadmin/browser/templates/browser/js/utils.js index 398bceb53..17268a4e7 100644 --- a/web/pgadmin/browser/templates/browser/js/utils.js +++ b/web/pgadmin/browser/templates/browser/js/utils.js @@ -56,6 +56,7 @@ define('pgadmin.browser.utils', pgAdmin['enable_psql'] = '{{ current_app.config.get('ENABLE_PSQL') }}' == 'True'; pgAdmin['allow_psql_shell_commands'] = '{{ current_app.config.get('ALLOW_PSQL_SHELL_COMMANDS') }}' == 'True'; pgAdmin['platform'] = '{{platform}}'; + pgAdmin['qt_default_placeholder'] = '{{qt_default_placeholder}}' /* GET Binary Path Browse config */ pgAdmin['enable_binary_path_browsing'] = '{{ current_app.config.get('ENABLE_BINARY_PATH_BROWSING') }}' == 'True'; diff --git a/web/pgadmin/static/js/sqleditor/new_connection_dialog.js b/web/pgadmin/static/js/sqleditor/new_connection_dialog.js index 68f1ba818..51b55db76 100644 --- a/web/pgadmin/static/js/sqleditor/new_connection_dialog.js +++ b/web/pgadmin/static/js/sqleditor/new_connection_dialog.js @@ -191,6 +191,17 @@ let NewConnectionDialog = { self.showNewConnectionProgress[0] ).addClass('d-none'); }, + get_title: function(qt_title_placeholder, selected_database_name, newConnCollectionModel, response) { + qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%DATABASE%'), selected_database_name); + if(newConnCollectionModel['role']) { + qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%USERNAME%'), newConnCollectionModel['role']); + } else { + qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%USERNAME%'), newConnCollectionModel['user']); + } + + qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%SERVER%'), response.server_name); + return qt_title_placeholder; + }, callback: function(e) { let self = this; if (e.button.element.name == 'dialog_help') { @@ -210,19 +221,11 @@ let NewConnectionDialog = { } }); let tab_title = ''; - var qt_title_placeholder = preferences['qt_tab_title_placeholder']; - qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%DATABASE%'), selected_database_name); - if(newConnCollectionModel['role']) { - qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%USERNAME%'), newConnCollectionModel['role']); - } else { - qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%USERNAME%'), newConnCollectionModel['user']); - } - - qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%SERVER%'), response.server_name); - - tab_title = qt_title_placeholder; + tab_title = this.get_title(qt_title_placeholder, selected_database_name, newConnCollectionModel, response); + let qt_default_placeholder = pgAdmin['qt_default_placeholder']; + let conn_title = this.get_title(qt_default_placeholder, selected_database_name, newConnCollectionModel, response); if(!newConnCollectionModel['role']) { newConnCollectionModel['role'] = null; @@ -247,6 +250,7 @@ let NewConnectionDialog = { 'server': newConnCollectionModel['server'], 'database': newConnCollectionModel['database'], 'title': _.escape(tab_title), + 'conn_title': _.escape(conn_title), 'user': newConnCollectionModel['user'], 'role': newConnCollectionModel['role'], 'server_name': _.escape(response.server_name), diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid_panel_title.js b/web/pgadmin/tools/datagrid/static/js/datagrid_panel_title.js index 8ff0cef68..d2ebf5929 100644 --- a/web/pgadmin/tools/datagrid/static/js/datagrid_panel_title.js +++ b/web/pgadmin/tools/datagrid/static/js/datagrid_panel_title.js @@ -23,7 +23,7 @@ function isServerInformationAvailable(parentData) { return parentData.server === undefined; } -export function getPanelTitle(pgBrowser, selected_item=null, custom_title=null, parentData=null) { +export function getPanelTitle(pgBrowser, selected_item=null, custom_title=null, parentData=null, conn_title=false) { var preferences = pgBrowser.get_preferences_for_module('browser'); if(selected_item == null && parentData == null) { selected_item = pgBrowser.treeMenu.selected(); @@ -38,10 +38,14 @@ export function getPanelTitle(pgBrowser, selected_item=null, custom_title=null, const db_label = getDatabaseLabel(parentData); var qt_title_placeholder = ''; - if (custom_title) { - qt_title_placeholder = custom_title; + if (!conn_title) { + if (custom_title) { + qt_title_placeholder = custom_title; + } else { + qt_title_placeholder = preferences['qt_tab_title_placeholder']; + } } else { - qt_title_placeholder = preferences['qt_tab_title_placeholder']; + qt_title_placeholder = pgAdmin['qt_default_placeholder']; } var title_data = { diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 3e91f424a..f511c373d 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -110,7 +110,7 @@ define('tools.querytool', [ this.set_server_version(opts.server_ver); this.trigger('pgadmin-sqleditor:view:initialised'); this.connection_list = [ - {'server_group': null,'server': null, 'database': null, 'user': null, 'role': null, 'title': '<' + gettext('New Connection') + '>'}, + {'server_group': null,'server': null, 'database': null, 'user': null, 'role': null, 'conn_title': '<' + gettext('New Connection') + '>'}, ]; }, @@ -184,9 +184,9 @@ define('tools.querytool', [ data_list.forEach((option, index) => { var opt = ''; if ('is_selected' in option && option['is_selected']) { - opt = '
  • '+ option.title +'
  • '; + opt = '
  • '+ option.conn_title +'
  • '; } else { - opt = '
  • '+ option.title +'
  • '; + opt = '
  • '+ option.conn_title +'
  • '; } $('#connections-list').append(opt); }); @@ -2284,7 +2284,7 @@ define('tools.querytool', [ 'sid': connection_details['server'], 'title': connection_details['title'], }; - self.set_editor_title(_.unescape(self.handler.url_params.title)); + self.set_editor_title(_.unescape(connection_details['conn_title'])); self.handler.setTitle(_.unescape(self.handler.url_params.title)); let success_msg = connection_details['server_name'] + '/' + connection_details['database_name'] + '- Database connected'; alertify.success(success_msg); @@ -2295,6 +2295,7 @@ define('tools.querytool', [ 'database': connection_details['database'], 'user': connection_details['user'], 'title': connection_details['title'], + 'conn_title': connection_details['conn_title'], 'role': connection_details['role'], 'is_allow_new_connection': true, 'database_name': connection_details['database_name'], @@ -2672,10 +2673,8 @@ define('tools.querytool', [ var server_data = pgWindow.default.pgAdmin.Browser.treeMenu.findNode(tree_data.slice(0,2)); var database_data = pgWindow.default.pgAdmin.Browser.treeMenu.findNode(tree_data.slice(0,4)); - - - - self.gridView.set_editor_title(_.unescape(url_params.title)); + let conn_title = panelTitleFunc.getPanelTitle(pgWindow.default.pgAdmin.Browser, null, null, null, true); + self.gridView.set_editor_title(_.unescape(conn_title)); let connection_data = { 'server_group': self.gridView.handler.url_params.sgid, 'server': self.gridView.handler.url_params.sid, @@ -2683,6 +2682,7 @@ define('tools.querytool', [ 'user': server_data.data.user.name, 'role': null, 'title': _.unescape(url_params.title), + 'conn_title': _.unescape(conn_title), 'is_allow_new_connection': false, 'database_name': _.unescape(database_data.data.label), 'server_name': _.unescape(server_data.data.label), diff --git a/web/pgadmin/utils/constants.py b/web/pgadmin/utils/constants.py index 5f5dd1e9f..0800193b4 100644 --- a/web/pgadmin/utils/constants.py +++ b/web/pgadmin/utils/constants.py @@ -31,6 +31,9 @@ UNAUTH_REQ = "Unauthorized request." SERVER_CONNECTION_CLOSED = gettext( 'Not connected to server or connection with the server has been closed.') +# Query tool placeholder +QT_DEFAULT_PLACEHOLDER = '%DATABASE%/%USERNAME%@%SERVER%' + # Data Types DATATYPE_TIME_WITH_TIMEZONE = 'time with time zone' DATATYPE_TIME_WITHOUT_TIMEZONE = 'time without time zone'