Skip to content

Commit

Permalink
Refs #11754 - moves content view history to scoped search
Browse files Browse the repository at this point in the history
  • Loading branch information
cfouant committed Nov 5, 2015
1 parent 53cace6 commit 4e5ed28
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 76 deletions.
@@ -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
13 changes: 0 additions & 13 deletions app/controllers/katello/api/v2/content_views_controller.rb
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/content_view_history.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 0 additions & 31 deletions app/models/katello/glue/elastic_search/content_view_history.rb

This file was deleted.

6 changes: 5 additions & 1 deletion config/routes/api/v2.rb
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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;
Expand Down
@@ -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'}}
}
);
}]
);
3 changes: 2 additions & 1 deletion lib/katello/permissions/content_view_permissions.rb
Expand Up @@ -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],
Expand Down
38 changes: 38 additions & 0 deletions 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
21 changes: 0 additions & 21 deletions test/controllers/api/v2/content_views_controller_test.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 4e5ed28

Please sign in to comment.