Skip to content

Commit

Permalink
#1821 Add case bulk flag/unflag and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 9, 2021
1 parent c17af93 commit ccc5d40
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 5 deletions.
87 changes: 82 additions & 5 deletions frontend/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('CaseListCtrl', CaseListCtrl);
.controller('CaseListCtrl', CaseListCtrl)
.controller('CaseBulkDeleteModalCtrl', CaseBulkDeleteModalCtrl);

function CaseListCtrl($scope, $q, $state, $window, $uibModal, StreamQuerySrv, FilteringSrv, SecuritySrv, StreamStatSrv, PaginatedQuerySrv, EntitySrv, CaseSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus, NotificationSrv, Severity, Tlp, CortexSrv) {
var self = this;
Expand Down Expand Up @@ -124,10 +125,23 @@
} else {
self.selection = [];
self.menu.selectAll = false;
// self.updateMenu();
self.updateMenu();
}
};

self.updateMenu = function() {
// Handle flag/unflag menu items
var temp = _.uniq(_.pluck(self.selection, 'flag'));
self.menu.unflag = temp.length === 1 && temp[0] === true;
self.menu.flag = temp.length === 1 && temp[0] === false;

// Handle close menu item
temp = _.uniq(_.pluck(self.selection, 'status'));
self.menu.close = temp.length === 1 && temp[0] === 'Open';

self.menu.delete = self.selection.length > 0;
};

self.select = function(caze) {
if (caze.selected) {
self.selection.push(caze);
Expand All @@ -136,7 +150,7 @@
return item._id === caze._id;
});
}
// self.updateMenu();
self.updateMenu();
};

self.selectAll = function() {
Expand All @@ -156,8 +170,7 @@
self.selection = [];
}

//self.updateMenu();

self.updateMenu();
};

this.toggleStats = function () {
Expand Down Expand Up @@ -268,6 +281,19 @@
self.filtering.setSort(sort);
};

this.bulkFlag = function(flag) {
var ids = _.pluck(self.selection, '_id');

return CaseSrv.bulkUpdate(ids, {flag: flag})
.then(function(/*responses*/) {
NotificationSrv.log('Selected cases have been updated successfully', 'success');
})
.catch(function(err) {
NotificationSrv.error('Bulk flag cases', err.data, err.status);
});

}

this.bulkEdit = function() {
var modal = $uibModal.open({
animation: 'true',
Expand All @@ -291,6 +317,21 @@
});
};

this.bulkRemove = function() {
var modal = $uibModal.open({
animation: 'true',
templateUrl: 'views/partials/case/case.bulk.delete.confirm.html',
controller: 'CaseBulkDeleteModalCtrl',
controllerAs: '$dialog',
size: 'lg',
resolve: {
selection: function() {
return self.selection;
}
}
});
}

this.getCaseResponders = function(caze, force) {
if (!force && this.caseResponders !== null) {
return;
Expand Down Expand Up @@ -319,4 +360,40 @@
});
};
}

function CaseBulkDeleteModalCtrl($uibModalInstance, $q, CaseSrv, NotificationSrv, selection) {
var self = this;

this.selection = selection;
this.count = selection.length;
this.typedCount = undefined;
this.loading = false;

this.ok = function() {
$uibModalInstance.close();
}
this.cancel = function() {
$uibModalInstance.dismiss();
}
this.confirm = function() {
self.loading = true;

var promises = _.map(self.selection, function(caze) {
return CaseSrv.forceRemove({ caseId: caze._id }).$promise;
});

$q.all(promises)
.then(function(responses) {
self.loading = false;
NotificationSrv.log('Cases have been deleted successfully: ' + responses.length, 'success');
$uibModalInstance.close();
})
.catch(function(errors) {
self.loading = false;
_.each(errors, function(err) {
NotificationSrv.error('Bulk delete cases', err.data, err.status);
});
})
}
}
})();
32 changes: 32 additions & 0 deletions frontend/app/views/partials/case/case.bulk.delete.confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<form name="removeForm" ng-submit="$dialog.confirm()">
<div class="modal-header bg-danger">
<h3 class="modal-title">Permanently remove selected cases</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to permanently delete the following <b>{{$dialog.selection.length}}</b> case(s)?</p>

<div class="mt-xs">
<table class="table table-striped">
<tr ng-repeat="item in $dialog.selection">
<td>#{{item.number}} - {{item.title}}</td>
</tr>
</table>
</div>

<div class="mt-xs">
<p><b>To confirm, please type the number of cases to delete.</b></p>

<input class="form-control input-lg" name="count" type="number" placeholder="{{$dialog.count}}"
ng-required ng-model="$dialog.typedCount">

<p><b class="text-danger">This action might take a while and cannot be undone.</b></p>
</div>
</div>
<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="$dialog.cancel()" ng-disabled="$dialog.loading" type="button">Cancel</button>
<button class="btn btn-danger pull-right" type="submit"
ng-disabled="$dialog.loading || removeForm.$invalid || ($dialog.count != $dialog.typedCount)">
Yes, confirm.
</button>
</div>
</form>
11 changes: 11 additions & 0 deletions frontend/app/views/partials/case/list/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
<li>
<a href ng-click="$vm.bulkEdit()"><i class="fa fa-edit"></i> Edit</a>
</li>
<li class="divider"></li>
<li ng-if="$vm.menu.flag">
<a href ng-click="$vm.bulkFlag(true)"><i class="fa fa-flag"></i> Add flag</a>
</li>
<li ng-if="$vm.menu.unflag">
<a href ng-click="$vm.bulkFlag(false)"><i class="fa fa-flag-o"></i> Remove flag</a>
</li>
<li ng-if="$vm.menu.delete" class="divider"></li>
<li>
<a href ng-click="$vm.bulkRemove()"><i class="fa fa-trash"></i> Delete</a>
</li>
</ul>
</div>

Expand Down

0 comments on commit ccc5d40

Please sign in to comment.