Fixed an issue where connection to the server is on wait state if a different user is provided. Fixes #5953

This commit is contained in:
Nikhil Mohite 2020-10-28 12:32:22 +05:30 committed by Akshay Joshi
parent 71a8c0f317
commit 6c723a7e43
5 changed files with 128 additions and 92 deletions

View File

@ -28,3 +28,4 @@ Bug fixes
| `Issue #5911 <https://redmine.postgresql.org/issues/5911>`_ - Ensure that macros should be run on the older version of Safari and Chrome.
| `Issue #5919 <https://redmine.postgresql.org/issues/5919>`_ - Added security related enhancements.
| `Issue #5923 <https://redmine.postgresql.org/issues/5923>`_ - Fixed an issue where non-closeable tabs are getting closed.
| `Issue #5953 <https://redmine.postgresql.org/issues/5953>`_ - Fixed an issue where connection to the server is on wait state if a different user is provided.

View File

@ -131,7 +131,7 @@ let NewConnectionDialog = {
self.showNewConnectionProgress[0]
).removeClass('d-none');
self.newConnCollectionModel = newConnectionDialogModel(response, handler.url_params.sgid, handler.url_params.sid);
self.newConnCollectionModel = newConnectionDialogModel(response, handler.url_params.sgid, handler.url_params.sid, handler, self);
let fields = Backform.generateViewSchema(null, self.newConnCollectionModel, 'create', null, null, true);
let view = this.view = new Backform.Dialog({
@ -240,6 +240,7 @@ let NewConnectionDialog = {
'role': newConnCollectionModel['role'],
'server_name': _.escape(response.server_name),
'database_name': _.escape(selected_database_name),
'password': response.password,
'is_selected': false,
};
handler.gridView.on_change_connection(connection_details, self);

View File

@ -15,7 +15,7 @@ import Backform from 'pgadmin.backform';
import url_for from 'sources/url_for';
import alertify from 'pgadmin.alertifyjs';
export default function newConnectionDialogModel(response, sgid, sid) {
export default function newConnectionDialogModel(response, sgid, sid, handler, conn_self) {
let server_name = '';
let database_name = '';
@ -158,12 +158,13 @@ export default function newConnectionDialogModel(response, sgid, sid) {
alertify.dialog('connectServer', function factory() {
return {
main: function(
title, message, server_id, submit_password=true
title, message, server_id, submit_password=true, connect_server=null,
) {
this.set('title', title);
this.message = message;
this.server_id = server_id;
this.submit_password = submit_password;
this.connect_server = connect_server;
},
setup:function() {
return {
@ -185,11 +186,11 @@ export default function newConnectionDialogModel(response, sgid, sid) {
this.setContent(this.message);
},
callback: function(closeEvent) {
var loadingDiv = $('#show_filter_progress');
if (closeEvent.button.text == gettext('OK')) {
if(this.submit_password) {
var _url = url_for('sqleditor.connect_server', {'sid': this.server_id});
var loadingDiv = $('#show_filter_progress');
loadingDiv.removeClass('d-none');
$.ajax({
type: 'POST',
@ -218,13 +219,26 @@ export default function newConnectionDialogModel(response, sgid, sid) {
alertify.connectServer().destroy();
alertify.connectServer('Connect to server', xhr.responseJSON.result, local_self.getValueFromDOM());
});
} else {
if(Object.keys(this.connect_server).length > 0) {
this.connect_server['password'] = $('#password').val();
this.connect_server['is_selected'] = false;
handler.gridView.on_change_connection(this.connect_server, conn_self, false);
loadingDiv = $('#fetching_data');
loadingDiv.addClass('d-none');
} else {
response.password = $('#password').val();
loadingDiv.addClass('d-none');
}
}
} else {
local_self.model.attributes.database = null;
local_self.model.attributes.user = null;
local_self.model.attributes.role = null;
Backform.Select2Control.prototype.onChange.apply(local_self, arguments);
loadingDiv.addClass('d-none');
alertify.connectServer().destroy();
}
closeEvent.close = true;
},

View File

@ -466,7 +466,7 @@ def update_query_tool_connection(trans_id, sgid, sid, did):
new_trans_id = str(random.randint(1, 9999999))
kwargs = {
'user': data['user'],
'role': data['role'],
'role': data['role'] if 'role' in data else None,
'password': data['password'] if 'password' in data else None
}

View File

@ -2125,7 +2125,7 @@ define('tools.querytool', [
set_selected_option: function(selected_config) {
this.connection_list.forEach(option =>{
if(option['server'] == selected_config['server'] && option['database'] == selected_config['database']) {
if(option['server'] == selected_config['server'] && option['database'] == selected_config['database'] && option['user'] == selected_config['user'] && option['role'] == selected_config['role']) {
selected_config['is_selected'] = true;
} else {
option['is_selected'] = false;
@ -2133,96 +2133,115 @@ define('tools.querytool', [
});
},
on_change_connection: function(connection_details, ref) {
on_change_connection: function(connection_details, ref, add_new_connection=true) {
if(!connection_details['is_selected']) {
var self = this;
var loadingDiv = null;
var msgDiv = null;
if(ref){
loadingDiv = $('#show_filter_progress');
loadingDiv.removeClass('d-none');
msgDiv = loadingDiv.find('.sql-editor-busy-text');
msgDiv.text('Connecting to database...');
} else{
loadingDiv = $('#fetching_data');
loadingDiv.removeClass('d-none');
msgDiv = loadingDiv.find('.sql-editor-busy-text');
if(add_new_connection) {
alertify.confirm(gettext('Change connection'),
gettext('By changing the connection you will lose all your unsaved data for the current connection. <br> Do you want to continue?'),
function() {
self.change_connection(connection_details, ref, true);
},
function() {
var loadingDiv = $('#fetching_data');
loadingDiv.addClass('d-none');
alertify.newConnectionDialog().destroy();
return true;
}
).set('labels', {
ok: gettext('Yes'),
cancel: gettext('No'),
});
} else {
self.change_connection(connection_details, ref, false);
}
alertify.confirm(gettext('Change connection'),
gettext('By changing the connection you will lose all your unsaved data for the current connection. <br> Do you want to continue?'),
function() {
self.set_selected_option(connection_details);
$.ajax({
url: url_for('datagrid.update_query_tool_connection', {
'trans_id': self.transId,
'sgid': connection_details['server_group'],
'sid': connection_details['server'],
'did': connection_details['database'],
}),
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(connection_details),
})
.done(function(res) {
if(res.success) {
self.transId = res.data.tran_id;
self.handler.transId = res.data.tran_id;
self.handler.url_params = {
'did': connection_details['database'],
'is_query_tool': self.handler.url_params.is_query_tool,
'server_type': self.handler.url_params.server_type,
'sgid': connection_details['server_group'],
'sid': connection_details['server'],
'title': connection_details['title'],
};
self.set_editor_title(_.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';
alertify.success(success_msg);
if(ref){
let connection_data = {
'server_group': self.handler.url_params.sgid,
'server': connection_details['server'],
'database': connection_details['database'],
'user': connection_details['user'],
'title': connection_details['title'],
'role': connection_details['role'],
'is_allow_new_connection': true,
'database_name': connection_details['database_name'],
'server_name': connection_details['server_name'],
'is_selected': true,
};
self.connection_list.unshift(connection_data);
self.render_connection(self.connection_list);
loadingDiv.addClass('d-none');
alertify.newConnectionDialog().destroy();
ref.close();
} else {
loadingDiv.addClass('d-none');
}
}
return true;
})
.fail(function(xhr) {
if(xhr.status == 428) {
alertify.connectServer('Connect to server', xhr.responseJSON.result, connection_details['server'], false);
} else {
alertify.error(xhr.responseJSON['errormsg']);
}
});
},
function() {
loadingDiv.addClass('d-none');
alertify.newConnectionDialog().destroy();
return true;
}
).set('labels', {
ok: gettext('Yes'),
cancel: gettext('No'),
});
}
},
change_connection: function(connection_details, ref, add_new_connection) {
var self = this;
var loadingDiv = null;
var msgDiv = null;
if(ref){
loadingDiv = $('#show_filter_progress');
loadingDiv.removeClass('d-none');
msgDiv = loadingDiv.find('.sql-editor-busy-text');
msgDiv.text('Connecting to database...');
} else{
loadingDiv = $('#fetching_data');
loadingDiv.removeClass('d-none');
msgDiv = loadingDiv.find('.sql-editor-busy-text');
}
self.set_selected_option(connection_details);
$.ajax({
url: url_for('datagrid.update_query_tool_connection', {
'trans_id': self.transId,
'sgid': connection_details['server_group'],
'sid': connection_details['server'],
'did': connection_details['database'],
}),
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(connection_details),
})
.done(function(res) {
if(res.success) {
delete connection_details.password;
self.transId = res.data.tran_id;
self.handler.transId = res.data.tran_id;
self.handler.url_params = {
'did': connection_details['database'],
'is_query_tool': self.handler.url_params.is_query_tool,
'server_type': self.handler.url_params.server_type,
'sgid': connection_details['server_group'],
'sid': connection_details['server'],
'title': connection_details['title'],
};
self.set_editor_title(_.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';
alertify.success(success_msg);
if(ref){
let connection_data = {
'server_group': self.handler.url_params.sgid,
'server': connection_details['server'],
'database': connection_details['database'],
'user': connection_details['user'],
'title': connection_details['title'],
'role': connection_details['role'],
'is_allow_new_connection': true,
'database_name': connection_details['database_name'],
'server_name': connection_details['server_name'],
'is_selected': true,
};
delete connection_data.password;
if(add_new_connection) {
self.connection_list.unshift(connection_data);
}
self.render_connection(self.connection_list);
loadingDiv.addClass('d-none');
alertify.newConnectionDialog().destroy();
alertify.connectServer().destroy();
} else {
loadingDiv.addClass('d-none');
alertify.connectServer().destroy();
}
}
return true;
})
.fail(function(xhr) {
if(xhr.status == 428) {
var connection_info = connection_details;
if(ref) {
connection_info = {};
}
alertify.connectServer('Connect to server', xhr.responseJSON.result, connection_details['server'], false, connection_info);
} else {
alertify.error(xhr.responseJSON['errormsg']);
}
});
},
});
@ -2566,6 +2585,7 @@ define('tools.querytool', [
'server_name': _.unescape(server_data.data.label),
'is_selected': true,
};
delete connection_data.password;
self.gridView.connection_list.unshift(connection_data);
self.gridView.render_connection(self.gridView.connection_list);
};