Ensure that the Query Tool connection string should not be changed as per the 'Query Tool tab title'. Fixes #6404

This commit is contained in:
Nikhil Mohite 2021-06-07 22:07:51 +05:30 committed by Akshay Joshi
parent d5f537aae4
commit e1067ffe67
8 changed files with 41 additions and 27 deletions

View File

@ -26,5 +26,6 @@ Bug fixes
********* *********
| `Issue #4203 <https://redmine.postgresql.org/issues/4203>`_ - Fixed the issue of renaming the database by another user. | `Issue #4203 <https://redmine.postgresql.org/issues/4203>`_ - Fixed the issue of renaming the database by another user.
| `Issue #6404 <https://redmine.postgresql.org/issues/6404>`_ - Ensure that the Query Tool connection string should not be changed as per the 'Query Tool tab title'.
| `Issue #6478 <https://redmine.postgresql.org/issues/6478>`_ - Fixed duplicate SQL issue for tables with more than one partition. | `Issue #6478 <https://redmine.postgresql.org/issues/6478>`_ - Fixed duplicate SQL issue for tables with more than one partition.
| `Issue #6482 <https://redmine.postgresql.org/issues/6482>`_ - Fixed an issue where the Foreground Color property of server dialog does not work. | `Issue #6482 <https://redmine.postgresql.org/issues/6482>`_ - Fixed an issue where the Foreground Color property of server dialog does not work.

View File

@ -50,7 +50,7 @@ from pgadmin.utils.master_password import validate_master_password, \
set_crypt_key, process_masterpass_disabled set_crypt_key, process_masterpass_disabled
from pgadmin.model import User from pgadmin.model import User
from pgadmin.utils.constants import MIMETYPE_APP_JS, PGADMIN_NODE,\ from pgadmin.utils.constants import MIMETYPE_APP_JS, PGADMIN_NODE,\
INTERNAL, KERBEROS, LDAP INTERNAL, KERBEROS, LDAP, QT_DEFAULT_PLACEHOLDER
try: try:
from flask_security.views import default_render_json from flask_security.views import default_render_json
@ -852,7 +852,8 @@ def utils():
pg_libpq_version=pg_libpq_version, pg_libpq_version=pg_libpq_version,
support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL, support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL,
logout_url=_get_logout_url(), logout_url=_get_logout_url(),
platform=sys.platform platform=sys.platform,
qt_default_placeholder=QT_DEFAULT_PLACEHOLDER
), ),
200, {'Content-Type': MIMETYPE_APP_JS}) 200, {'Content-Type': MIMETYPE_APP_JS})

View File

