-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37884 - CVE controller to query
- Loading branch information
Showing
7 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/controllers/katello/api/v2/content_view_environments_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Katello | ||
class Api::V2::ContentViewEnvironmentsController < Api::V2::ApiController | ||
before_action :find_optional_organization, :only => [:index, :auto_complete_search] | ||
before_action :find_environment | ||
before_action :find_content_view | ||
before_action :find_activation_key | ||
before_action :find_host | ||
|
||
resource_description do | ||
api_version "v2" | ||
end | ||
|
||
api :GET, "/content_view_environments", N_("List content view environmentss") | ||
param :organization_id, :number, :desc => N_("organization identifier"), :required => false | ||
param :lifecycle_environment_id, :number, :desc => N_("environment identifier"), :required => false | ||
param :content_view_id, :number, :desc => N_("Content view identifier"), :required => false | ||
param :activation_key_id, :number, :desc => N_("Activation key identifier"), :required => false | ||
param :host_id, :number, :desc => N_("Host identifier"), :required => false | ||
param_group :search, Api::V2::ApiController | ||
def index | ||
respond(:collection => scoped_search(index_relation.distinct, :id, :asc, resource_class: ContentViewEnvironment)) | ||
end | ||
|
||
def index_relation | ||
content_view_environments = ContentViewEnvironment.readable.non_generated | ||
content_view_environments = content_view_environments.in_organization(@organization) if @organization | ||
content_view_environments = content_view_environments.where(environment: @environment) if @environment | ||
content_view_environments = content_view_environments.where(content_view: @content_view) if @content_view | ||
content_view_environments = content_view_environments.where(id: @activation_key.content_view_environments) if @activation_key | ||
content_view_environments = content_view_environments.where(id: @host.content_view_environments) if @host | ||
content_view_environments | ||
end | ||
|
||
def find_environment | ||
return unless params.key?(:lifecycle_environment_id) | ||
@environment = KTEnvironment.readable.find(params[:lifecycle_environment_id]) | ||
end | ||
|
||
def find_content_view | ||
return unless params.key?(:content_view_id) | ||
@content_view = ContentView.readable.find(params[:content_view_id]) | ||
end | ||
|
||
def find_activation_key | ||
return unless params.key?(:activation_key_id) | ||
@activation_key = ActivationKey.readable.find(params[:activation_key_id]) | ||
end | ||
|
||
def find_host | ||
return unless params.key?(:host_id) | ||
@host = ::Host::Managed.authorized("view_hosts").find(params[:host_id]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/views/katello/api/v2/content_view_environments/index.json.rabl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object false | ||
|
||
extends "katello/api/v2/common/metadata" | ||
|
||
child @collection[:results] => :results do | ||
extends "katello/api/v2/content_view_environments/show" | ||
end |
29 changes: 29 additions & 0 deletions
29
app/views/katello/api/v2/content_view_environments/show.json.rabl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
object @resource | ||
extends 'katello/api/v2/common/identifier' | ||
|
||
extends 'katello/api/v2/common/timestamps' | ||
attributes :default_environment? => :default | ||
|
||
child :organization => :organization do | ||
attributes :name, :label, :id | ||
end | ||
|
||
node :content_view do |cve| | ||
cve.content_view&.slice(:id, :name, :label, :default) | ||
end | ||
|
||
node :lifecyle_environment do |cve| | ||
cve.environment&.slice(:id, :name, :label, :library) | ||
end | ||
|
||
node :environment do |cve| | ||
cve.environment&.slice(:id, :name, :label, :library) | ||
end | ||
|
||
child :activation_keys => :activation_keys do | ||
attributes :id, :name, :label | ||
end | ||
|
||
node :hosts_count do |cve| | ||
cve.hosts.count | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/controllers/api/v2/content_view_environments_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require "katello_test_helper" | ||
module Katello | ||
class Api::V2::ContentViewEnvironmentsControllerTest < ActionController::TestCase | ||
include Support::ForemanTasks::Task | ||
|
||
def models | ||
@organization = get_organization | ||
@library_dev_staging_view = katello_content_views(:library_dev_staging_view) | ||
@staging = KTEnvironment.find(katello_environments(:staging).id) | ||
@library_dev_staging_ak = katello_activation_keys(:library_dev_staging_view_key) | ||
end | ||
|
||
def permissions | ||
@view_cv_permission = :view_content_views | ||
@view_lce_permission = :view_lifecycle_environments | ||
@denied_perms = [:create_content_views] | ||
end | ||
|
||
def setup | ||
setup_controller_defaults_api | ||
models | ||
permissions | ||
end | ||
|
||
def test_index | ||
get :index, params: { } | ||
|
||
assert_response :success | ||
assert_template 'api/v2/content_view_environments/index' | ||
end | ||
|
||
def test_index_org | ||
get :index, params: { :organization_id => @organization.id } | ||
|
||
assert_response :success | ||
assert_template 'api/v2/content_view_environments/index' | ||
end | ||
|
||
def test_index_in_environment | ||
get :index, params: { :lifecycle_environment_id => @staging.id } | ||
|
||
assert_response :success | ||
assert_template 'api/v2/content_view_environments/index' | ||
end | ||
|
||
def test_index_in_content_view | ||
get :index, params: { :content_view_id => @library_dev_staging_view.id } | ||
|
||
assert_response :success | ||
assert_template 'api/v2/content_view_environments/index' | ||
end | ||
|
||
def test_index_for_activation_key | ||
get :index, params: { :activation_key_id => @library_dev_staging_ak.id } | ||
|
||
assert_response :success | ||
assert_template 'api/v2/content_view_environments/index' | ||
end | ||
|
||
def test_index_protected | ||
allowed_perms = [@view_cv_permission, @view_lce_permission] | ||
assert_protected_action(:index, allowed_perms, @denied_perms, [@organization]) do | ||
get :index, params: {} | ||
end | ||
end | ||
end | ||
end |