Skip to content

Commit

Permalink
Fixes #29454 - container tags don't show all CVVs (#8658)
Browse files Browse the repository at this point in the history
* Fixes #29454 - container tags don't show all CVVs

* Fixes #29454 - container tags don't show all CVVs

* Fixes #29454 - container tags don't show all CVVs

* Fixes #29454 - container tags don't show all CVVs

Co-authored-by: Jonathon Turel <[email protected]>
  • Loading branch information
ianballou and jturel authored Apr 27, 2020
1 parent e801fb0 commit 576259f
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 34 deletions.
17 changes: 17 additions & 0 deletions app/controllers/katello/api/v2/docker_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ def index
end
end

api :GET, "/docker_tags/:id/repositories", N_("List of repositories for a docker meta tag")
def repositories
tag = DockerMetaTag.find(params[:id])

if tag.repositories.size > 1 #pulp3
repos = tag.repositories.non_archived
else
repos = []
tag.related_tags.each do |related|
repos << related.repositories.non_archived
end
repos.flatten!
end

respond_with_template_collection('index', 'repositories', collection: full_result_response(repos))
end

private

def find_repositories
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/docker_meta_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.search_in_tags(tags, grouped = false)
if grouped
grouped_fields = "#{table_name}.name, katello_repositories.root_id"
ids = distinct.select("ON (#{grouped_fields}) #{table_name}.id").joins(:repositories)
where(:id => ids).where("#{self.table_name}.schema1_id in (#{sql}) or #{self.table_name}.schema2_id in (#{sql})")
self.where(:id => ids)
else
self.where("#{self.table_name}.schema1_id in (#{sql}) or #{self.table_name}.schema2_id in (#{sql})")
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/katello/api/v2/docker_tags/_base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ child :docker_manifest => :manifest do
attributes :schema_version, :digest, :manifest_type
end

child :repository => :repository do
child :repositories => :repositories do
attributes :id, :name, :full_path
end

Expand Down
8 changes: 8 additions & 0 deletions app/views/katello/api/v2/repositories/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ end
child :content_view => :content_view do |_repo|
attribute :id, :name
end

child :content_view_version do
attributes :id, :name, :content_view_id
end

child :environment do
attributes :id, :name
end
3 changes: 3 additions & 0 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class ActionDispatch::Routing::Mapper
get :auto_complete_name
get :compare
end
member do
get :repositories
end
end

api_resources :environments, :only => [:index, :show, :create, :update, :destroy] do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,24 @@ angular.module('Bastion.docker-tags').controller('DockerTagEnvironmentsControlle
'sort_order': 'ASC',
'paged': false
};

var nutupane = new Nutupane(DockerTag, params, null, {disableAutoLoad: true});

var renderTable = function () {
var ids = _.map($scope.tag.related_tags, 'id');
var newParams = {
'organization_id': CurrentOrganization,
'search': $location.search().search || "",
'sort_by': 'name',
'sort_order': 'ASC',
'paged': false,
'ids[]': ids
};
$scope.table = nutupane.table;
nutupane.setParams(newParams);
$scope.panel.loading = false;
if (!_.isEmpty(ids)) {
nutupane.refresh();
}
params.action = 'repositories';
params.id = $scope.tag.id;

nutupane.setParams(params);
nutupane.refresh();
};

$scope.table = nutupane.table;

$scope.controllerName = 'katello_docker_tags';

if ($scope.tag) {
$scope.tag.$promise.then(function() {
$scope.panel.loading = false;
}

if ($scope.tag && $scope.tag.related_tags) {
renderTable();
} else {
$scope.tag.$promise.then(renderTable);
}
});
}
]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@

