fix(user-service): make sync calls to update user async

This commit is contained in:
EvB 2017-05-26 14:27:28 -04:00
parent 4750d1c5ef
commit 20284f57f3

View file

@ -3,9 +3,9 @@
* about the user.
*/
angular.module('quay')
.factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config', '$location',
.factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config', '$location', '$timeout',
function(ApiService, CookieService, $rootScope, Config, $location) {
function(ApiService, CookieService, $rootScope, Config, $location, $timeout) {
var userResponse = {
verified: false,
anonymous: true,
@ -25,10 +25,14 @@ function(ApiService, CookieService, $rootScope, Config, $location) {
userService.updateUserIn = function(scope, opt_callback) {
scope.$watch(function () { return userService.currentUser(); }, function (currentUser) {
scope.user = currentUser;
if (opt_callback) {
opt_callback(currentUser);
}
if (currentUser) {
$timeout(function(){
scope.user = currentUser;
if (opt_callback) {
opt_callback(currentUser);
}
}, 0, false);
};
}, true);
};
@ -185,25 +189,20 @@ function(ApiService, CookieService, $rootScope, Config, $location) {
var deleteNamespaceItself = function() {
info.progress = 1;
info.progressMessage = 'Deleting namespace...';
if (info.user) {
ApiService.deleteCurrentUser().then(function(resp) {
// Reload the user.
userService.load();
var cb = function(resp) {
userService.load(function(currentUser) {
callback(true);
$location.path('/');
}, errorDisplay);
});
}
if (info.user) {
ApiService.deleteCurrentUser().then(cb, errorDisplay)
} else {
var delParams = {
'orgname': info.organization.name
};
ApiService.deleteAdminedOrganization(null, delParams).then(function(resp) {
// Reload the user.
userService.load();
callback(true);
$location.path('/');
}, errorDisplay);
ApiService.deleteAdminedOrganization(null, delParams).then(cb, errorDisplay);
}
};