Fix deletion of repos and users with V2 stuff

Fixes #674
This commit is contained in:
Joseph Schorr 2015-10-21 14:07:25 -04:00
parent d24e69df2d
commit 803a983126
3 changed files with 15 additions and 4 deletions

View file

@ -7,8 +7,8 @@ from data.model import (DataModelException, tag, db_transaction, storage, image,
_basequery, config)
from data.database import (Repository, Namespace, RepositoryTag, Star, Image, ImageStorage, User,
Visibility, RepositoryPermission, TupleSelector, RepositoryActionCount,
Role, RepositoryAuthorizedEmail, db_for_update, get_epoch_timestamp,
db_random_func)
Role, RepositoryAuthorizedEmail, TagManifest, db_for_update,
get_epoch_timestamp, db_random_func)
logger = logging.getLogger(__name__)
@ -43,6 +43,12 @@ def _purge_all_repository_tags(namespace_name, repository_name):
except Repository.DoesNotExist:
raise DataModelException('Invalid repository \'%s/%s\'' %
(namespace_name, repository_name))
# Delete all manifests.
repo_tags = RepositoryTag.select().where(RepositoryTag.repository == repo.id)
TagManifest.delete().where(TagManifest.tag << repo_tags).execute()
# Delete all tags.
RepositoryTag.delete().where(RepositoryTag.repository == repo.id).execute()

View file

@ -650,9 +650,12 @@ def detach_external_login(user, service_name):
def delete_user(user):
user.delete_instance(recursive=True, delete_nullable=True)
# Delete any repositories under the user's namespace.
for repo in list(Repository.select().where(Repository.namespace_user == user)):
repository.purge_repository(user.username, repo.name)
# TODO: also delete any repository data associated
# Delete the user itself.
user.delete_instance(recursive=True, delete_nullable=True)
def get_pull_credentials(robotname):

View file

@ -21,6 +21,7 @@ from data.database import (db, all_models, Role, TeamRole, Visibility, LoginServ
from data import model
from app import app, storage as store
from storage.basestorage import StoragePaths
from endpoints.v2.manifest import _generate_and_store_manifest
from workers import repositoryactioncounter
@ -132,6 +133,7 @@ def __create_subtree(repo, structure, creator_username, parent, tag_map):
new_tag = model.tag.create_or_update_tag(repo.namespace_user.username, repo.name, tag_name,
new_image.docker_image_id)
_generate_and_store_manifest(repo.namespace_user.username, repo.name, tag_name)
tag_map[tag_name] = new_tag
for tag_name in last_node_tags: