Skip to content

Commit

Permalink
#52 Add a confirmation dialog before misp export operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Sep 8, 2017
1 parent 7c44374 commit 78b4fc5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 13 deletions.
103 changes: 93 additions & 10 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,100 @@
});
};


var extractExportErrors = function (errors) {
var result = [];

console.log(errors);
result = errors.map(function(item) {
return {
data: item.object.dataType === 'file' ? item.object.attachment.name : item.object.data,
message: item.message
};
});

return result;
}

var showExportErrors = function(errors) {
$uibModal.open({
templateUrl: 'views/partials/misp/error.dialog.html',
controller: function(clipboard, $uibModalInstance, failures) {
this.failures = failures;
this.cancel = function() {
$uibModalInstance.dismiss();
}

this.copyToClipboard = function() {
clipboard.copyText(_.pluck(failures, 'data').join('\n'));
$uibModalInstance.dismiss();
}
},
controllerAs: 'dialog',
size: 'lg',
resolve: {
failures: function() {
return errors;
}
}
})
}

$scope.shareCase = function() {
var mispConfig = $scope.appConfig.connectors.misp;
MispSrv.getServer(mispConfig)
.then(function(server) {
return MispSrv.export($scope.caseId, server);
})
.then(function(response){
console.log(response);
}, function(err) {
console.log(err);
});
var modalInstance = $uibModal.open({
templateUrl: 'views/partials/misp/case.export.confirm.html',
controller: function($uibModalInstance, data) {
this.caze = data;
this.cancel = function() {
$uibModalInstance.dismiss();
}

this.confirm = function() {
$uibModalInstance.close();
}
},
controllerAs: 'dialog',
resolve: {
data: function() {
return $scope.caze;
}
}
});

modalInstance.result.then(function() {
var mispConfig = $scope.appConfig.connectors.misp;
return MispSrv.getServer(mispConfig)
}).then(function(server) {
return MispSrv.export($scope.caseId, server);
})
.then(function(response){
var success = 0,
failure = 0;

if (response.status === 207) {
success = response.data.success.length;
failure = response.data.failure.length;

showExportErrors(extractExportErrors(response.data.failure));

NotificationSrv.log('The case has been successfully exported, but '+ failure +' observable(s) failed', 'warning');
} else {
success = angular.isObject(response.data) ? 1 : response.data.length;
NotificationSrv.log('The case has been successfully exported with ' + success+ ' observable(s)', 'success');
}

}, function(err) {
if(!err) {
return;
}

if (err.status === 400) {
showExportErrors(extractExportErrors(err.data));
} else {
NotificationSrv.error('CaseExportCtrl', 'An unexpected error occurred while exporting case', response.status);
}
});

};

/**
Expand Down
12 changes: 12 additions & 0 deletions ui/app/views/partials/misp/case.export.confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="modal-header bg-primary">
<h3 class="modal-title">MISP Export</h3>
</div>
<div class="modal-body">
<p>
Are you sure you want to export the case <strong>{{dialog.caze.title}}</strong>.
</p>
</div>
<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="dialog.cancel()" type="button">Cancel</button>
<button class="btn btn-primary pull-right" ng-click="dialog.confirm()">Confirm</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 class="modal-title">Export case to MISP</h3>
<th>Reason</th>
</thead>
<tbody>
<tr ng-repeat="o in failures">
<tr ng-repeat="o in dialog.failures">
<td class="wrap">{{o.data | fang}}</td>
<td class="nowrap">{{o.message}}</td>
</tr>
Expand All @@ -23,6 +23,6 @@ <h3 class="modal-title">Export case to MISP</h3>
</div>

<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="cancel()" type="button">Cancel</button>
<button class="btn btn-primary pull-right" ng-click="copyToClipboard()" type="button"><i class="fa fa-copy"></i> Copy to clipboard</button>
<button class="btn btn-default" ng-click="dialog.cancel()" type="button">Cancel</button>
<button class="btn btn-primary pull-right" ng-click="dialog.copyToClipboard()" type="button"><i class="fa fa-copy"></i> Copy to clipboard</button>
</div>

0 comments on commit 78b4fc5

Please sign in to comment.