Add support for deleting namespaces (users, organizations)
Fixes #102 Fixes #105
This commit is contained in:
parent
a74e94fb67
commit
73eb66eac5
23 changed files with 407 additions and 33 deletions
|
@ -3,9 +3,9 @@
|
|||
* about the user.
|
||||
*/
|
||||
angular.module('quay')
|
||||
.factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config',
|
||||
.factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config', '$location',
|
||||
|
||||
function(ApiService, CookieService, $rootScope, Config) {
|
||||
function(ApiService, CookieService, $rootScope, Config, $location) {
|
||||
var userResponse = {
|
||||
verified: false,
|
||||
anonymous: true,
|
||||
|
@ -169,6 +169,69 @@ function(ApiService, CookieService, $rootScope, Config) {
|
|||
return externalUsername || userResponse.username;
|
||||
};
|
||||
|
||||
userService.deleteNamespace = function(info, callback) {
|
||||
var namespace = info.user ? info.user.username : info.organization.name;
|
||||
var deleteNamespaceItself = function() {
|
||||
info.progress = 1;
|
||||
info.progressMessage = 'Deleting namespace...';
|
||||
|
||||
if (info.user) {
|
||||
ApiService.deleteCurrentUser().then(function(resp) {
|
||||
// Reload the user.
|
||||
userService.load();
|
||||
callback(true);
|
||||
$location.path('/');
|
||||
}, errorDisplay);
|
||||
} else {
|
||||
var delParams = {
|
||||
'name': info.organization.name
|
||||
};
|
||||
|
||||
ApiService.deleteOrganization(null, delParams).then(function(resp) {
|
||||
// Reload the user.
|
||||
userService.load();
|
||||
callback(true);
|
||||
$location.path('/');
|
||||
}, errorDisplay);
|
||||
}
|
||||
};
|
||||
|
||||
var repoIndex = 0;
|
||||
var repositories = null;
|
||||
var deleteAllRepos = function() {
|
||||
if (repoIndex >= repositories.length) {
|
||||
deleteNamespaceItself();
|
||||
return;
|
||||
}
|
||||
|
||||
var repoParams = {
|
||||
'repository': namespace + '/' + repositories[repoIndex]['name']
|
||||
};
|
||||
|
||||
info.progress = repoIndex / repositories.length;
|
||||
info.progressMessage = 'Deleting repository ' + repoParams['repository'] + '...';
|
||||
|
||||
ApiService.deleteRepository(null, repoParams).then(function() {
|
||||
repoIndex++;
|
||||
deleteAllRepos();
|
||||
}, errorDisplay);
|
||||
};
|
||||
|
||||
// First delete each repo for the namespace, updating the info so it can show a progress bar.
|
||||
// This is not strictly necessary (as the namespace delete call will do it as well), but it is
|
||||
// a better user experience.
|
||||
var params = {
|
||||
'namespace': namespace,
|
||||
'public': false
|
||||
};
|
||||
|
||||
var errorDisplay = ApiService.errorDisplay('Could not delete namespace', callback);
|
||||
ApiService.listRepos(null, params).then(function(resp) {
|
||||
repositories = resp['repositories'];
|
||||
deleteAllRepos();
|
||||
}, errorDisplay);
|
||||
};
|
||||
|
||||
userService.currentUser = function() {
|
||||
return userResponse;
|
||||
};
|
||||
|
|
Reference in a new issue