diff --git a/data/model/legacy.py b/data/model/legacy.py index 7ff24adc8..2d076c5cc 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -1146,6 +1146,9 @@ def get_repo_image_extended(namespace_name, repository_name, docker_image_id): return images[0] +def is_repository_public(repository): + return repository.visibility == _get_public_repo_visibility() + def repository_is_public(namespace_name, repository_name): try: (Repository @@ -1579,9 +1582,15 @@ def _tag_alive(query): (RepositoryTag.lifetime_end_ts > int(time.time()))) -def list_repository_tags(namespace_name, repository_name, include_hidden=False): +def list_repository_tags(namespace_name, repository_name, include_hidden=False, + include_storage=False): + + toSelect = (RepositoryTag, Image) + if include_storage: + toSelect = (RepositoryTag, Image, ImageStorage) + query = _tag_alive(RepositoryTag - .select(RepositoryTag, Image) + .select(*toSelect) .join(Repository) .join(Namespace, on=(Repository.namespace_user == Namespace.id)) .switch(RepositoryTag) @@ -1592,6 +1601,9 @@ def list_repository_tags(namespace_name, repository_name, include_hidden=False): if not include_hidden: query = query.where(RepositoryTag.hidden == False) + if include_storage: + query = query.switch(Image).join(ImageStorage) + return query diff --git a/endpoints/api/image.py b/endpoints/api/image.py index f82bfd55a..71171d572 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -17,7 +17,7 @@ def image_view(image, image_map): command = extended_props.command def docker_id(aid): - if not aid: + if not aid or not aid in image_map: return '' return image_map[aid] @@ -51,19 +51,26 @@ class RepositoryImageList(RepositoryParamResource): all_tags = model.list_repository_tags(namespace, repository) tags_by_image_id = defaultdict(list) + found_image_ids = set() + for tag in all_tags: tags_by_image_id[tag.image.docker_image_id].append(tag.name) + found_image_ids.add(str(tag.image.id)) + found_image_ids.update(tag.image.ancestors.split('/')[1:-1]) image_map = {} + filtered_images = [] for image in all_images: - image_map[str(image.id)] = image.docker_image_id + if str(image.id) in found_image_ids: + image_map[str(image.id)] = image.docker_image_id + filtered_images.append(image) def add_tags(image_json): image_json['tags'] = tags_by_image_id[image_json['id']] return image_json return { - 'images': [add_tags(image_view(image, image_map)) for image in all_images] + 'images': [add_tags(image_view(image, image_map)) for image in filtered_images] } diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 74f494112..9d610e686 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -188,16 +188,9 @@ class Repository(RepositoryParamResource): return tag_info - organization = None - try: - organization = model.get_organization(namespace) - except model.InvalidOrganizationException: - pass - - is_public = model.repository_is_public(namespace, repository) repo = model.get_repository(namespace, repository) if repo: - tags = model.list_repository_tags(namespace, repository) + tags = model.list_repository_tags(namespace, repository, include_storage=True) tag_dict = {tag.name: tag_view(tag) for tag in tags} can_write = ModifyRepositoryPermission(namespace, repository).can() can_admin = AdministerRepositoryPermission(namespace, repository).can() @@ -206,6 +199,7 @@ class Repository(RepositoryParamResource): is_starred = (model.repository_is_starred(get_authenticated_user(), repo) if get_authenticated_user() else False) + is_public = model.is_repository_public(repo) return { 'namespace': namespace, @@ -216,7 +210,7 @@ class Repository(RepositoryParamResource): 'can_admin': can_admin, 'is_public': is_public, 'is_building': len(list(active_builds)) > 0, - 'is_organization': bool(organization), + 'is_organization': repo.namespace_user.organization, 'is_starred': is_starred, 'status_token': repo.badge_token if not is_public else '', 'stats': { diff --git a/static/directives/repo-view/repo-panel-changes.html b/static/directives/repo-view/repo-panel-changes.html index b69ef66e4..281fff6bb 100644 --- a/static/directives/repo-view/repo-panel-changes.html +++ b/static/directives/repo-view/repo-panel-changes.html @@ -1,61 +1,64 @@