Skip to content

Commit

Permalink
#241 Prevent users from filtering alerts and cases by unavailable values
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Sep 12, 2017
1 parent 8a00005 commit c3fe689
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 28 deletions.
13 changes: 11 additions & 2 deletions ui/app/scripts/controllers/alert/AlertListCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('AlertListCtrl', function($scope, $q, $state, $uibModal, TemplateSrv, AlertingSrv, NotificationSrv, FilteringSrv, Severity) {
.controller('AlertListCtrl', function($scope, $q, $state, $uibModal, TagSrv, TemplateSrv, AlertingSrv, NotificationSrv, FilteringSrv, Severity) {
var self = this;

self.list = [];
Expand Down Expand Up @@ -93,6 +93,7 @@
self.searchForm = {
searchQuery: self.filtering.buildQuery() || ''
};
self.lastSearch = null;

$scope.$watch('$vm.list.pageSize', function (newValue) {
self.filtering.setPageSize(newValue);
Expand Down Expand Up @@ -275,7 +276,11 @@

this.applyFilters = function () {
self.searchForm.searchQuery = self.filtering.buildQuery();
self.search();

if(self.lastSearch !== self.searchForm.searchQuery) {
self.lastSearch = self.searchForm.searchQuery;
self.search();
}
};

this.clearFilters = function () {
Expand Down Expand Up @@ -372,6 +377,10 @@
return AlertingSrv.sources(query);
};

this.getTags = function(query) {
return TagSrv.fromAlerts(query);
};

self.load();
});
})();
9 changes: 7 additions & 2 deletions ui/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
this.searchForm = {
searchQuery: this.uiSrv.buildQuery() || ''
};
this.lastQuery = null;

this.list = PSearchSrv(undefined, 'case', {
scope: $scope,
Expand All @@ -36,7 +37,6 @@
field: 'status'
});


$scope.$watch('$vm.list.pageSize', function (newValue) {
self.uiSrv.setPageSize(newValue);
});
Expand All @@ -55,7 +55,12 @@

this.applyFilters = function () {
self.searchForm.searchQuery = self.uiSrv.buildQuery();
self.search();

if(self.lastQuery !== self.searchForm.searchQuery) {
self.lastQuery = self.searchForm.searchQuery;
self.search();
}

};

this.clearFilters = function () {
Expand Down
41 changes: 27 additions & 14 deletions ui/app/scripts/services/TagSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,40 @@
angular.module('theHiveServices')
.service('TagSrv', function(StatSrv, $q) {

this.fromCases = function(query) {
var defer = $q.defer();

StatSrv.getPromise({
objectType: 'case',
var getPromiseFor = function(objectType) {
return StatSrv.getPromise({
objectType: objectType,
field: 'tags',
limit: 1000
}).then(function(response) {
var tags = [];
});
};

var mapTags = function(collection, term) {
return _.map(_.filter(_.keys(collection), function(tag) {
var regex = new RegExp(term, 'gi');
return regex.test(tag);
}), function(tag) {
return {text: tag};
});
};

tags = _.map(_.filter(_.keys(response.data), function(tag) {
var regex = new RegExp(query, 'gi');
return regex.test(tag);
}), function(tag) {
return {text: tag};
});
var getTags = function(objectType, term) {
var defer = $q.defer();

defer.resolve(tags);
getPromiseFor(objectType).then(function(response) {
defer.resolve(mapTags(response.data, term) || []);
});

return defer.promise;
}


this.fromCases = function(term) {
return getTags('case', term);
};

this.fromAlerts = function(term) {
return getTags('alert', term);
};

});
Expand Down
15 changes: 9 additions & 6 deletions ui/app/views/partials/alert/list/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ <h4>Filters</h4>
min-length="2"
ng-model="$vm.filtering.activeFilters.status.value"
placeholder="ex: New, Updated, Ignored, Imported"
replace-spaces-with-dashes="false">
<auto-complete load-on-focus="true" min-length="1" source="$vm.getStatuses($query)"></auto-complete>
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true">
<auto-complete load-on-focus="true" load-on-down-arrow="true" min-length="1" source="$vm.getStatuses($query)"></auto-complete>
</tags-input>
</div>
</div>
Expand All @@ -55,8 +56,9 @@ <h4>Filters</h4>
min-length="2"
ng-model="$vm.filtering.activeFilters.source.value"
placeholder="ex: CIRCL, OSINT"
replace-spaces-with-dashes="false">
<auto-complete debounceDelay="400" source="$vm.getSources($query)"></auto-complete>
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true">
<auto-complete debounceDelay="400" load-on-down-arrow="true" source="$vm.getSources($query)"></auto-complete>
</tags-input>
</div>
</div>
Expand All @@ -69,8 +71,9 @@ <h4>Filters</h4>
min-length="2"
ng-model="$vm.filtering.activeFilters.severity.value"
placeholder="ex: High, Medium, Low"
replace-spaces-with-dashes="false">
<auto-complete load-on-focus="true" min-length="1" source="$vm.getSeverities($query)"></auto-complete>
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true">
<auto-complete load-on-focus="true" load-on-down-arrow="true" min-length="1" source="$vm.getSeverities($query)"></auto-complete>
</tags-input>
</div>
</div>
Expand Down
11 changes: 7 additions & 4 deletions ui/app/views/partials/case/list/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ <h4>Filters</h4>
min-length="2"
ng-model="$vm.uiSrv.activeFilters.status.value"
placeholder="ex: Open, Resolved"
replace-spaces-with-dashes="false">
<auto-complete load-on-focus="true" min-length="1" source="$vm.getStatuses($query)"></auto-complete>
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true">
<auto-complete load-on-focus="true" load-on-down-arrow="true" min-length="1" source="$vm.getStatuses($query)"></auto-complete>
</tags-input>
</div>
</div>
Expand All @@ -56,6 +57,7 @@ <h4>Filters</h4>
ng-model="$vm.uiSrv.activeFilters.owner.value"
placeholder="ex: Firstname Lastname"
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true"
display-property="label">
<auto-complete debounceDelay="400" source="$vm.getUsers($query)" display-property="label"></auto-complete>
</tags-input>
Expand All @@ -70,8 +72,9 @@ <h4>Filters</h4>
min-length="2"
ng-model="$vm.uiSrv.activeFilters.severity.value"
placeholder="ex: High, Medium, Low"
replace-spaces-with-dashes="false">
<auto-complete load-on-focus="true" min-length="1" source="$vm.getSeverities($query)"></auto-complete>
replace-spaces-with-dashes="false"
add-from-autocomplete-only="true">
<auto-complete load-on-focus="true" load-on-down-arrow="true" min-length="1" source="$vm.getSeverities($query)"></auto-complete>
</tags-input>
</div>
</div>
Expand Down

0 comments on commit c3fe689

Please sign in to comment.