Skip to content

Commit

Permalink
#110 Add responder config tab
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 10, 2018
1 parent f574744 commit cedddb4
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
import _ from 'lodash/core';

import ConfigurationEditController from './config.edit.controller';
import configurationEditTpl from './config.edit.modal.html';
import ConfigurationEditController from '../config.edit.controller';
import configurationEditTpl from '../config.edit.modal.html';

export default class OrganizationConfigsController {
constructor($log, $uibModal, AnalyzerService, NotificationService) {
Expand Down Expand Up @@ -39,9 +39,9 @@ export default class OrganizationConfigsController {

_.forEach(conf.configurationItems, item => {
conf.config[item.name] =
conf.config[item.name] !== undefined
? conf.config[item.name]
: item.defaultValue || (item.multi ? [undefined] : undefined);
conf.config[item.name] !== undefined ?
conf.config[item.name] :
item.defaultValue || (item.multi ? [undefined] : undefined);
});

return conf;
Expand Down Expand Up @@ -70,4 +70,4 @@ export default class OrganizationConfigsController {
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';
import _ from 'lodash/core';

import ConfigurationEditController from '../config.edit.controller';
import configurationEditTpl from '../config.edit.modal.html';

export default class OrganizationConfigsController {
constructor($log, $uibModal, ResponderService, NotificationService) {
'ngInject';

this.$log = $log;
this.$uibModal = $uibModal;
this.ResponderService = ResponderService;
this.NotificationService = NotificationService;

this.state = {
filter: ''
};
}

isSet(config) {
return _.indexOf([undefined, null, ''], config) === -1;
}

edit(config) {
let modal = this.$uibModal.open({
controller: ConfigurationEditController,
templateUrl: configurationEditTpl,
controllerAs: '$modal',
size: 'lg',
resolve: {
configuration: () => {
// let defaultValues = {
// string: null,
// number: 0,
// boolean: true
// };
let conf = angular.copy(config);

_.forEach(conf.configurationItems, item => {
conf.config[item.name] =
conf.config[item.name] !== undefined ?
conf.config[item.name] :
item.defaultValue || (item.multi ? [undefined] : undefined);
});

return conf;
}
}
});

modal.result
.then(configuration =>
this.ResponderService.saveConfiguration(config.name, {
config: configuration
})
)
.then(() => this.ResponderService.configurations())
.then(configs => (this.configurations = configs))
.then(() =>
this.NotificationService.success(
`Configuration ${config.name} updated successfully`
)
)
.catch(err => {
if (!_.isString(err)) {
this.NotificationService.error(
`Failed to update configuration ${config.name}`
);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!-- <pre>{{$ctrl.configurations | json}}</pre> -->

<section>
<p class="lead">Available responder configurations ({{$ctrl.configurations.length || 0}})</p>

<div class="row mv-s" ng-if="$ctrl.configurations.length === 0">
<div class="col-md-12">
<div class="empty-message">No configurations found.</div>
</div>
</div>

<div class="row mv-s" ng-if="$ctrl.configurations.length > 0">
<div class="col-sm-12 mb-s">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-search"></i>
</span>
<input type="text" class="form-control input-lg" ng-model="$ctrl.state.filter" placeholder="Filter configurations">
</div>
</div>
<div class="col-sm-12 flex-table config-list">
<div class="flex-header media">
<div class="flex-col flex-w-100 text-center">Options</div>
<div class="flex-col flex-3">Configuration</div>
<div class="flex-col flex-1">Responders</div>
<div class="flex-col flex-w-100"></div>
</div>
<div class="flex-row media" ng-repeat="config in $ctrl.configurations | filter:$ctrl.state.filter:name" ng-class="{'global-config': config.name === 'global'}">
<div class="flex-col flex-w-100 text-center vertical">
<div>
<h4 class="media-heading">{{config.configurationItems.length}}</h4>
<ng-pluralize count="config.configurationItems.length" when="{'0': 'Options', '1': 'Option', 'other': 'Options'}"></ng-pluralize>
</div>
</div>
<div class="flex-col flex-3">
<h4 class="media-heading">
<span class="mr-m text-primary">{{config.name === 'global' ? 'Global Configuration' : config.name}}</span>
</h4>
<h4 class="media-heading">
<div ng-repeat="item in config.configurationItems">
<small class="mr-xxs">
<strong><i class="mr-xxs fa" ng-class="{
'fa-check text-success': $ctrl.isSet(config.config[item.name]),
'fa-times text-danger': !$ctrl.isSet(config.config[item.name])
}"></i> {{item.name}}:</strong> {{item.description}}
<span ng-if="item.defaultValue">(<em>Default:</em> {{item.defaultValue}})</span>
</small>
</div>
</h4>
</div>
<div class="flex-col flex-1">
<h4 class="media-heading">
<span class="mr-m text-primary"><ng-pluralize count="config.responders.length" when="{'0': '0 Responders', '1': '1 Responder', 'other': '{} Responders'}"></ng-pluralize></span>
</h4>
<h4 class="media-heading">
<div ng-repeat="item in config.responders">
<small>{{item}}</small>
</div>
</h4>
</div>
<div class="flex-col flex-icon flex-w-100 text-center" ng-click="$ctrl.edit(config)">
<a href class="text-primary">
<i class="fa fa-edit"></i>Edit</a>
</div>
</div>
</div>
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>Organization:
<uib-tab index="1" require-roles="orgadmin">
<uib-tab-heading>
<i class="fa fa-cog"></i> Analyzers Config</uib-tab-heading>
<organization-config-list organization="$ctrl.organization" configurations="$ctrl.configurations"></organization-config-list>
<organization-config-list organization="$ctrl.organization" configurations="$ctrl.analyzersConfigurations"></organization-config-list>
</uib-tab>
<uib-tab index="2" require-roles="orgadmin">
<uib-tab-heading>
Expand All @@ -26,7 +26,7 @@ <h1>Organization:
<uib-tab index="3" require-roles="orgadmin">
<uib-tab-heading>
<i class="fa fa-cog"></i> Responders Config</uib-tab-heading>
<organization-config-list organization="$ctrl.organization" configurations="$ctrl.configurations"></organization-config-list>
<organization-responder-config-list organization="$ctrl.organization" configurations="$ctrl.respondersConfigurations"></organization-responder-config-list>
</uib-tab>
<uib-tab index="4" require-roles="orgadmin">
<uib-tab-heading>
Expand Down
38 changes: 28 additions & 10 deletions www/src/app/pages/admin/organizations/organizations.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import OrganizationUsersController from './components/users-list.controller';
import organizationUsersTpl from './components/users-list.html';

// Analyzers
import AnalyzerConfigFormController from './components/analyzer-config-form.controller';
import analyzerConfigFormTpl from './components/analyzer-config-form.html';
import AnalyzerConfigFormController from './components/analyzers/analyzer-config-form.controller';
import analyzerConfigFormTpl from './components/analyzers/analyzer-config-form.html';

import OrganizationAnalyzersController from './components/analyzers-list.controller';
import organizationAnalyzersTpl from './components/analyzers-list.html';
import OrganizationAnalyzersController from './components/analyzers/analyzers-list.controller';
import organizationAnalyzersTpl from './components/analyzers/analyzers-list.html';

import OrganizationConfigsController from './components/config-list.controller';
import organizationConfigsTpl from './components/config-list.html';
import OrganizationConfigsController from './components/analyzers/config-list.controller';
import organizationConfigsTpl from './components/analyzers/config-list.html';

import ConfigurationForm from './components/config-form.controller';
import configurationFormTpl from './components/config-form.html';
Expand All @@ -32,8 +32,10 @@ import responderConfigFormTpl from './components/responders/responder-config-for
import OrganizationRespondersController from './components/responders/responders-list.controller';
import organizationRespondersTpl from './components/responders/responders-list.html';

import OrganizationReponderConfigsController from './components/responders/config-list.controller';
import organizationResponderConfigsTpl from './components/responders/config-list.html';

import organizationService from './organizations.service.js';
import organizationService from './organizations.service';

import './organizations.scss';

Expand Down Expand Up @@ -71,13 +73,20 @@ const organizationsModule = angular
return $q.resolve([]);
}
},
configurations: (AuthService, AnalyzerService, $q) => {
analyzersConfigurations: (AuthService, AnalyzerService, $q) => {
if (AuthService.hasRole([Roles.ORGADMIN])) {
return AnalyzerService.configurations();
} else {
return $q.resolve([]);
}
},
respondersConfigurations: (AuthService, ResponderService, $q) => {
if (AuthService.hasRole([Roles.ORGADMIN])) {
return ResponderService.configurations();
} else {
return $q.resolve([]);
}
},
responderDefinitions: (AuthService, ResponderService, $q) => {
if (AuthService.hasRole([Roles.ORGADMIN])) {
return ResponderService.definitions();
Expand Down Expand Up @@ -110,9 +119,10 @@ const organizationsModule = angular
users: '<',
analyzerDefinitions: '<',
analyzers: '<',
configurations: '<',
analyzersConfigurations: '<',
responderDefinitions: '<',
responders: '<'
responders: '<',
respondersConfigurations: '<'
}
})
.component('organizationAnalyzersList', {
Expand Down Expand Up @@ -148,6 +158,14 @@ const organizationsModule = angular
configurations: '<'
}
})
.component('organizationResponderConfigList', {
controller: OrganizationReponderConfigsController,
templateUrl: organizationResponderConfigsTpl,
bindings: {
organization: '<',
configurations: '<'
}
})
.component('configurationForm', {
controller: ConfigurationForm,
templateUrl: configurationFormTpl,
Expand Down
Loading

0 comments on commit cedddb4

Please sign in to comment.