public in the privilege control should not be allowed to select the

'WITH GRANT' options.
This commit is contained in:
Harshal Dhumal
2016-02-22 17:36:04 +05:30
committed by Ashesh Vashi
parent 8186e45844
commit 0b956813d4

View File

@@ -152,9 +152,19 @@
privileges.add(p, {silent: true});
});
this.on("change:grantee", this.granteeChanged)
return this;
},
granteeChanged: function() {
var privileges = this.get('privileges'),
grantee = this.get('grantee');
// Reset all with grant options if grantee is public.
if (grantee == 'public') {
privileges.each(function(m) {
m.set("with_grant", false);
});
}
},
toJSON: function(session) {
if (session) {
return pgNode.Model.prototype.toJSON.apply(this, arguments);
@@ -231,7 +241,7 @@
' </td>',
' <td class="renderable">',
' <label>',
' <input type="checkbox" name="with_grant" privilege="<%- privilege_type %>" target="<%- target %>" <%= with_grant ? \'checked\' : "" %> <%= privilege ? "" : \'disabled\'%>></input>',
' <input type="checkbox" name="with_grant" privilege="<%- privilege_type %>" target="<%- target %>" <%= with_grant ? \'checked\' : "" %> <%= enable_with_grant ? "" : \'disabled\'%>></input>',
' WITH GRANT OPTION',
' </label>',
' </td>',
@@ -264,7 +274,9 @@
d, {
'target': self.cid,
'header': false,
'privilege_label': self.Labels[d.privilege_type]
'privilege_label': self.Labels[d.privilege_type],
'with_grant': (self.model.get('grantee') != 'public' && d.with_grant),
'enable_with_grant': (self.model.get('grantee') != 'public' && d.privilege)
});
privilege = (privilege && d.privilege);
with_grant = (with_grant && privilege && d.with_grant);
@@ -279,7 +291,8 @@
'privilege_label': 'ALL',
'privilege_type': 'ALL',
'privilege': privilege,
'with_grant': with_grant,
'with_grant': (self.model.get('grantee') != 'public' && with_grant),
'enable_with_grant': (self.model.get('grantee') != 'public' && privilege),
'header': true
}));
}
@@ -311,7 +324,8 @@
checked = $el.prop('checked'),
$tr = $el.closest('tr'),
$tbl = $tr.closest('table'),
collection = this.model.get('privileges');
collection = this.model.get('privileges'),
grantee = this.model.get('grantee');
/*
* If the checkbox selected/deselected is for 'ALL', we will select all
@@ -341,8 +355,14 @@
* We have clicked the ALL checkbox, we should be able to select
* the grant options too.
*/
if (grantee == 'public') {
$allGrants.prop('disabled', true);
$elGrant.prop('disabled', true);
} else {
$allGrants.prop('disabled', false);
$elGrant.prop('disabled', false);
}
} else {
/*
* ALL checkbox has been deselected, hence - we need to make
@@ -402,7 +422,7 @@
$allPrivilege.prop('checked', false);
$allGrant.prop('disabled', true);
$allGrant.prop('checked', false);
} else {
} else if (grantee != "public") {
$elGrant.prop('disabled', false);
}
} else if (!checked) {
@@ -428,7 +448,7 @@
$allGrant.prop('disabled', false);
$allGrant.prop('checked', true);
}
} else {
} else if (grantee != "public") {
$allGrant.prop('disabled', false);
}
}
@@ -519,7 +539,24 @@
var PrivilegeCell = Backgrid.Extension.PrivilegeCell = Backgrid.Cell.extend({
className: "edit-cell",
formatter: PrivilegeCellFormatter,
editor: PrivilegeCellEditor
editor: PrivilegeCellEditor,
initialize: function (options) {
var self = this;
Backgrid.Cell.prototype.initialize.apply(this, arguments);
self.model.on("change:grantee", function () {
if (!self.$el.hasClass("editor")) {
/*
* Add time out before render; As we might want to wait till model
* is updated by PrivilegeRoleModel:granteeChanged.
*/
setTimeout(function() {
self.render();
},10);
}
});
}
});
return PrivilegeRoleModel;