Skip to content

Commit

Permalink
#966 Update the UI code to fix the $http usage issues introduced by t…
Browse files Browse the repository at this point in the history
…he migration to Angular 1.7
  • Loading branch information
nadouani committed May 10, 2019
1 parent cb43880 commit b43e951
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 148 deletions.
4 changes: 0 additions & 4 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css"/>
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/angular-json-human/dist/angular-json-human.css" />
<link rel="stylesheet" href="bower_components/animate.css/animate.css" />
<link rel="stylesheet" href="bower_components/dropzone/dist/min/dropzone.min.css" />
<link rel="stylesheet" href="bower_components/ng-tags-input/ng-tags-input.css" />
Expand Down Expand Up @@ -68,8 +67,6 @@
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/lodash/dist/lodash.compat.js"></script>
<script src="bower_components/angular-json-human/dist/angular-json-human.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/angular-moment/angular-moment.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
Expand All @@ -95,7 +92,6 @@
<script src="bower_components/es6-shim/es6-shim.js"></script>
<script src="bower_components/angular-clipboard/angular-clipboard.js"></script>
<script src="bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
<script src="bower_components/myforce-angularjs-dropdown-multiselect/src/angularjs-dropdown-multiselect.js"></script>
<script src="bower_components/angular-highlightjs/build/angular-highlightjs.js"></script>
<script src="bower_components/marked/lib/marked.js"></script>
<script src="bower_components/angular-marked/dist/angular-marked.js"></script>
Expand Down
19 changes: 11 additions & 8 deletions ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ angular.module('thehive', [
currentUser: function($q, $state, AuthenticationSrv) {
var deferred = $q.defer();

AuthenticationSrv.current(function(userData) {
AuthenticationSrv.current()
.then(function(userData) {
return deferred.resolve(userData);
}, function(err, status) {
return deferred.resolve(status === 520 ? status : null);
});
})
.catch( function(err) {
return deferred.resolve(err.status === 520 ? err.status : null);
});

return deferred.promise;
},
Expand Down Expand Up @@ -149,16 +151,17 @@ angular.module('thehive', [
currentUser: function($q, $state, $timeout, AuthenticationSrv) {
var deferred = $q.defer();

AuthenticationSrv.current(function(userData) {
AuthenticationSrv.current()
.then(function(userData) {
return deferred.resolve(userData);
}, function( /*err, status*/ ) {

})
.catch( function(/*err*/) {
$timeout(function() {
$state.go('login');
});

return deferred.reject();
});
});

return deferred.promise;
},
Expand Down
48 changes: 26 additions & 22 deletions ui/app/scripts/controllers/AuthenticationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
$uibModalStack.dismissAll();

$scope.ssoLogin = function (code) {
AuthenticationSrv.ssoLogin(code, function(data, status, headers) {
var redirectLocation = headers().location;
if(angular.isDefined(redirectLocation)) {
window.location = redirectLocation;
} else {
$state.go('app.cases');
}
}, function(data, status) {
if (status === 520) {
NotificationSrv.error('AuthenticationCtrl', data, status);
} else {
NotificationSrv.log(data.message, 'error');
}
$location.url($location.path());
});
AuthenticationSrv.ssoLogin(code)
.then(function(response) {
var redirectLocation = response.headers().location;
if(angular.isDefined(redirectLocation)) {
window.location = redirectLocation;
} else {
$state.go('app.cases');
}
})
.catch(function(err) {
if (err.status === 520) {
NotificationSrv.error('AuthenticationCtrl', err.data, err.status);
} else {
NotificationSrv.log(err.data.message, 'error');
}
$location.url($location.path());
});
};

$scope.ssoEnabled = function() {
Expand All @@ -33,14 +35,16 @@


$scope.login = function() {
$scope.params.username = angular.lowercase($scope.params.username);
AuthenticationSrv.login($scope.params.username, $scope.params.password, function() {
$state.go('app.cases');
}, function(data, status) {
if (status === 520) {
NotificationSrv.error('AuthenticationCtrl', data, status);
$scope.params.username = $scope.params.username.toLowerCase();
AuthenticationSrv.login($scope.params.username, $scope.params.password)
.then(function() {
$state.go('app.cases');
})
.catch(function(err) {
if (err.status === 520) {
NotificationSrv.error('AuthenticationCtrl', err.data.message, err.status);
} else {
NotificationSrv.log(data.message, 'error');
NotificationSrv.log(err.data.message, 'error');
}
});
};
Expand Down
10 changes: 5 additions & 5 deletions ui/app/scripts/controllers/MigrationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
$scope.migrating = true;
$http.post('./api/maintenance/migrate', {}, {
timeout: 10 * 60 * 60 * 1000 // 10 minutes
}).success(function() {
}).then(function(/*response*/) {
console.log('Migration started');
}).error(function(response) {
if (angular.isObject(response)) {
NotificationSrv.error('UserMgmtCtrl', response.data, response.status);
}).catch(function(err) {
if (angular.isObject(err)) {
NotificationSrv.error('UserMgmtCtrl', err.data, err.status);
} else {
console.log("Migration timeout");
}
Expand All @@ -59,7 +59,7 @@
$scope.createInitialUser = function() {
console.log("createInitialUser");
UserSrv.save({
'login': angular.lowercase($scope.newUser.login),
'login': $scope.newUser.login.toLowerCase(),
'name': $scope.newUser.name,
'password': $scope.newUser.password,
'roles': ['read', 'write', 'admin']
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/admin/AdminUserDialogCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
UserSrv.update({'userId': self.user.id}, postData, onSuccess, onFailure);
} else {
postData = {
login: angular.lowercase(self.formData.id),
login: self.formData.id.toLowerCase(),
name: self.formData.name,
roles: buildRoles(self.formData.roles, self.formData.alert)
};
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/admin/AdminUsersCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
$scope.initNewUser();

$scope.addUser = function(user) {
user.login = angular.lowercase(user.login);
user.login = user.login.toLowerCase();
if ($scope.apiKey) {
user['with-key'] = true;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/directives/dashboard/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

var rawData = {};
_.each(response.data, function(value, key) {
rawData[key] = value[scope.options.dateField]
rawData[key] = value[scope.options.dateField];
});

_.each(rawData, function(value) {
Expand Down Expand Up @@ -137,7 +137,7 @@
scope.chart = chart;
}, function(err) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
NotificationSrv.error('dashboardBar', 'Failed to fetch data, please edit the widget definition', err.status);
});
};

Expand All @@ -160,7 +160,7 @@
}

return csv;
}
};

if (scope.autoload === true) {
scope.load();
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/directives/dashboard/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
};
});

}, function(/*err*/) {
}, function(err) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
NotificationSrv.error('dashboardBar', 'Failed to fetch data, please edit the widget definition', err.status);
});
};

Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/directives/dashboard/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
rawData = {};

_.each(response.data, function(value, key) {
rawData[key] = value[scope.options.field]
rawData[key] = value[scope.options.field];
});

_.each(rawData, function(value) {
Expand Down Expand Up @@ -152,8 +152,8 @@

scope.chart = chart;
}, function(err) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
scope.error = true;
NotificationSrv.error('dashboardBar', 'Failed to fetch data, please edit the widget definition', err.status);
});
};

Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/directives/dashboard/multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@
};

scope.chart = chart;
}, function(/*err*/) {
}, function(err) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
NotificationSrv.error('dashboardBar', 'Failed to fetch data, please edit the widget definition', err.status);
});
};

Expand Down
5 changes: 2 additions & 3 deletions ui/app/scripts/directives/dashboard/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@

scope.content = template;

}, function(/*err*/) {
}, function(err) {
scope.error = true;

NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
NotificationSrv.error('dashboardBar', 'Failed to fetch data, please edit the widget definition', err.status);
});
};

Expand Down
6 changes: 4 additions & 2 deletions ui/app/scripts/services/AuditSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
'rootId': rootId,
'count': max
}
}).success(function(data) {
}).then(function(response) {
var data = response.data;

angular.forEach(data, function(d) {
ret.push(d);
});
Expand Down Expand Up @@ -47,7 +49,7 @@
};

StreamSrv.addListener(eventConfig);
}).error(function(data, status) {
}).catch(function(data, status) {
NotificationSrv.error('AuditSrv', data, status);
});
return ret;
Expand Down
Loading

0 comments on commit b43e951

Please sign in to comment.