diff --git a/app/controllers/katello/api/v2/content_view_histories_controller.rb b/app/controllers/katello/api/v2/content_view_histories_controller.rb new file mode 100644 index 00000000000..029412c4f51 --- /dev/null +++ b/app/controllers/katello/api/v2/content_view_histories_controller.rb @@ -0,0 +1,23 @@ +module Katello + class Api::V2::ContentViewHistoriesController < Api::V2::ApiController + include Katello::Concerns::FilteredAutoCompleteSearch + + before_filter :find_content_view + + api :GET, "/content_views/:id/history", N_("Show a content view's history") + param :id, :number, :desc => N_("content view numeric identifier"), :required => true + def index + respond_for_index :collection => scoped_search(index_relation.uniq, :katello_content_view_version_id, :asc, :resource_class => ContentViewHistory) + end + + def index_relation + ContentViewHistory.joins(:content_view_version).where("#{ContentViewVersion.table_name}.content_view_id" => @view.id) + end + + private + + def find_content_view + @view = ContentView.find(params[:content_view_id]) if params[:content_view_id] + end + end +end diff --git a/app/controllers/katello/api/v2/content_views_controller.rb b/app/controllers/katello/api/v2/content_views_controller.rb index 496010a89e8..dd65a87faa4 100644 --- a/app/controllers/katello/api/v2/content_views_controller.rb +++ b/app/controllers/katello/api/v2/content_views_controller.rb @@ -6,8 +6,6 @@ class Api::V2::ContentViewsController < Api::V2::ApiController before_filter :find_content_view, :except => [:index, :create, :auto_complete_search] before_filter :find_organization, :only => [:create] before_filter :find_optional_organization, :only => [:index, :auto_complete_search] - before_filter :load_search_service, :only => [:history, :available_puppet_modules, - :available_puppet_module_names] before_filter :find_environment, :only => [:index, :remove_from_environment] wrap_parameters :include => (ContentView.attribute_names + %w(repository_ids component_ids)) @@ -119,17 +117,6 @@ def available_puppet_module_names :collection => scoped_search(modules, 'name', 'ASC', :resource_class => PuppetModule, :group => :name) end - api :GET, "/content_views/:id/history", N_("Show a content view's history") - param :id, :number, :desc => N_("content view numeric identifier"), :required => true - def history - options = sort_params - options[:load_records?] = true - options[:filters] = [{:term => {:content_view_id => @view.id}}] - - respond_for_index :template => '../content_view_histories/index', - :collection => item_search(ContentViewHistory, params, options) - end - api :DELETE, "/content_views/:id/environments/:environment_id", N_("Remove a content view from an environment") param :id, :number, :desc => N_("content view numeric identifier"), :required => true param :environment_id, :number, :desc => N_("environment numeric identifier"), :required => true diff --git a/app/models/katello/content_view_history.rb b/app/models/katello/content_view_history.rb index a3594bad958..055cc0dbf69 100644 --- a/app/models/katello/content_view_history.rb +++ b/app/models/katello/content_view_history.rb @@ -2,8 +2,6 @@ module Katello class ContentViewHistory < Katello::Model include Katello::Authorization::ContentViewHistory - include Glue::ElasticSearch::ContentViewHistory if SETTINGS[:katello][:use_elasticsearch] - belongs_to :environment, :class_name => "Katello::KTEnvironment", :inverse_of => :content_view_histories, :foreign_key => :katello_environment_id belongs_to :content_view_version, :class_name => "Katello::ContentViewVersion", :foreign_key => :katello_content_view_version_id, :inverse_of => :history @@ -21,6 +19,8 @@ class ContentViewHistory < Katello::Model scope :active, -> { where(:status => IN_PROGRESS) } alias_method :version, :content_view_version + scoped_search :on => :name, :in => :environment, :rename => :environment, :complete_value => true + def content_view self.content_view_version.try(:content_view) end diff --git a/app/models/katello/glue/elastic_search/content_view_history.rb b/app/models/katello/glue/elastic_search/content_view_history.rb deleted file mode 100644 index 6ccab900012..00000000000 --- a/app/models/katello/glue/elastic_search/content_view_history.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Katello - module Glue::ElasticSearch::ContentViewHistory - extend ActiveSupport::Concern - - included do - include Ext::IndexedModel - - index_options :extended_json => :extended_index_attrs, - :json => {:only => [:user, :id, :created_at, :updated_at]} - - mapping do - indexes :version_id, :type => 'integer' - indexes :created_at, :type => 'date' - indexes :environment, :type => 'string' - indexes :content_view_id, :type => 'integer' - indexes :version, :type => 'float' - indexes :user, :type => 'string' - end - end - - def extended_index_attrs - { - :environment => self.environment.try(:name), - :version_id => self.version.id, - :version => self.version.version, - :content_view_id => self.content_view.id, - :environment_id => self.katello_environment_id - } - end - end -end diff --git a/config/routes/api/v2.rb b/config/routes/api/v2.rb index a053e5a2e3d..d695da33d2b 100644 --- a/config/routes/api/v2.rb +++ b/config/routes/api/v2.rb @@ -59,7 +59,6 @@ class ActionDispatch::Routing::Mapper post :publish post :refresh put :remove - get :history get :available_puppet_modules get :available_puppet_module_names match '/environments/:environment_id' => "content_views#remove_from_environment", :via => :delete @@ -76,6 +75,11 @@ class ActionDispatch::Routing::Mapper api_resources :errata, :only => [:index] api_resources :package_groups, :only => [:index] end + api_resources :history, :controller => :content_view_histories, :only => [:index] do + collection do + get :auto_complete_search + end + end api_resources :puppet_modules, :only => [:index] api_resources :repositories, :only => [:index] api_resources :content_view_versions, :only => [:index] diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-view.factory.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-view.factory.js index 9fcca48701d..17118dc29c1 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-view.factory.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-view.factory.js @@ -19,7 +19,6 @@ angular.module('Bastion.content-views').factory('ContentView', copy: {method: 'POST', params: {action: 'copy'}}, update: {method: 'PUT'}, publish: {method: 'POST', params: {action: 'publish'}}, - history: {method: 'GET', params: {action: 'history'}}, removeAssociations: {method: 'PUT', params: {action: 'remove'}}, versions: {method: 'GET', isArray: false, params: {action: 'content_view_versions'}}, components: {method: 'GET', transformResponse: function (data) { diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.routes.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.routes.js index 0f96bf0ba80..1db746e2721 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.routes.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.routes.js @@ -219,7 +219,7 @@ angular.module('Bastion.content-views').config(['$stateProvider', function ($sta url: '/history', permission: 'view_content_views', controller: 'ContentViewHistoryController', - templateUrl: 'content-views/details/views/content-view-details-history.html' + templateUrl: 'content-views/details/histories/views/content-view-history.html' }) .state('content-views.details.composite-content-views', { abstract: true, diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/content-view-details-history.controller.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.controller.js similarity index 82% rename from engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/content-view-details-history.controller.js rename to engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.controller.js index 97257dd2270..afb86e2a971 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/content-view-details-history.controller.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.controller.js @@ -10,15 +10,15 @@ * A controller for showing the history of a content view */ angular.module('Bastion.content-views').controller('ContentViewHistoryController', - ['$scope', 'translate', 'ContentView', 'Nutupane', - function ($scope, translate, ContentView, Nutupane) { + ['$scope', 'translate', 'ContentViewHistory', 'Nutupane', + function ($scope, translate, ContentViewHistory, Nutupane) { var nutupane; - nutupane = new Nutupane(ContentView, { - id: $scope.$stateParams.contentViewId, + nutupane = new Nutupane(ContentViewHistory, { + contentViewId: $scope.$stateParams.contentViewId, 'sort_by': 'created_at', 'sort_order': 'DESC' - }, 'history'); + }); nutupane.table.closeItem = function () {}; $scope.detailsTable = nutupane.table; diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.factory.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.factory.js new file mode 100644 index 00000000000..f490c44b00b --- /dev/null +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/content-view-history.factory.js @@ -0,0 +1,22 @@ +/** + * @ngdoc service + * @name Bastion.content-views.factory:ContentViewHistory + * + * @requires BastionResource + * @requires CurrentOrganization + * + * @description + * Provides a BastionResource for interacting with content view histories. + */ +angular.module('Bastion.content-views').factory('ContentViewHistory', + ['BastionResource', 'CurrentOrganization', + function (BastionResource, CurrentOrganization) { + + return BastionResource('/katello/api/v2/content_views/:contentViewId/history/:action', + {id: '@id', contentViewId: '@contentViewId', 'organization_id': CurrentOrganization}, + { + autocomplete: {method: 'GET', isArray: true, params: {action: 'auto_complete_search'}} + } + ); + }] +); diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-details-history.html b/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/views/content-view-history.html similarity index 100% rename from engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-details-history.html rename to engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/histories/views/content-view-history.html diff --git a/lib/katello/permissions/content_view_permissions.rb b/lib/katello/permissions/content_view_permissions.rb index 2a7a78f4e3f..72c09c07bd1 100644 --- a/lib/katello/permissions/content_view_permissions.rb +++ b/lib/katello/permissions/content_view_permissions.rb @@ -3,10 +3,11 @@ Foreman::Plugin.find(:katello).security_block :content_views do permission :view_content_views, { - 'katello/api/v2/content_views' => [:index, :show, :history, :available_puppet_modules, + 'katello/api/v2/content_views' => [:index, :show, :available_puppet_modules, :available_puppet_module_names], 'katello/api/v2/content_view_filters' => [:index, :show], 'katello/api/v2/content_view_filter_rules' => [:index, :show], + 'katello/api/v2/content_view_histories' => [:index], 'katello/api/v2/content_view_puppet_modules' => [:index, :show], 'katello/api/v2/content_view_versions' => [:index, :show], 'katello/api/v2/package_groups' => [:index, :show], diff --git a/test/controllers/api/v2/content_view_histories_controller_test.rb b/test/controllers/api/v2/content_view_histories_controller_test.rb new file mode 100644 index 00000000000..8b47c3af73d --- /dev/null +++ b/test/controllers/api/v2/content_view_histories_controller_test.rb @@ -0,0 +1,38 @@ +require "katello_test_helper" + +module Katello + class Api::V2::ContentViewHistoriesControllerTest < ActionController::TestCase + def models + @library_dev_staging_view = ContentView.find(katello_content_views(:library_dev_staging_view)) + end + + def permissions + @view_permission = :view_content_views + @create_permission = :create_content_views + @update_permission = :edit_content_views + @destroy_permission = :destroy_content_views + end + + def setup + setup_controller_defaults_api + models + permissions + end + + def test_index + get :index, :content_view_id => @library_dev_staging_view + + assert_response :success + assert_template 'katello/api/v2/content_view_histories/index' + end + + def test_index_protected + allowed_perms = [@view_permission] + denied_perms = [@create_permission, @update_permission, :destroy_content_views] + + assert_protected_action(:index, allowed_perms, denied_perms) do + get :index, :content_view_id => @library_dev_staging_view.id + end + end + end +end diff --git a/test/controllers/api/v2/content_views_controller_test.rb b/test/controllers/api/v2/content_views_controller_test.rb index fb2d4ccf324..2997e5d34f1 100644 --- a/test/controllers/api/v2/content_views_controller_test.rb +++ b/test/controllers/api/v2/content_views_controller_test.rb @@ -25,9 +25,6 @@ def permissions def setup setup_controller_defaults_api - @request.env['HTTP_ACCEPT'] = 'application/json' - @request.env['CONTENT_TYPE'] = 'application/json' - @fake_search_service = @controller.load_search_service(Support::SearchService::FakeSearchService.new) ContentView.any_instance.stubs(:reindex_on_association_change).returns(true) ContentViewVersion.any_instance.stubs(:package_count).returns(0) ContentViewVersion.any_instance.stubs(:errata_count).returns(0) @@ -158,22 +155,6 @@ def test_update_components assert_template %w(katello/api/v2/common/update katello/api/v2/layouts/resource) end - def test_history - get :history, :id => @library_dev_staging_view - - assert_response :success - assert_template 'katello/api/v2/content_views/../content_view_histories/index' - end - - def test_history_protected - allowed_perms = [@view_permission] - denied_perms = [@create_permission, @update_permission, :destroy_content_views] - - assert_protected_action(:history, allowed_perms, denied_perms) do - get :history, :id => @library_dev_staging_view.id - end - end - def test_update_protected allowed_perms = [@update_permission] denied_perms = [@view_permission, @create_permission, :destroy_content_views] @@ -200,8 +181,6 @@ def test_available_puppet_modules_protected end def test_available_puppet_module_names - Support::SearchService::FakeSearchService.any_instance.stubs(:facets).returns('facet_search' => {'terms' => []}) - get :available_puppet_module_names, :id => @library_dev_staging_view.id assert_response :success