Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #14825: Don't require organization to search repositories (#5999)
  • Loading branch information
ehelms authored and daviddavis committed May 2, 2016
1 parent 5d88cd2 commit f4ae98f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/controllers/katello/api/v2/repositories_controller.rb
Expand Up @@ -2,7 +2,7 @@ module Katello
class Api::V2::RepositoriesController < Api::V2::ApiController
include Katello::Concerns::FilteredAutoCompleteSearch

before_filter :find_organization, :only => [:index, :auto_complete_search]
before_filter :find_optional_organization, :only => [:index, :auto_complete_search]
before_filter :find_product, :only => [:index, :auto_complete_search]
before_filter :find_product_for_create, :only => [:create]
before_filter :find_organization_from_product, :only => [:create]
Expand Down Expand Up @@ -36,7 +36,7 @@ class Api::V2::RepositoriesController < Api::V2::ApiController

api :GET, "/repositories", N_("List of enabled repositories")
api :GET, "/content_views/:id/repositories", N_("List of repositories for a content view")
param :organization_id, :number, :required => true, :desc => N_("ID of an organization to show repositories in")
param :organization_id, :number, :desc => N_("ID of an organization to show repositories in")
param :product_id, :number, :desc => N_("ID of a product to show repositories of")
param :environment_id, :number, :desc => N_("ID of an environment to show repositories in")
param :content_view_id, :number, :desc => N_("ID of a content view to show repositories in")
Expand Down Expand Up @@ -105,7 +105,12 @@ def index_relation_environment(query)
instance_ids += instances.where(:library_instance_id => nil)
query = Repository.where(:id => instance_ids)
elsif (params[:library] && !params[:environment_id]) || (params[:environment_id].blank? && params[:content_view_version_id].blank? && params[:content_view_id].blank?)
query = query.where(:content_view_version_id => @organization.default_content_view.versions.first.id)

if @organization
query = query.where(:content_view_version_id => @organization.default_content_view.versions.first.id)
else
query = query.in_default_view
end
end
query
end
Expand Down Expand Up @@ -316,6 +321,7 @@ def gpg_key_content

def find_product
@product = Product.find(params[:product_id]) if params[:product_id]
find_organization_from_product if @organization.nil? && @product
end

def find_product_for_create
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/repositories_controller_test.rb
Expand Up @@ -83,7 +83,7 @@ def assert_response_ids(response, expected)
def test_index_with_product_id
ids = Repository.where(:product_id => @product.id, :library_instance_id => nil).pluck(:id)

response = get :index, :product_id => @product.id, :organization_id => @organization.id
response = get :index, :product_id => @product.id
response_ids = JSON.parse(response.body)['results'].map { |repo| repo['id'] }

assert_response :success
Expand Down

0 comments on commit f4ae98f

Please sign in to comment.