+import _ from 'underscore';
import Modal from '../../components/common/modals';
import '../../components/common/select-list';
import './templates';
function getSearchUrl (permission, permissionTemplate) {
- return baseUrl + '/api/permissions/template_groups?ps=100&permission=' + permission +
+ return baseUrl + '/api/permissions/template_groups?ps=100&permission=' + permission.key +
'&templateId=' + permissionTemplate.id;
}
selectUrl: baseUrl + '/api/permissions/add_group_to_template',
deselectUrl: baseUrl + '/api/permissions/remove_group_from_template',
extra: {
- permission: this.options.permission,
+ permission: this.options.permission.key,
templateId: this.options.permissionTemplate.id
},
selectParameter: 'groupName',
serializeData: function () {
return _.extend(Modal.prototype.serializeData.apply(this, arguments), {
+ permissionName: this.options.permission.name,
permissionTemplateName: this.options.permissionTemplate.name
});
}
export default React.createClass({
propTypes: {
- permissionTemplate: React.PropTypes.object.isRequired
+ permissionTemplate: React.PropTypes.object.isRequired,
+ topQualifiers: React.PropTypes.array.isRequired
},
- render() {
- if (_.size(this.props.permissionTemplate.defaultFor) === 0) {
- return null;
- }
+ renderIfSingleTopQualifier() {
+ return (
+ <ul className="list-inline nowrap spacer-bottom">
+ <li>Default</li>
+ </ul>
+ );
+ },
+
+ renderIfMultipleTopQualifiers() {
let defaults = this.props.permissionTemplate.defaultFor.map(qualifier => {
return <li key={qualifier}><QualifierIcon qualifier={qualifier}/> {window.t('qualifier', qualifier)}</li>;
});
{defaults}
</ul>
);
+ },
+
+ render() {
+ if (_.size(this.props.permissionTemplate.defaultFor) === 0) {
+ return null;
+ }
+ return this.props.topQualifiers.length === 1 ?
+ this.renderIfSingleTopQualifier() :
+ this.renderIfMultipleTopQualifiers();
}
});
setDefaultPermissionTemplate(this.props.permissionTemplate.id, qualifier).done(() => this.props.refresh());
},
- render() {
- let availableQualifiers = this.getAvailableQualifiers();
- if (availableQualifiers.length === 0) {
- return null;
- }
+ renderIfSingleTopQualifier(availableQualifiers) {
+ let qualifiers = availableQualifiers.map(qualifier => {
+ return (
+ <span key={qualifier} className="text-middle">
+ <a onClick={this.setDefault.bind(this, qualifier)} className="button" href="#">Set Default</a>
+ </span>
+ );
+ });
+ return <span className="little-spacer-right">{qualifiers}</span>;
+ },
+
+ renderIfMultipleTopQualifiers(availableQualifiers) {
let qualifiers = availableQualifiers.map(qualifier => {
return (
<li key={qualifier}>
<ul className="dropdown-menu">{qualifiers}</ul>
</span>
);
+ },
+
+ render() {
+ let availableQualifiers = this.getAvailableQualifiers();
+ if (availableQualifiers.length === 0) {
+ return null;
+ }
+
+ return this.props.topQualifiers.length === 1 ?
+ this.renderIfSingleTopQualifier(availableQualifiers) :
+ this.renderIfMultipleTopQualifiers(availableQualifiers);
}
});
<td className="spacer-right">Users</td>
<td className="spacer-left bordered-left">{p.usersCount}</td>
<td className="spacer-left">
- <a onClick={this.showUsers.bind(this, p.key)} className="icon-bullet-list" title="Update Users"
+ <a onClick={this.showUsers.bind(this, p)} className="icon-bullet-list" title="Update Users"
data-toggle="tooltip" href="#"></a>
</td>
</tr>
<td className="spacer-right">Groups</td>
<td className="spacer-left bordered-left">{p.groupsCount}</td>
<td className="spacer-left">
- <a onClick={this.showGroups.bind(this, p.key)} className="icon-bullet-list" title="Update Users"
+ <a onClick={this.showGroups.bind(this, p)} className="icon-bullet-list" title="Update Users"
data-toggle="tooltip" href="#"></a>
</td>
</tr>
{permissions}
<td className="thin text-right">
{this.renderAssociation()}
- <Defaults permissionTemplate={this.props.permissionTemplate}/>
+ <Defaults
+ permissionTemplate={this.props.permissionTemplate}
+ topQualifiers={this.props.topQualifiers}/>
<div className="nowrap">
<SetDefaults
permissionTemplate={this.props.permissionTemplate}
<div class="modal-head">
- <h2>Update Groups of "{{permissionTemplateName}}"</h2>
+ <h2>Update Groups for "{{permissionName}}" Permission of "{{permissionTemplateName}}" Template</h2>
</div>
<div class="modal-body">
<div class="js-modal-messages"></div>
<div class="modal-head">
- <h2>Update Users of "{{permissionTemplateName}}"</h2>
+ <h2>Update Users for "{{permissionName}}" Permission of "{{permissionTemplateName}}" Template</h2>
</div>
<div class="modal-body">
<div class="js-modal-messages"></div>
+import _ from 'underscore';
import Modal from '../../components/common/modals';
import '../../components/common/select-list';
import './templates';
onRender: function () {
this._super();
- var searchUrl = baseUrl + '/api/permissions/template_users?ps=100&permission=' + this.options.permission +
+ var searchUrl = baseUrl + '/api/permissions/template_users?ps=100&permission=' + this.options.permission.key +
'&templateId=' + this.options.permissionTemplate.id;
new window.SelectList({
el: this.$('#permission-templates-users'),
selectUrl: baseUrl + '/api/permissions/add_user_to_template',
deselectUrl: baseUrl + '/api/permissions/remove_user_from_template',
extra: {
- permission: this.options.permission,
+ permission: this.options.permission.key,
templateId: this.options.permissionTemplate.id
},
selectParameter: 'login',
serializeData: function () {
return _.extend(Modal.prototype.serializeData.apply(this, arguments), {
+ permissionName: this.options.permission.name,
permissionTemplateName: this.options.permissionTemplate.name
});
}
--- /dev/null
+/* eslint no-unused-expressions: 0 */
+import React from 'react/addons';
+import Defaults from '../../src/main/js/apps/permission-templates/permission-template-defaults';
+import SetDefaults from '../../src/main/js/apps/permission-templates/permission-template-set-defaults';
+
+let TestUtils = React.addons.TestUtils;
+let chai = require('chai');
+let expect = chai.expect;
+
+describe('Permission Templates', function () {
+ describe('Defaults', () => {
+ it('should display one qualifier', () => {
+ let permissionTemplate = { defaultFor: ['VW'] },
+ topQualifiers = ['TRK', 'VW'];
+ let result = TestUtils.renderIntoDocument(
+ <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-vw')).to.have.length(1);
+ });
+
+ it('should display two qualifiers', () => {
+ let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
+ topQualifiers = ['TRK', 'VW'];
+ let result = TestUtils.renderIntoDocument(
+ <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.have.length(1);
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-vw')).to.have.length(1);
+ });
+
+ it('should omit "project" if there is only one qualifier', () => {
+ let permissionTemplate = { defaultFor: ['TRK'] },
+ topQualifiers = ['TRK'];
+ let result = TestUtils.renderIntoDocument(
+ <Defaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'icon-qualifier-trk')).to.be.empty;
+ });
+ });
+
+ describe('SetDefaults', () => {
+ var refresh = function () {};
+
+ it('should display a dropdown with one option', () => {
+ let permissionTemplate = { defaultFor: ['VW'] },
+ topQualifiers = ['TRK', 'VW'];
+ let result = TestUtils.renderIntoDocument(
+ <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
+ expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
+ });
+
+ it('should display a dropdown with two options', () => {
+ let permissionTemplate = { defaultFor: [] },
+ topQualifiers = ['TRK', 'VW'];
+ let result = TestUtils.renderIntoDocument(
+ <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.have.length(1);
+ expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(2);
+ });
+
+ it('should not display a dropdown', () => {
+ let permissionTemplate = { defaultFor: ['TRK', 'VW'] },
+ topQualifiers = ['TRK', 'VW'];
+ let result = TestUtils.renderIntoDocument(
+ <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.be.empty;
+ expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.be.empty;
+ });
+
+ it('should omit dropdown if there is only one qualifier', () => {
+ let permissionTemplate = { defaultFor: [] },
+ topQualifiers = ['TRK'];
+ let result = TestUtils.renderIntoDocument(
+ <SetDefaults permissionTemplate={permissionTemplate} topQualifiers={topQualifiers} refresh={refresh}/>
+ );
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'dropdown')).to.be.empty;
+ expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'a')).to.have.length(1);
+ });
+ });
+});
+/* globals global: false */
+
var jsdom = require('jsdom');
// A super simple DOM ready for React to render into
global.navigator = document.defaultView.navigator;
global.window.baseUrl = '';
+global.window.t = global.window.tp = function () {
+ var args = Array.prototype.slice.call(arguments, 0);
+ return args.join('.');
+};