/** @jsx React.DOM */
var PermissionsTable = React.createClass({
render: function() {
var rows = [];
var resources = _.sortBy(this.props.resources, function(r){
return r.id.split(':')[2];
});
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);
return
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: [], loaded: false, expand: false}
},
expand: function(event) {
this.setState({expand: true})
},
collapse: function(event) {
this.setState({expand: false})
},
componentWillMount: function() {
$.get(this.url(), function(data){
this.setPermissions(data);
}.bind(this));
},
setPermissions: function(_resources) {
/**
* Filter out owned resources
*/
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;
this.setState({resources: resources, loaded: true});
},
render: function(){
var content;
if (this.state.loaded) {
if ( this.state.expand )
content =
else
content =
}
else {
content = Loading...
}
var cx = React.addons.classSet;
var classes = cx({
permissions: true,
loading: !this.state.loaded
});
return
Permissions held
{content}
;
},
url: function(){
return "/api/authz/" + conjurConfiguration.account + "/resources?acting_as=" + this.props.role;
}
})