<tbody>
<tr bst-table-row
ng-repeat="tag in table.rows | filter:dockerTagFilter">
ng-repeat="repo in table.rows | filter:dockerTagFilter">
<td bst-table-cell>
<a ui-sref="environment.details({environmentId: tag.environment.id})">
{{ tag.environment.name }}
<a ui-sref="environment.details({environmentId: repo.kt_environment.id})">
{{ repo.kt_environment.name }}
</a>
</td>
<td bst-table-cell>
<a ui-sref="content-view.version.docker({contentViewId: tag.content_view_version.content_view_id, versionId: tag.content_view_version.id})">
{{ tag.content_view_version.name }}
<a ui-sref="content-view.version.docker({contentViewId: repo.content_view_version.content_view_id, versionId: repo.content_view_version.id})">
{{ repo.content_view_version.name }}
</a>
</td>
<td bst-table-cell>
{{ tag.repository.full_path }}:{{ tag.name }}
{{ repo.full_path }}:{{ tag.name }}
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ angular.module('Bastion.docker-tags').controller('DockerTagsController',
}
return versions.join(", ");
};

$scope.getRepositoryNames = function (tag) {
return tag.repositories.map(function(repo) {
return repo.name;
}).filter(function(item, index, names) {
return names.indexOf(item) >= index;
}).sort().join(', ');
};
}]
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
angular.module('Bastion.docker-tags').factory('DockerTag',
['BastionResource', 'CurrentOrganization', function (BastionResource, CurrentOrganization) {

return BastionResource('katello/api/v2/docker_tags/:id/',
return BastionResource('katello/api/v2/docker_tags/:id/:action/',
{id: '@id', 'organization_id': CurrentOrganization},
{
autocomplete: {method: 'GET', isArray: true, params: {id: 'auto_complete_search'}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 translate>Container Image Tags</h2>
{{ tag.product.name }}
</td>
<td bst-table-cell>
{{ tag.repository.name }}
{{ getRepositoryNames(tag) }}
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Controller: DockerTagEnvironmentsController', function() {
this.getParams = function (params) { return {}; };
this.refresh = function () {};
};
dockerTag = {id: 1, related_tags: [{id: 1}]};
dockerTag = {id: 1, related_tags: [{id: 1}], repositories: ['test1']};
DockerTag = MockResource.$new();
}));

Expand All @@ -29,6 +29,7 @@ describe('Controller: DockerTagEnvironmentsController', function() {
$scope.tag = dockerTag;
$scope.panel = {};
$scope.$stateParams = {tagId: 1};
$scope.tag.$promise = { then: function (callback) { callback({}) } };

$controller('DockerTagEnvironmentsController', {
$scope: $scope,
Expand Down
7 changes: 6 additions & 1 deletion lib/katello/permission_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ def product_permissions # rubocop:disable Metrics/MethodLength
'katello/api/v2/package_groups' => [:index, :show, :auto_complete_search, :compare],
'katello/api/v2/docker_manifests' => [:index, :show, :auto_complete_search, :compare],
'katello/api/v2/docker_manifest_lists' => [:index, :show, :auto_complete_search, :compare],
'katello/api/v2/docker_tags' => [:index, :show, :auto_complete_search, :auto_complete_name, :compare],
'katello/api/v2/docker_tags' => [:index,
:show,
:auto_complete_search,
:auto_complete_name,
:compare,
:repositories],
'katello/api/v2/file_units' => [:index, :show, :auto_complete_search, :compare],
'katello/api/v2/ostree_branches' => [:index, :show, :auto_complete_search, :compare],
'katello/api/v2/errata' => [:index, :show, :auto_complete_search, :compare],
Expand Down
10 changes: 10 additions & 0 deletions test/models/docker_meta_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,15 @@ def test_search_meta_tag

assert_includes DockerMetaTag.search_for("repository = #{dmt.repositories.first.name}"), dmt
end

def test_search_in_tags
DockerMetaTag.import_meta_tags([@repo])
repo2 = Repository.find_by(pulp_id: "Default_Organization-Test-busybox-dev")
dup_tag = DockerMetaTag.create(schema1_id: repo2.docker_tags.min.id, schema2_id: repo2.docker_tags.sort.second.id, name: "latest")
RepositoryDockerMetaTag.create(docker_meta_tag_id: dup_tag.id, repository_id: repo2.id)

assert_equal DockerMetaTag.search_in_tags(DockerTag.all).sort, [DockerMetaTag.first, dup_tag]
assert_equal DockerMetaTag.search_in_tags(DockerTag.all, true).sort, [DockerMetaTag.first]
end
end
end

0 comments on commit 576259f

Please sign in to comment.