/** @jsx React.DOM */
/* global conjur, React, _ */
(function(conjur, React, _) {
'use strict';
/** render a link to the role represented by this.props.id
Example:
*/
this.RoleLink = React.createClass({
render: function() {
// guard against misuse such as https://github.com/conjurinc/conjur-asset-ui/issues/78
if (this.props.id === undefined) {
return React.DOM.em({}, 'undefined');
}
var tokens = this.props.id.split(':'),
kind = tokens[1],
id = tokens[tokens.length-1],
href,
classes = ['role-link'],
knownTypes = ['user', 'group', 'layer', 'host', 'policy'],
kindIsKnown,
text;
if (tokens.length === 1) { // just username
kind = 'user';
id = tokens[0];
}
// TODO: shouldn't point to unknown types
href = '/ui/' + conjur.utils.pluralize(kind) + '/' + window.encodeURIComponent(id);
kindIsKnown = _.contains(knownTypes, kind);
text = id;
if (!this.props.noIcon) {
if (kindIsKnown) {
classes.push(kind);
} else {
classes.push('abstract'); // we have no picture for abstract role yet
if (text === id) {
text = [kind, text].join(':'); // prepend kind to id
}
}
} else if (text === id) {
text = [kind, text].join(':'); // prepend kind to id
}
return (
{text}
);
}
});
}).bind(conjur.views)
(
conjur,
React,
_
);