mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-25 18:20:20 -06:00
Make the privilege control to work as expected. Using the
NodeListByNameCell for selecting the grantee. This patch includes: - Change the RolePrivilegesModel schema to allow to use the NodeListByNameCell for showing grantee, and granter information. - When setting some value - do not use the silent flag in Select2Cell, which will allow the session manager to take the value in account, which is used by the NodeListByNameCell. - Set the top object in the children of the UniqueControl collections. [Ashesh Vashi] - Pass on the node information to the actual data model, so that - we can use node information by the control itself. [Ashesh Vashi] - While adding the new privilege, set the granter to the current user. [Ashesh Vashi]
This commit is contained in:
parent
1ce0db3b58
commit
4e5e7755b5
@ -115,7 +115,8 @@ class ServerModule(sg.ServerGroupPluginModule):
|
||||
{
|
||||
'name': 'pgadmin.browser.server.privilege',
|
||||
'path': url_for('browser.index') + 'server/static/js/privilege',
|
||||
'when': self.node_type
|
||||
'when': self.node_type,
|
||||
'deps': ['pgadmin.browser.node.ui']
|
||||
},
|
||||
{
|
||||
'name': 'pgadmin.browser.server.variable',
|
||||
|
@ -5,7 +5,7 @@
|
||||
function(_, $, Backbone, Backform, Backgrid, Alertify, pgNode) {
|
||||
// Export global even in AMD case in case this script is loaded with
|
||||
// others that may still expect a global Backform.
|
||||
return factory(root, _, $, Backbone, Backform, Alertify, pgNode);
|
||||
return factory(root, _, $, Backbone, Backform, Backgrid, Alertify, pgNode);
|
||||
});
|
||||
|
||||
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
|
||||
@ -14,15 +14,16 @@
|
||||
$ = root.jQuery || root.$ || root.Zepto || root.ender,
|
||||
Backbone = require('backbone') || root.Backbone,
|
||||
Backform = require('backform') || root.Backform;
|
||||
Backgrid = require('backgrid') || root.Backgrid;
|
||||
Alertify = require('alertify') || root.Alertify;
|
||||
pgAdmin = require('pgadmin.browser.node') || root.pgAdmin.Browser.Node;
|
||||
factory(root, _, $, Backbone, Backform, Alertify, pgNode);
|
||||
|
||||
// Finally, as a browser global.
|
||||
} else {
|
||||
factory(root, root._, (root.jQuery || root.Zepto || root.ender || root.$), root.Backbone, root.Backform, root.pgAdmin.Browser.Node);
|
||||
factory(root, root._, (root.jQuery || root.Zepto || root.ender || root.$), root.Backbone, root.Backform, root.Backgrid, root.alertify, root.pgAdmin.Browser.Node);
|
||||
}
|
||||
} (this, function(root, _, $, Backbone, Backform, Alertify, pgNode) {
|
||||
} (this, function(root, _, $, Backbone, Backform, Backgrid, Alertify, pgNode) {
|
||||
|
||||
/**
|
||||
* Each Privilege, supporeted by an database object, will be represented
|
||||
@ -65,17 +66,40 @@
|
||||
* provide the type of privileges (it supports).
|
||||
*/
|
||||
privileges:[],
|
||||
|
||||
schema: [{
|
||||
id: 'grantee', label:'Grantee', type:'text', group: null, cell: 'string',
|
||||
disabled: false, cellHeaderClasses: 'width_percent_40'
|
||||
}, {
|
||||
id: 'grantee', label:'Grantee', type:'text', group: null,
|
||||
editable: true, cellHeaderClasses: 'width_percent_40',
|
||||
cell: 'node-list-by-name', node: 'role',
|
||||
disabled : function(column, collection) {
|
||||
if (column instanceof Backbone.Collection) {
|
||||
// This has been called during generating the header cell
|
||||
return false;
|
||||
}
|
||||
return !(this.node_info && this.node_info.server.user.name == column.get('grantor'));
|
||||
},
|
||||
transform: function(data) {
|
||||
var res =
|
||||
Backgrid.Extension.NodeListByNameCell.prototype.defaults.transform.apply(
|
||||
this, arguments
|
||||
);
|
||||
res.unshift({label: 'public', value: 'public'});
|
||||
return res;
|
||||
}
|
||||
},{
|
||||
id: 'privileges', label:'Privileges',
|
||||
type: 'collection', model: PrivilegeModel, group: null,
|
||||
disabled: false, cell: 'privilege', control: 'text',
|
||||
cellHeaderClasses: 'width_percent_40'
|
||||
cell: 'privilege', control: 'text', cellHeaderClasses: 'width_percent_40',
|
||||
disabled : function(column, collection) {
|
||||
if (column instanceof Backbone.Collection) {
|
||||
// This has been called during generating the header cell
|
||||
return false;
|
||||
}
|
||||
return !(this.node_info && this.node_info.server.user.name == column.get('grantor') ||
|
||||
this.attributes.node_info.server.user.name == column.get('grantor'));
|
||||
}
|
||||
},{
|
||||
id: 'grantor', label: 'Granter', type: 'text', disabled: true
|
||||
id: 'grantor', label: 'Granter', type: 'text', disabled: true,
|
||||
cell: 'node-list-by-name', node: 'role'
|
||||
}],
|
||||
|
||||
/*
|
||||
@ -86,6 +110,14 @@
|
||||
|
||||
pgNode.Model.prototype.initialize.apply(this, arguments);
|
||||
|
||||
if (_.isNull(attrs)) {
|
||||
this.set(
|
||||
'grantor',
|
||||
opts && opts.top && opts.top.node_info && opts.top.node_info.server.user.name,
|
||||
{silent: true}
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the collection of the privilege supported by this model
|
||||
*/
|
||||
@ -437,7 +469,7 @@
|
||||
if (rawData instanceof Backbone.Collection) {
|
||||
rawData.each(function(m) {
|
||||
if (m.get('privilege')) {
|
||||
res += m.get('privilege_type');
|
||||
res += self.notation[m.get('privilege_type')];
|
||||
if (m.get('with_grant')) {
|
||||
res += '*';
|
||||
}
|
||||
|
@ -132,8 +132,10 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
|
||||
}
|
||||
|
||||
// We know - which data model to be used for this object.
|
||||
var newModel = new (this.model.extend({urlRoot: urlBase}))(attrs, {}),
|
||||
info = this.getTreeNodeHierarchy.apply(this, [item]),
|
||||
var info = this.getTreeNodeHierarchy.apply(this, [item]),
|
||||
newModel = new (this.model.extend({urlRoot: urlBase})) (
|
||||
attrs, {node_info: info}
|
||||
),
|
||||
groups = Backform.generateViewSchema(
|
||||
info, newModel, type, this, node
|
||||
);
|
||||
@ -1551,6 +1553,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
|
||||
(self.collection && self.collection.handler);
|
||||
self.trackChanges = false;
|
||||
self.errorModel = new Backbone.Model();
|
||||
self.node_info = options.node_info;
|
||||
|
||||
if (self.schema && _.isArray(self.schema)) {
|
||||
_.each(self.schema, function(s) {
|
||||
|
@ -75,7 +75,7 @@
|
||||
'collection': ['sub-node-collection', 'sub-node-collection', 'string'],
|
||||
'uniqueColCollection': ['unique-col-collection', 'unique-col-collection', 'string'],
|
||||
'switch' : 'switch',
|
||||
'select2': 'select2',
|
||||
'select2': 'select2'
|
||||
};
|
||||
|
||||
var getMappedControl = Backform.getMappedControl = function(type, mode) {
|
||||
@ -651,6 +651,7 @@
|
||||
model: self.field.get('model'),
|
||||
silent: true,
|
||||
handler: self.model.handler || self.model,
|
||||
top: self.model.top || self.model,
|
||||
attrName: self.field.get('name')
|
||||
});
|
||||
self.model.set(self.field.get('name'), collection, {silent: true});
|
||||
@ -725,7 +726,7 @@
|
||||
* conflicting with another model value.
|
||||
*/
|
||||
|
||||
m.set(uniqueChangedAttr[0], m.previous(uniqueChangedAttr[0]), {silent: true});
|
||||
m.set(uniqueChangedAttr[0], m.previous(uniqueChangedAttr[0]));
|
||||
}
|
||||
if (oldModel) {
|
||||
var idx = collection.indexOf(oldModel);
|
||||
@ -859,7 +860,11 @@
|
||||
}
|
||||
|
||||
$(grid.body.$el.find($("tr.new"))).removeClass("new")
|
||||
var m = new (data.model)(null, {silent: true});
|
||||
var m = new (data.model) (null, {
|
||||
silent: true,
|
||||
handler: self.model.handler || self.model,
|
||||
top: self.model.top || self.model
|
||||
});
|
||||
collection.add(m);
|
||||
|
||||
var idx = collection.indexOf(m),
|
||||
@ -1205,7 +1210,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
// After validation we need to set that value into model (only if all falgs are true)
|
||||
// After validation we need to set that value into model (only if all flags are true)
|
||||
if (isValid) {
|
||||
this.stopListening(this.model, "change:" + name, this.render);
|
||||
this.model.set(name, value);
|
||||
|
@ -367,7 +367,7 @@
|
||||
onSave: function (e) {
|
||||
var model = this.model;
|
||||
var column = this.column;
|
||||
model.set(column.get("name"), this.$select.val(),{silent:true});
|
||||
model.set(column.get("name"), this.$select.val());
|
||||
}
|
||||
});
|
||||
return Backgrid;
|
||||
|
Loading…
Reference in New Issue
Block a user