Skip to content

Commit

Permalink
#609 Add responders menu for task log items
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 30, 2018
1 parent 546a054 commit a2e3e74
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 20 deletions.
2 changes: 0 additions & 2 deletions ui/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
},
sort: ['-flag', '+order', '+startDate', '+title'],
onUpdate: function() {
console.log($scope.tasks.values);

$scope.buildTaskGroups($scope.tasks.values);
}
//pageSize: 30
Expand Down
45 changes: 36 additions & 9 deletions ui/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseTasksItemCtrl',
function ($scope, $rootScope, $state, $stateParams, $timeout, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, NotificationSrv, CortexSrv, task) {
function ($scope, $rootScope, $state, $stateParams, $timeout, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, NotificationSrv, CortexSrv, StatSrv, task) {
var caseId = $stateParams.caseId,
taskId = $stateParams.itemId;

Expand Down Expand Up @@ -37,22 +37,49 @@

$scope.logs = PSearchSrv(caseId, 'case_task_log', {
scope: $scope,
'filter': {
'_and': [{
'_parent': {
'_type': 'case_task',
'_query': {
'_id': taskId
filter: {
_and: [{
_parent: {
_type: 'case_task',
_query: {
_id: taskId
}
}
}, {
'_not': {
_not: {
'status': 'Deleted'
}
}]
},
'sort': $scope.state.sort,
'pageSize': 10
'pageSize': 10,
onUpdate: function() {
var ids = _.pluck($scope.logs.values, 'id');

StatSrv.getPromise({
objectType: 'connector/cortex/action',
field: 'objectId',
limit: 1000,
skipTotal: true,
query: {
_and: [{
_field: 'objectType',
_value: 'case_task_log'
},
{
_in: {
_field: 'objectId',
_values: ids
}
}]
}
}).then(function(response) {
var counts = response.data;
_.each($scope.logs.values, function(log) {
log.nbActions = counts[log.id] ? counts[log.id].count : 0;
});
});
}
});

$scope.actions = PSearchSrv(null, 'connector/cortex/action', {
Expand Down
56 changes: 55 additions & 1 deletion ui/app/scripts/directives/logEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@
.directive('logEntry', function($uibModal, TaskLogSrv, UserInfoSrv, NotificationSrv) {
return {
templateUrl: 'views/directives/log-entry.html',
controller: function($scope, CortexSrv, PSearchSrv) {
$scope.showActions = false;
$scope.actions = null;
$scope.logResponders = null;
$scope.getLogResponders = function(logId) {
$scope.logResponders = null;
CortexSrv.getResponders('case_task_log', logId)
.then(function(responders) {
$scope.logResponders = responders;
})
.catch(function(err) {
NotificationSrv.error('logEntry', response.data, response.status);
})
};

$scope.runResponder = function(responderId, log) {
CortexSrv.runResponder(responderId, 'case_task_log', _.pick(log, 'id'))
.then(function(response) {
NotificationSrv.log(['Responder', response.data.responderName, 'started successfully on task log'].join(' '), 'success');
})
.catch(function(response) {
NotificationSrv.error('logEntry', response.data, response.status);
});
};

$scope.getActions = function(logId) {
$scope.actions = PSearchSrv(null, 'connector/cortex/action', {
scope: $scope,
streamObjectType: 'action',
filter: {
_and: [
{
_not: {
status: 'Deleted'
}
}, {
objectType: 'case_task_log'
}, {
objectId: logId
}
]
},
sort: ['-startDate'],
pageSize: 100,
guard: function(updates) {
return _.find(updates, function(item) {
return (item.base.object.objectType === 'case_task_log') && (item.base.object.objectId === logId);
}) !== undefined;
}
});

};
},
link: function(scope) {

// drop log
Expand Down Expand Up @@ -48,7 +101,8 @@
},
restrict: 'EA',
scope: {
log: '='
log: '=',
appConfig: '='
}
};
});
Expand Down
1 change: 0 additions & 1 deletion ui/app/scripts/filters/flattern-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
}
}

console.log(result);
return result;
};

Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/CortexSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
};

return $http.post(baseUrl + '/action', post);
}
}
});

})();
8 changes: 5 additions & 3 deletions ui/app/scripts/services/StatSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
stats.push(agg);
}

stats.push({
_agg: 'count'
});
if(!config.skipTotal) {
stats.push({
_agg: 'count'
});
}

var entity = config.objectType.replace(/_/g, '/');
if(entity[0] === '/') {
Expand Down
1 change: 0 additions & 1 deletion ui/app/scripts/utils/saveSvgAsPng.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
}
}
img.onerror = function() {
console.log("Could not load "+href);
left--;
if (left == 0) {
callback();
Expand Down
30 changes: 29 additions & 1 deletion ui/app/views/directives/log-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@
<user user-id="log.owner" icon-size="xs"></user>
</div>
<div class="col-md-6">
<span class="pull-right ml-xs" uib-dropdown ng-if="appConfig.connectors.cortex.enabled">
<a href class="text-primary noline nowrap" ng-click="getLogResponders(log.id, true)" uib-dropdown-toggle>
<i class="text-primary fa fa-cog"></i>
</a>
<ul class="dropdown-menu align-right" uib-dropdown-menu>
<li ng-if="logResponders && logResponders.length === 0">
<a href ng-click="getLogResponders(task.id, true)">
<strong><i class="fa fa-refresh mr-xxs"></i> No responders available</strong>
</a>
</li>
<li ng-repeat="responder in logResponders">
<a href ng-click="runResponder(responder.id, log)">
<strong>{{responder.name}}</strong>
<br>
<small>{{responder.description}}</small></a>
</li>
</ul>
</span>
<span class="pull-right">
<a href ng-click="dropLog()" uib-tooltip="Delete log">
<i class="text-danger glyphicon glyphicon-remove-circle"></i>
<i class="text-danger fa fa-times-circle"></i>
</a>
</span>
<span class="text-muted mr-xs pull-right" ng-bind="log.startDate | showDate"></span>
Expand Down Expand Up @@ -47,4 +65,14 @@
<updatable-text on-update="updateLog()" value="log.message"></updatable-text>
</div>
</div>

<div class="row" ng-if="log.nbActions > 0">
<div class="col-md-12">
<a href ng-show="showActions" ng-click="showActions=false">Hide Responder Jobs ({{log.nbActions}})</a>
<a href ng-show="!showActions" ng-click="showActions=true; getActions(log.id)">Show Responder Jobs ({{log.nbActions}})</a>
</div>
<div class="col-md-12" ng-show="showActions && actions">
<responder-actions header="" actions="actions"></responder-actions>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion ui/app/views/partials/case/case.tasks.item.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h4 class="mb-xs text-primary">Task logs</h4>

<psearch control="logs"></psearch>
<div ng-repeat="log in logs.values">
<log-entry log="log"></log-entry>
<log-entry log="log" app-config="appConfig"></log-entry>
</div>
<psearch control="logs"></psearch>
</div>
Expand Down

0 comments on commit a2e3e74

Please sign in to comment.