Skip to content

Commit

Permalink
#1985 Update case merge dialog to take into account the merge into re…
Browse files Browse the repository at this point in the history
…solved cases config
  • Loading branch information
nadouani committed May 31, 2021
1 parent 37998df commit 5b025a8
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 65 deletions.
112 changes: 63 additions & 49 deletions frontend/app/scripts/controllers/alert/AlertEventCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
(function () {
'use strict';
angular.module('theHiveControllers')
.controller('AlertEventCtrl', function($scope, $rootScope, $state, $uibModal, $uibModalInstance, ModalUtilsSrv, AuthenticationSrv, CustomFieldsSrv, CaseResolutionStatus, AlertingSrv, NotificationSrv, UiSettingsSrv, clipboard, event, templates, readonly) {
.controller('AlertEventCtrl', function ($scope, $rootScope, $state, $uibModal, $uibModalInstance, ModalUtilsSrv, AuthenticationSrv, CustomFieldsSrv, CaseResolutionStatus, AlertingSrv, NotificationSrv, UiSettingsSrv, clipboard, event, templates, readonly) {
var self = this;
var eventId = event._id;

Expand All @@ -23,26 +23,26 @@

self.hideEmptyCaseButton = UiSettingsSrv.hideEmptyCaseButton();

self.updateObservableCount = function(count) {
self.updateObservableCount = function (count) {
self.counts.observables = count;
};

self.updateSimilarCasesCount = function(count) {
self.updateSimilarCasesCount = function (count) {
self.counts.similarCases = count;
};

self.getCustomFieldName = function(fieldDef) {
self.getCustomFieldName = function (fieldDef) {
return 'customFields.' + fieldDef.reference + '.' + fieldDef.type;
};

self.load = function() {
AlertingSrv.get(eventId).then(function(data) {
self.load = function () {
AlertingSrv.get(eventId).then(function (data) {
self.event = data;
self.loading = false;
}, function(response) {
self.loading = false;
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
$uibModalInstance.dismiss();
}, function (response) {
self.loading = false;
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
$uibModalInstance.dismiss();
});
};

Expand All @@ -51,78 +51,92 @@
field[fieldName] = newValue;

return AlertingSrv.update(self.event._id, field)
.then(function() {
NotificationSrv.log('Alert updated successfully', 'success');
})
.catch(function (response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
.then(function () {
NotificationSrv.log('Alert updated successfully', 'success');
})
.catch(function (response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
};

self.import = function() {
self.import = function () {
self.loading = true;
AlertingSrv.create(self.event._id, {
caseTemplate: self.event.caseTemplate
}).then(function(response) {
}).then(function (response) {
$uibModalInstance.dismiss();

$rootScope.$broadcast('alert:event-imported');

$state.go('app.case.details', {
caseId: response.data.id
});
}, function(response) {
}, function (response) {
self.loading = false;
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
};

self.mergeIntoCase = function(caseId) {
self.mergeIntoCase = function (caseId) {
self.loading = true;
AlertingSrv.mergeInto(self.event._id, caseId)
.then(function(response) {
.then(function (response) {
$uibModalInstance.dismiss();

$rootScope.$broadcast('alert:event-imported');

$state.go('app.case.details', {
caseId: response.data.id
});
}, function(response) {
}, function (response) {
self.loading = false;
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
};

self.merge = function() {
self.merge = function () {
var caseModal = $uibModal.open({
templateUrl: 'views/partials/case/case.merge.html',
controller: 'CaseMergeModalCtrl',
controllerAs: 'dialog',
size: 'lg',
resolve: {
source: function() {
source: function () {
return self.event;
},
title: function() {
title: function () {
return 'Merge Alert: ' + self.event.title;
},
prompt: function() {
prompt: function () {
return self.event.title;
},
filter: function () {
var skipResolvedCases = UiSettingsSrv.disallowMergeAlertInResolvedSimilarCases() === true;

if (skipResolvedCases) {
return {
_ne: {
_field: 'status',
_value: 'Resolved'
}
}
}

return null;
}
}
});

caseModal.result.then(function(selectedCase) {
caseModal.result.then(function (selectedCase) {
self.mergeIntoCase(selectedCase._id);
}).catch(function(err) {
if(err && !_.isString(err)) {
}).catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('AlertEventCtrl', err.data, err.status);
}
});
};

this.follow = function() {
this.follow = function () {
var fn = angular.noop;

if (self.event.follow === true) {
Expand All @@ -131,59 +145,59 @@
fn = AlertingSrv.follow;
}

fn(self.event._id).then(function() {
fn(self.event._id).then(function () {
$uibModalInstance.close();
}).catch(function(response) {
}).catch(function (response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
};

this.delete = function() {
this.delete = function () {
ModalUtilsSrv.confirm('Remove Alert', 'Are you sure you want to delete this Alert?', {
okText: 'Yes, remove it',
flavor: 'danger'
}).then(function() {
}).then(function () {
AlertingSrv.forceRemove(self.event._id)
.then(function() {
$uibModalInstance.close();
NotificationSrv.log('Alert has been permanently deleted', 'success');
})
.catch(function(response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
.then(function () {
$uibModalInstance.close();
NotificationSrv.log('Alert has been permanently deleted', 'success');
})
.catch(function (response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
});

};

this.canMarkAsRead = AlertingSrv.canMarkAsRead;
this.canMarkAsUnread = AlertingSrv.canMarkAsUnread;

this.markAsRead = function() {
this.markAsRead = function () {
var fn = angular.noop;

if(this.canMarkAsRead(this.event)) {
if (this.canMarkAsRead(this.event)) {
fn = AlertingSrv.markAsRead;
} else {
fn = AlertingSrv.markAsUnread;
}

fn(this.event._id).then(function( /*data*/ ) {
fn(this.event._id).then(function ( /*data*/) {
$uibModalInstance.close();
}, function(response) {
}, function (response) {
NotificationSrv.error('AlertEventCtrl', response.data, response.status);
});
};

self.cancel = function() {
self.cancel = function () {
$uibModalInstance.dismiss();
};

self.copyId = function(id) {
self.copyId = function (id) {
clipboard.copyText(id);
NotificationSrv.log('Alert ID has been copied to clipboard', 'success');
};

this.$onInit = function() {
this.$onInit = function () {
self.load();
};
});
Expand Down
16 changes: 15 additions & 1 deletion frontend/app/scripts/controllers/alert/AlertListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(function () {
'use strict';
angular.module('theHiveControllers')
.controller('AlertListCtrl', function ($rootScope, $scope, $q, $state, $uibModal, TagSrv, StreamQuerySrv, CaseTemplateSrv, UtilsSrv, ModalUtilsSrv, AlertingSrv, NotificationSrv, FilteringSrv, CortexSrv, Severity, VersionSrv) {
.controller('AlertListCtrl', function ($rootScope, $scope, $q, $state, $uibModal, TagSrv, UiSettingsSrv, StreamQuerySrv, CaseTemplateSrv, UtilsSrv, ModalUtilsSrv, AlertingSrv, NotificationSrv, FilteringSrv, CortexSrv, Severity, VersionSrv) {
var self = this;

self.urls = VersionSrv.mispUrls();
Expand Down Expand Up @@ -382,6 +382,20 @@
},
prompt: function () {
return 'the ' + self.selection.length + ' selected Alert(s)';
},
filter: function () {
var skipResolvedCases = UiSettingsSrv.disallowMergeAlertInResolvedSimilarCases() === true;

if (skipResolvedCases) {
return {
_ne: {
_field: 'status',
_value: 'Resolved'
}
}
}

return null;
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions frontend/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@
},
prompt: function () {
return '#' + $scope.caze.number + ': ' + $scope.caze.title;
},
filter: function () {
return {
_ne: {
_field: 'number',
_value: $scope.caze.number
}
}
}
}
});
Expand Down
41 changes: 26 additions & 15 deletions frontend/app/scripts/controllers/case/CaseMergeModalCtrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function() {
(function () {
'use strict';

angular.module('theHiveControllers')
.controller('CaseMergeModalCtrl', CaseMergeModalCtrl);

function CaseMergeModalCtrl($state, $uibModalInstance, $q, QuerySrv, SearchSrv, CaseSrv, UserSrv, NotificationSrv, source, title, prompt) {
function CaseMergeModalCtrl($uibModalInstance, $q, QuerySrv, UserSrv, NotificationSrv, source, title, prompt, filter) {
var me = this;

this.source = source;
Expand All @@ -20,44 +20,55 @@
};
this.getUserInfo = UserSrv.getCache;

this.getCaseList = function(type, input) {
this.getCaseList = function (type, input) {
var defer = $q.defer();

var filter = (type === 'title') ? {
var selectionFilter = (type === 'title') ? {
_like: {
title: input
_field: 'title',
_value: input
}
} : {
_field: 'number',
_value: Number.parseInt(input)
};

var caseFilter;

if (filter) {
caseFilter = {
_and: [selectionFilter, filter]
}
} else {
caseFilter = selectionFilter
}

QuerySrv.call('v1',
[{_name: 'listCase'}],
[{ _name: 'listCase' }],
{
filter:filter,
filter: caseFilter,
name: 'get-case-for-merge'
}
).then(function(data) {
).then(function (data) {
defer.resolve(data);
});
}); // TODO add error handler

return defer.promise;
};

this.format = function(caze) {
this.format = function (caze) {
if (caze) {
return '#' + caze.number + ' - ' + caze.title;
}
return null;
};

this.clearSearch = function() {
this.clearSearch = function () {
this.search.input = null;
this.search.cases = [];
};

this.onTypeChange = function(type) {
this.onTypeChange = function (type) {
this.clearSearch();

this.search.placeholder = 'Search by case ' + type;
Expand All @@ -69,15 +80,15 @@
}
};

this.onSelect = function(item /*, model, label*/ ) {
this.onSelect = function (item /*, model, label*/) {
this.search.cases = [item];
};

this.merge = function() {
this.merge = function () {
$uibModalInstance.close(me.search.cases[0]);
};

this.cancel = function() {
this.cancel = function () {
$uibModalInstance.dismiss();
};
}
Expand Down

0 comments on commit 5b025a8

Please sign in to comment.