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 @@
- -
-
No tags selected to view
-
- Please select one or more tags in the Tags tab to visualize. +
+ +
+
No tags selected to view
+
+ Please select one or more tags in the Tags tab to visualize. +
-
- -
-

- Visualize Tags: - - {{ tag }} - -

+ +
+

+ Visualize Tags: + + {{ tag }} + +

-
+
- -
-
- -
-
-
- - -
-
- {{ currentTag }} -
-
- {{ currentImage.substr(0, 12) }} -
- -
- -
-
- - -
+ +
+
+ +
-
+ + +
+
+ {{ currentTag }} +
+
+ {{ currentImage.substr(0, 12) }} +
+ +
+ +
+
+ + +
+
+
+
+
diff --git a/static/directives/repo-view/repo-panel-tags.html b/static/directives/repo-view/repo-panel-tags.html index 740ee7834..dbb752e23 100644 --- a/static/directives/repo-view/repo-panel-tags.html +++ b/static/directives/repo-view/repo-panel-tags.html @@ -1,7 +1,6 @@

Repository Tags

-
diff --git a/static/js/directives/repo-view/repo-panel-changes.js b/static/js/directives/repo-view/repo-panel-changes.js index a2eee551c..7b5debe37 100644 --- a/static/js/directives/repo-view/repo-panel-changes.js +++ b/static/js/directives/repo-view/repo-panel-changes.js @@ -89,6 +89,10 @@ angular.module('quay').directive('repoPanelChanges', function () { scope: { 'repository': '=repository', 'selectedTags': '=selectedTags', + + 'imagesResource': '=imagesResource', + 'images': '=images', + 'isEnabled': '=isEnabled' }, controller: function($scope, $element, $timeout, ApiService, UtilService, ImageMetadataService) { @@ -99,13 +103,24 @@ angular.module('quay').directive('repoPanelChanges', function () { $scope.currentImage = null; $scope.currentTag = null; - if (!$scope.imagesResource) { - loadImages(); + if (!$scope.tracker) { + updateImages(); + } + }; + + var updateImages = function() { + if (!$scope.repository || !$scope.images) { return; } + + $scope.tracker = new RepositoryImageTracker($scope.repository, $scope.images); + + if ($scope.selectedTags && $scope.selectedTags.length) { + refreshTree(); } }; $scope.$watch('selectedTags', update) $scope.$watch('repository', update); + $scope.$watch('images', updateImages); $scope.$watch('isEnabled', function(isEnabled) { if (isEnabled) { @@ -147,23 +162,6 @@ angular.module('quay').directive('repoPanelChanges', function () { } }; - var loadImages = function(opt_callback) { - var params = { - 'repository': $scope.repository.namespace + '/' + $scope.repository.name - }; - - $scope.imagesResource = ApiService.listRepositoryImagesAsResource(params).get(function(resp) { - $scope.images = resp.images; - $scope.tracker = new RepositoryImageTracker($scope.repository, $scope.images); - - if ($scope.selectedTags && $scope.selectedTags.length) { - refreshTree(); - } - - opt_callback && opt_callback(); - }); - }; - $scope.setImage = function(image_id) { $scope.currentTag = null; $scope.currentImage = image_id; diff --git a/static/js/directives/repo-view/repo-panel-tags.js b/static/js/directives/repo-view/repo-panel-tags.js index 84b75c25f..c96098b8d 100644 --- a/static/js/directives/repo-view/repo-panel-tags.js +++ b/static/js/directives/repo-view/repo-panel-tags.js @@ -10,7 +10,9 @@ angular.module('quay').directive('repoPanelTags', function () { restrict: 'C', scope: { 'repository': '=repository', - 'selectedTags': '=selectedTags' + 'selectedTags': '=selectedTags', + 'imagesResource': '=imagesResource', + 'images': '=images', }, controller: function($scope, $element, $filter, $location, ApiService, UIService) { var orderBy = $filter('orderBy'); @@ -24,16 +26,6 @@ angular.module('quay').directive('repoPanelTags', function () { $scope.iterationState = {}; $scope.tagActionHandler = null; - var loadImages = function() { - var params = { - 'repository': $scope.repository.namespace + '/' + $scope.repository.name - }; - - $scope.imagesResource = ApiService.listRepositoryImagesAsResource(params).get(function(resp) { - $scope.images = resp.images; - }); - }; - var setTagState = function() { if (!$scope.repository || !$scope.selectedTags) { return; } @@ -124,9 +116,6 @@ angular.module('quay').directive('repoPanelTags', function () { $scope.$watch('repository', function(repository) { if (!repository) { return; } - // Load the repository's images. - loadImages(); - // Process each of the tags. setTagState(); }); diff --git a/static/js/pages/repo-view.js b/static/js/pages/repo-view.js index 9e84aa549..81fc620f2 100644 --- a/static/js/pages/repo-view.js +++ b/static/js/pages/repo-view.js @@ -21,6 +21,8 @@ $scope.viewScope = { 'selectedTags': [], 'repository': null, + 'images': null, + 'imagesResource': null, 'builds': null, 'changesVisible': false }; @@ -70,6 +72,16 @@ }); }; + var loadImages = function() { + var params = { + 'repository': $scope.namespace + '/' + $scope.name + }; + + $scope.viewScope.imagesResource = ApiService.listRepositoryImagesAsResource(params).get(function(resp) { + $scope.viewScope.images = resp.images; + }); + }; + var loadRepositoryBuilds = function(callback) { var params = { 'repository': $scope.namespace + '/' + $scope.name, @@ -86,8 +98,9 @@ }, errorHandler); }; - // Load the repository. + // Load the repository and images. loadRepository(); + loadImages(); $scope.setTags = function(tagNames) { if (!tagNames) { diff --git a/static/partials/repo-view.html b/static/partials/repo-view.html index b0bde7883..f63885110 100644 --- a/static/partials/repo-view.html +++ b/static/partials/repo-view.html @@ -59,6 +59,8 @@
@@ -73,6 +75,8 @@