Resolved an issue about missing 'canDrop' function check for the browser
tree nodes.
Each individual node is responsible for introducing the 'canDrop'
function/flag to decide whether the 'Delete/Drop' context menu should be
enabled/disabled.
In commit-id: 26aa5607ad
, 'obj.canDrop'
was set to true in the 'pgBrowser.Node' in delete callback, just to make
the server-group droppable, which is wrong, as all the nodes are
getting affected because of this change in a wrong way.
To fix the issue, added the 'canDrop' function in the server-group node.
Apart from them, also added restriction for not allowing to delete the
default server-group.
Also, handled the same restriction at the server end.
pull/3/head
parent
d1e3237e2e
commit
2c7a45814c
|
@ -107,6 +107,16 @@ class ServerGroupView(NodeView):
|
|||
def delete(self, gid):
|
||||
"""Delete a server group node in the settings database"""
|
||||
|
||||
# if server group id is 1 we won't delete it.
|
||||
if gid == 1:
|
||||
return make_json_response(
|
||||
status=417,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified server group cannot be deleted.'
|
||||
)
|
||||
)
|
||||
|
||||
# There can be only one record at most
|
||||
servergroup = ServerGroup.query.filter_by(
|
||||
user_id=current_user.id,
|
||||
|
|
|
@ -19,11 +19,6 @@ function($, _, pgAdmin, Backbone) {
|
|||
applies: ['object', 'context'], callback: 'show_obj_properties',
|
||||
category: 'create', priority: 1, label: '{{ _('Server Group...') }}',
|
||||
data: {'action': 'create'}, icon: 'wcTabIcon icon-server-group'
|
||||
}, {
|
||||
name: 'drop_server_group', node: 'server-group', module: this,
|
||||
applies: ['object', 'context'], callback: 'delete_obj',
|
||||
priority: 2, label: '{{ _('Drop Server Group...') }}',
|
||||
icon: 'fa fa-trash'
|
||||
}]);
|
||||
},
|
||||
model: pgAdmin.Browser.Node.Model.extend({
|
||||
|
@ -50,6 +45,12 @@ function($, _, pgAdmin, Backbone) {
|
|||
return null;
|
||||
}
|
||||
}),
|
||||
canDrop: function(itemData, item, data) {
|
||||
if(itemData._id == 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
canDelete: function(i) {
|
||||
var s = pgAdmin.Browser.tree.siblings(i, true);
|
||||
|
||||
|
|
|
@ -470,7 +470,6 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
|
|||
delete_obj: function(args, item) {
|
||||
var input = args || {'url':'drop'};
|
||||
obj = this,
|
||||
obj.canDrop = true
|
||||
t = pgBrowser.tree,
|
||||
i = input.item || item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
@ -538,7 +537,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
|
|||
error: function(jqx) {
|
||||
var msg = jqx.responseText;
|
||||
/* Error from the server */
|
||||
if (jqx.status == 410 || jqx.status == 500) {
|
||||
if (jqx.status == 417 || jqx.status == 410 || jqx.status == 500) {
|
||||
try {
|
||||
var data = $.parseJSON(jqx.responseText);
|
||||
msg = data.errormsg;
|
||||
|
|
Loading…
Reference in New Issue