Skip to content

Commit

Permalink
#160 Allow access to admin pages just for admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 27, 2017
1 parent f51208e commit d880c94
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
3 changes: 2 additions & 1 deletion ui/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"c3": false,
"saveSvgAsPng": false,
"Blob": false,
"File": false
"File": false,
"hljs": false
}
}
26 changes: 25 additions & 1 deletion ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
templateUrl: 'views/app.html',
controller: 'RootCtrl',
resolve: {
currentUser: function($q, AuthenticationSrv) {
var deferred = $q.defer();

AuthenticationSrv.current(function(userData) {
deferred.resolve(userData);
}, function(err) {
deferred.reject(err);
});

return deferred.promise;
},
appConfig: function(VersionSrv) {
return VersionSrv.get();
}
Expand Down Expand Up @@ -94,7 +105,20 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
.state('app.administration', {
abstract: true,
url: 'administration',
template: '<ui-view/>'
template: '<ui-view/>',
onEnter: function($state, AuthenticationSrv){
var currentUser = AuthenticationSrv.currentUser;

if(!currentUser || !currentUser.roles || _.map(currentUser.roles, function(role) {
return role.toLowerCase();
}).indexOf('admin') === -1) {
if(!$state.is('app.cases')) {
$state.go('app.cases');
} else {
return $state.reload();
}
}
}
})
.state('app.administration.users', {
url: '/users',
Expand Down
74 changes: 35 additions & 39 deletions ui/app/scripts/controllers/RootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Controller for main page
*/
angular.module('theHiveControllers').controller('RootCtrl',
function($scope, $uibModal, $location, $state, $base64, AuthenticationSrv, MispSrv, StreamSrv, StreamStatSrv, TemplateSrv, MetricsCacheSrv, AlertSrv) {
function($scope, $uibModal, $location, $state, $base64, AuthenticationSrv, MispSrv, StreamSrv, StreamStatSrv, TemplateSrv, MetricsCacheSrv, AlertSrv, currentUser) {
'use strict';

$scope.querystring = '';
Expand All @@ -12,48 +12,44 @@ angular.module('theHiveControllers').controller('RootCtrl',
$scope.mispEnabled = false;

StreamSrv.init();
$scope.currentUser = AuthenticationSrv.current(function() {
// while succeed get myCurrentTasks stats

$scope.templates = TemplateSrv.query();

$scope.myCurrentTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'_and': [{
'status': 'InProgress'
}, {
'owner': $scope.currentUser.id
}]
},
result: {},
objectType: 'case_task',
field: 'status'
});

$scope.waitingTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'status': 'Waiting'
},
result: {},
objectType: 'case_task',
field: 'status'
});
$scope.currentUser = currentUser;

$scope.templates = TemplateSrv.query();

$scope.myCurrentTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'_and': [{
'status': 'InProgress'
}, {
'owner': $scope.currentUser.id
}]
},
result: {},
objectType: 'case_task',
field: 'status'
});

// Get metrics cache
MetricsCacheSrv.all().then(function(list) {
$scope.metricsCache = list;
});
$scope.waitingTasks = StreamStatSrv({
scope: $scope,
rootId: 'any',
query: {
'status': 'Waiting'
},
result: {},
objectType: 'case_task',
field: 'status'
});

// Get MISP counts
$scope.mispEvents = MispSrv.stats($scope);
}, function(data, status) {
AlertSrv.error('RootCtrl', data, status);
// Get metrics cache
MetricsCacheSrv.all().then(function(list) {
$scope.metricsCache = list;
});

// Get MISP counts
$scope.mispEvents = MispSrv.stats($scope);

$scope.$on('templates:refresh', function(){
$scope.templates = TemplateSrv.query();
});
Expand Down

0 comments on commit d880c94

Please sign in to comment.