Call rest api to transfer ownership

This commit is contained in:
Johannes Zellner
2021-01-14 20:47:30 +01:00
parent 2086444a9e
commit e0f6ddfcf7
2 changed files with 36 additions and 1 deletions

View File

@@ -67,6 +67,41 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
submit: function () {
$scope.transferOwnership.busy = true;
// first grant other user owner role, then remove it from existing
var data = {
id: $scope.transferOwnership.userInfo.id,
role: 'owner'
};
Client.updateUser(data, function (error) {
if (error) {
$scope.transferOwnership.busy = false;
$scope.transferOwnership.error = error.message;
console.error('Unable to change user role:', error);
return;
}
data = {
id: $scope.userInfo.id,
role: 'user'
};
Client.updateUser(data, function (error) {
$scope.transferOwnership.busy = false;
if (error) {
$scope.transferOwnership.error = error.message;
console.error('Unable to change user role:', error);
return;
}
$('#transferOwnershipModal').modal('hide');
// current user was demoted, reload to refresh UI state
window.location.reload();
});
});
}
};