@ -10,7 +10,7 @@ import sys
from flask_babelex import gettext from flask_babelex import gettext
from pgadmin.utils.constants import PREF_LABEL_DISPLAY,\ from pgadmin.utils.constants import PREF_LABEL_DISPLAY,\
PREF_LABEL_KEYBOARD_SHORTCUTS, PREF_LABEL_TABS_SETTINGS, \ PREF_LABEL_KEYBOARD_SHORTCUTS, PREF_LABEL_TABS_SETTINGS, \
PREF_LABEL_OPTIONS PREF_LABEL_OPTIONS, QT_DEFAULT_PLACEHOLDER
from flask_security import current_user from flask_security import current_user
import config import config
@ -470,7 +470,7 @@ def register_browser_preferences(self):
self.qt_tab_title = self.preference.register( self.qt_tab_title = self.preference.register(
'tab_settings', 'qt_tab_title_placeholder', 'tab_settings', 'qt_tab_title_placeholder',
gettext("Query tool tab title"), gettext("Query tool tab title"),
'text', '%DATABASE%/%USERNAME%@%SERVER%', 'text', QT_DEFAULT_PLACEHOLDER,
category_label=PREF_LABEL_DISPLAY, category_label=PREF_LABEL_DISPLAY,
help_str=gettext( help_str=gettext(
'Supported placeholders are %DATABASE%, %USERNAME%, and %SERVER%. ' 'Supported placeholders are %DATABASE%, %USERNAME%, and %SERVER%. '

View File

@ -56,6 +56,7 @@ define('pgadmin.browser.utils',
pgAdmin['enable_psql'] = '{{ current_app.config.get('ENABLE_PSQL') }}' == 'True'; 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['allow_psql_shell_commands'] = '{{ current_app.config.get('ALLOW_PSQL_SHELL_COMMANDS') }}' == 'True';
pgAdmin['platform'] = '{{platform}}'; pgAdmin['platform'] = '{{platform}}';
pgAdmin['qt_default_placeholder'] = '{{qt_default_placeholder}}'
/* GET Binary Path Browse config */ /* GET Binary Path Browse config */
pgAdmin['enable_binary_path_browsing'] = '{{ current_app.config.get('ENABLE_BINARY_PATH_BROWSING') }}' == 'True'; pgAdmin['enable_binary_path_browsing'] = '{{ current_app.config.get('ENABLE_BINARY_PATH_BROWSING') }}' == 'True';

View File

@ -191,6 +191,17 @@ let NewConnectionDialog = {
self.showNewConnectionProgress[0] self.showNewConnectionProgress[0]
).addClass('d-none'); ).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) { callback: function(e) {
let self = this; let self = this;
if (e.button.element.name == 'dialog_help') { if (e.button.element.name == 'dialog_help') {
@ -210,19 +221,11 @@ let NewConnectionDialog = {
} }
}); });
let tab_title = ''; let tab_title = '';
var qt_title_placeholder = preferences['qt_tab_title_placeholder']; 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']) { tab_title = this.get_title(qt_title_placeholder, selected_database_name, newConnCollectionModel, response);
qt_title_placeholder = qt_title_placeholder.replace(new RegExp('%USERNAME%'), newConnCollectionModel['role']); let qt_default_placeholder = pgAdmin['qt_default_placeholder'];
} else { let conn_title = this.get_title(qt_default_placeholder, selected_database_name, newConnCollectionModel, response);
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;
if(!newConnCollectionModel['role']) { if(!newConnCollectionModel['role']) {
newConnCollectionModel['role'] = null; newConnCollectionModel['role'] = null;
@ -247,6 +250,7 @@ let NewConnectionDialog = {
'server': newConnCollectionModel['server'], 'server': newConnCollectionModel['server'],
'database': newConnCollectionModel['database'], 'database': newConnCollectionModel['database'],
'title': _.escape(tab_title), 'title': _.escape(tab_title),
'conn_title': _.escape(conn_title),
'user': newConnCollectionModel['user'], 'user': newConnCollectionModel['user'],
'role': newConnCollectionModel['role'], 'role': newConnCollectionModel['role'],
'server_name': _.escape(response.server_name), 'server_name': _.escape(response.server_name),

View File

@ -23,7 +23,7 @@ function isServerInformationAvailable(parentData) {
return parentData.server === undefined; 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'); var preferences = pgBrowser.get_preferences_for_module('browser');
if(selected_item == null && parentData == null) { if(selected_item == null && parentData == null) {
selected_item = pgBrowser.treeMenu.selected(); selected_item = pgBrowser.treeMenu.selected();
@ -38,10 +38,14 @@ export function getPanelTitle(pgBrowser, selected_item=null, custom_title=null,
const db_label = getDatabaseLabel(parentData); const db_label = getDatabaseLabel(parentData);
var qt_title_placeholder = ''; var qt_title_placeholder = '';
if (custom_title) { if (!conn_title) {
qt_title_placeholder = custom_title; if (custom_title) {
qt_title_placeholder = custom_title;
} else {
qt_title_placeholder = preferences['qt_tab_title_placeholder'];
}
} else { } else {
qt_title_placeholder = preferences['qt_tab_title_placeholder']; qt_title_placeholder = pgAdmin['qt_default_placeholder'];
} }
var title_data = { var title_data = {

View File

@ -110,7 +110,7 @@ define('tools.querytool', [
this.set_server_version(opts.server_ver); this.set_server_version(opts.server_ver);
this.trigger('pgadmin-sqleditor:view:initialised'); this.trigger('pgadmin-sqleditor:view:initialised');
this.connection_list = [ this.connection_list = [
{'server_group': null,'server': null, 'database': null, 'user': null, 'role': null, 'title': '&lt;' + gettext('New Connection') + '&gt;'}, {'server_group': null,'server': null, 'database': null, 'user': null, 'role': null, 'conn_title': '&lt;' + gettext('New Connection') + '&gt;'},
]; ];
}, },
@ -184,9 +184,9 @@ define('tools.querytool', [
data_list.forEach((option, index) => { data_list.forEach((option, index) => {
var opt = ''; var opt = '';
if ('is_selected' in option && option['is_selected']) { if ('is_selected' in option && option['is_selected']) {
opt = '<li class="connection-list-item selected-connection" data-index='+ index +'><a class="dropdown-item" href="#" tabindex="0">'+ option.title +'</a></li>'; opt = '<li class="connection-list-item selected-connection" data-index='+ index +'><a class="dropdown-item" href="#" tabindex="0">'+ option.conn_title +'</a></li>';
} else { } else {
opt = '<li class="connection-list-item" data-index='+ index +'><a class="dropdown-item" href="#" tabindex="0">'+ option.title +'</a></li>'; opt = '<li class="connection-list-item" data-index='+ index +'><a class="dropdown-item" href="#" tabindex="0">'+ option.conn_title +'</a></li>';
} }
$('#connections-list').append(opt); $('#connections-list').append(opt);
}); });
@ -2284,7 +2284,7 @@ define('tools.querytool', [
'sid': connection_details['server'], 'sid': connection_details['server'],
'title': connection_details['title'], '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)); self.handler.setTitle(_.unescape(self.handler.url_params.title));
let success_msg = connection_details['server_name'] + '/' + connection_details['database_name'] + '- Database connected'; let success_msg = connection_details['server_name'] + '/' + connection_details['database_name'] + '- Database connected';
alertify.success(success_msg); alertify.success(success_msg);
@ -2295,6 +2295,7 @@ define('tools.querytool', [
'database': connection_details['database'], 'database': connection_details['database'],
'user': connection_details['user'], 'user': connection_details['user'],
'title': connection_details['title'], 'title': connection_details['title'],
'conn_title': connection_details['conn_title'],
'role': connection_details['role'], 'role': connection_details['role'],
'is_allow_new_connection': true, 'is_allow_new_connection': true,
'database_name': connection_details['database_name'], '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 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)); var database_data = pgWindow.default.pgAdmin.Browser.treeMenu.findNode(tree_data.slice(0,4));
let conn_title = panelTitleFunc.getPanelTitle(pgWindow.default.pgAdmin.Browser, null, null, null, true);
self.gridView.set_editor_title(_.unescape(conn_title));
self.gridView.set_editor_title(_.unescape(url_params.title));
let connection_data = { let connection_data = {
'server_group': self.gridView.handler.url_params.sgid, 'server_group': self.gridView.handler.url_params.sgid,
'server': self.gridView.handler.url_params.sid, 'server': self.gridView.handler.url_params.sid,
@ -2683,6 +2682,7 @@ define('tools.querytool', [
'user': server_data.data.user.name, 'user': server_data.data.user.name,
'role': null, 'role': null,
'title': _.unescape(url_params.title), 'title': _.unescape(url_params.title),
'conn_title': _.unescape(conn_title),
'is_allow_new_connection': false, 'is_allow_new_connection': false,
'database_name': _.unescape(database_data.data.label), 'database_name': _.unescape(database_data.data.label),
'server_name': _.unescape(server_data.data.label), 'server_name': _.unescape(server_data.data.label),

View File

@ -31,6 +31,9 @@ UNAUTH_REQ = "Unauthorized request."
SERVER_CONNECTION_CLOSED = gettext( SERVER_CONNECTION_CLOSED = gettext(
'Not connected to server or connection with the server has been closed.') 'Not connected to server or connection with the server has been closed.')
# Query tool placeholder
QT_DEFAULT_PLACEHOLDER = '%DATABASE%/%USERNAME%@%SERVER%'
# Data Types # Data Types
DATATYPE_TIME_WITH_TIMEZONE = 'time with time zone' DATATYPE_TIME_WITH_TIMEZONE = 'time with time zone'
DATATYPE_TIME_WITHOUT_TIMEZONE = 'time without time zone' DATATYPE_TIME_WITHOUT_TIMEZONE = 'time without time zone'