Port connect server password dialog to React. Fixes #7337

This commit is contained in:
Akshay Joshi
2022-05-16 16:21:14 +05:30
parent 7686c33cbd
commit 44f9ba4a57
14 changed files with 205 additions and 218 deletions

View File

@@ -1284,7 +1284,7 @@ class ServerNode(PGChildNodeView):
}
)
def connect(self, gid, sid, user_name=None, resp_json=False):
def connect(self, gid, sid):
"""
Connect the Server and return the connection object.
Verification Process before Connection:
@@ -1410,8 +1410,7 @@ class ServerNode(PGChildNodeView):
# not provided, or password has not been saved earlier.
if prompt_password or prompt_tunnel_password:
return self.get_response_for_password(
server, 428, prompt_password, prompt_tunnel_password,
user=user_name, resp_json=resp_json
server, 428, prompt_password, prompt_tunnel_password
)
status = True
@@ -1427,8 +1426,7 @@ class ServerNode(PGChildNodeView):
except Exception as e:
current_app.logger.exception(e)
return self.get_response_for_password(
server, 401, True, True, getattr(e, 'message', str(e)),
resp_json=resp_json)
server, 401, True, True, getattr(e, 'message', str(e)))
if not status:
@@ -1440,7 +1438,7 @@ class ServerNode(PGChildNodeView):
return internal_server_error(errmsg)
return self.get_response_for_password(
server, 401, True, True, errmsg, resp_json=resp_json
server, 401, True, True, errmsg
)
else:
if save_password and config.ALLOW_SAVE_PASSWORD:
@@ -1864,8 +1862,7 @@ class ServerNode(PGChildNodeView):
return internal_server_error(errormsg=str(e))
def get_response_for_password(self, server, status, prompt_password=False,
prompt_tunnel_password=False, errmsg=None,
user=None, resp_json=False):
prompt_tunnel_password=False, errmsg=None):
if server.use_ssh_tunnel:
data = {
@@ -1888,11 +1885,7 @@ class ServerNode(PGChildNodeView):
return make_json_response(
success=0,
status=status,
result=render_template(
'servers/tunnel_password.html',
_=gettext,
**data,
) if not resp_json else data
result=data
)
else:
data = {
@@ -1908,11 +1901,7 @@ class ServerNode(PGChildNodeView):
return make_json_response(
success=0,
status=status,
result=render_template(
'servers/password.html',
_=gettext,
**data
) if not resp_json else data
result=data
)
def clear_saved_password(self, gid, sid):

View File

@@ -12,6 +12,7 @@ import { getNodePrivilegeRoleSchema } from '../../../static/js/privilege.ui';
import { getNodeVariableSchema } from '../../../static/js/variable.ui';
import DatabaseSchema from './database.ui';
import Notify from '../../../../../../static/js/helpers/Notifier';
import { showServerPassword } from '../../../../../static/js/password_dialogs';
define('pgadmin.node.database', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
@@ -400,11 +401,11 @@ define('pgadmin.node.database', [
if (msg == 'CRYPTKEY_SET') {
connect_to_database(_model, _data, _tree, _item, _wasConnected);
} else {
Alertify.dlgServerPass(
showServerPassword(
gettext('Connect to database'),
msg, _model, _data, _tree, _item, _status,
onSuccess, onFailure, onCancel
).resizeTo();
);
}
}, 100);
});

View File

@@ -10,6 +10,7 @@
import { getNodeListById } from '../../../../static/js/node_ajax';
import ServerSchema from './server.ui';
import Notify from '../../../../../static/js/helpers/Notifier';
import { showServerPassword } from '../../../../static/js/password_dialogs';
define('pgadmin.node.server', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
@@ -885,10 +886,11 @@ define('pgadmin.node.server', [
if (msg == 'CRYPTKEY_SET') {
connect_to_server(_node, _data, _tree, _item, _wasConnected);
} else if (msg != 'CRYPTKEY_NOT_SET') {
Alertify.dlgServerPass(
showServerPassword(
gettext('Connect to Server'),
msg, _node, _data, _tree, _item, _wasConnected
).resizeTo();
msg, _node, _data, _tree, _item, _wasConnected, onSuccess,
onFailure, onCancel
);
}
}, 100);
});
@@ -954,88 +956,6 @@ define('pgadmin.node.server', [
}
};
// Ask Password and send it back to the connect server
if (!Alertify.dlgServerPass) {
Alertify.dialog('dlgServerPass', function factory() {
return {
main: function(
title, message, node, _data, _tree, _item,
_status, _onSuccess, _onFailure, _onCancel
) {
this.set('title', title);
this.message = message;
this.tree = _tree;
this.nodeData = _data;
this.nodeItem = _item;
this.node= node;
this.connected = _status;
this.onSuccess = _onSuccess || onSuccess;
this.onFailure = _onFailure || onFailure;
this.onCancel = _onCancel || onCancel;
},
setup:function() {
return {
buttons:[{
text: gettext('Cancel'), className: 'btn btn-secondary fa fa-times pg-alertify-button',
key: 27,
},{
text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button',
}],
focus: {element: '#password', select: true},
options: {
modal: 0, resizable: false, maximizable: false, pinnable: false,
},
};
},
build:function() {/*This is intentional (SonarQube)*/},
prepare:function() {
this.setContent(this.message);
},
callback: function(closeEvent) {
var _tree = this.tree,
_item = this.nodeItem,
_node = this.node,
_data = this.nodeData,
_status = this.connected,
_onSuccess = this.onSuccess,
_onFailure = this.onFailure,
_onCancel = this.onCancel;
if (closeEvent.button.text == gettext('OK')) {
var _url = _node.generate_url(_item, 'connect', _data, true);
if (!_status) {
_tree.setLeaf(_item);
_tree.removeIcon(_item);
_tree.addIcon(_item, {icon: 'icon-server-connecting'});
}
$.ajax({
type: 'POST',
timeout: 30000,
url: _url,
data: $('#frmPassword').serialize(),
})
.done(function(res) {
return _onSuccess(
res, _node, _data, _tree, _item, _status
);
})
.fail(function(xhr, status, error) {
return _onFailure(
xhr, status, error, _node, _data, _tree, _item, _status
);
});
} else {
_onCancel && typeof(_onCancel) == 'function' &&
_onCancel(_tree, _item, _data, _status);
}
},
};
});
}
var onCancel = function(_tree, _item, _data, _status) {
_data.is_connecting = false;
_tree.unload(_item);