/** @jsx React.DOM */
var PermissionsTable = React.createClass({
render: function() {
var rows = [];
var resources = _.sortBy(this.props.resources, function(r){
return r.id; // this way it will be sorting by (kind, id)
});
resources.forEach(function(r){
var rowspan = r.permissions.length + 1;
var parts = r.id.split(":");
var id = parts[2];
var kind = parts[1]; // ignore env?
var cells = [
| ,
{kind} |
];
if(rowspan == 1){
cells.push( full permissions | );
}
rows.push(
{cells}
);
if(rowspan > 1){
rows.push(r.permissions.map(function(p){
return
}));
}
});
rows = _.flatten(rows);
var showhidelink = ;
if (this.props.tabview) {
showhidelink="";
}
if (rows.length==0) {
return None;
}
return
{showhidelink}
Resource |
Kind |
Privilege |
Can Grant? |
Granted By |
{rows}
}
});
// Renders a permission as a tr
var PermissionRow = React.createClass({
render: function(){
var p = this.props.data;
return
{ p.privilege } |
{ p.grant_option ? "yes" : "no" } |
|
;
}
});
var PermissionsSummary = React.createClass({
render: function() {
var expand = "";
if ( this.props.length > 0 )
expand =
Show all »
;
return
{this.props.length} permissions
{expand}
}
});
var Permissions = React.createClass({
getInitialState: function() {
return {resources: null, loaded: false, expand: false}
},
expand: function(event) {
this.setState({expand: true})
},
collapse: function(event) {
this.setState({expand: false})
},
componentWillMount: function() { // shouldn't it be done in model??? otherwise it will re-load stuff on each re-rendering of parent block
if ( this.props.roles ) {
$.get(this.url(), function(data){
this.setPermissions(data);
}.bind(this));
}
},
setPermissions: function(_resources) {
/**
* Filter out owned resources.
* Filter out permissions on resources which are not held by the current role.
*/
var resources;
if ( this.props.owned ) {
var ownedIds = _.pluck(this.props.owned, 'id');
resources = _resources.filter(function(r) {
return !_.contains(ownedIds, r.id);
});
}
else
resources = _resources;
var roleSet = {};
this.props.roles.forEach(function(r) {
roleSet[r] = r;
});
var cleanResources = resources.filter(function(item) {
return item.id.split(':')[1] !== "secret"; // assets of 'secret' kind are internal
});
cleanResources.forEach(function(resource) {
var permissions = resource.permissions;
var hasPermissions = [];
permissions.forEach(function(permission) {
if ( roleSet.hasOwnProperty(permission['role']) )
hasPermissions.push(permission);
});
resource.permissions = hasPermissions;
});
this.setState({resources: cleanResources, loaded: true});
},
render: function(){
var content;
if (this.state.loaded) {
if ( this.state.expand || this.props.tabview )
content =
else
content =
}
else {
if ( this.props.roles )
content = Loading...
else
content = "You are not authorized to see these permissions";
}
var cx = React.addons.classSet;
var classes = cx({
permissions: true,
loading: !this.state.loaded
});
var permissionsheader = this.props.tabview ? "" : Permissions held
;
return
{permissionsheader}
{content}
;
},
url: function(){
return "/api/authz/" + conjur.app.configuration.account + "/resources?acting_as=" + this.props.role;
}
})