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 #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 #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
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})

View File

@ -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%. '

View File

@ -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';

View File

@ -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),

View File

@ -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 = {

View File

@ -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': '&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) => {
var opt = '';
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 {
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);
});
@ -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),

View File

@ -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'