Class: Katello::Api::V2::ContentViewsController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::Authorization::Api::V2::ContentViewsController, Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/content_views_controller.rb

Constant Summary

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

#full_result_response, #resource_class, #scoped_search

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#available_puppet_module_namesObject



110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 110

def available_puppet_module_names
  current_names = @view.content_view_puppet_modules.where("name is NOT NULL").pluck(:name)

  repos = @view.organization.library.puppet_repositories

  modules = PuppetModule.in_repositories(repos)
  modules = modules.where('name NOT in (?)', current_names) if current_names.present?

  respond_for_index :template => '../puppet_modules/names',
                    :collection => scoped_search(modules, 'name', 'ASC', :resource_class => PuppetModule, :group => :name)
end

#available_puppet_modulesObject



95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 95

def available_puppet_modules
  current_uuids = @view.content_view_puppet_modules.where("uuid is NOT NULL").pluck(:uuid)
  repositories = @view.organization.library.puppet_repositories

  query = PuppetModule.in_repositories(repositories)
  query = query.where(:name => params[:name]) if params[:name]
  query = query.where("#{PuppetModule.table_name}.uuid NOT in (?)", current_uuids) if current_uuids.present?

  respond_for_index :template => 'puppet_modules',
                    :collection => scoped_search(query, 'name', 'ASC', :resource_class => PuppetModule)
end

#copyObject



176
177
178
179
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 176

def copy
  new_content_view = @view.copy(params[:content_view][:name])
  respond_for_create :resource => new_content_view
end

#createObject



59
60
61
62
63
64
65
66
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 59

def create
  @view = ContentView.create!(view_params) do |view|
    view.organization = @organization
    view.label ||= labelize_params(params[:content_view])
  end

  respond :resource => @view
end

#destroyObject



168
169
170
171
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 168

def destroy
  task = async_task(::Actions::Katello::ContentView::Destroy, @view)
  respond_for_async :resource => task
end

#indexObject



33
34
35
36
37
38
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 33

def index
  content_view_includes = [:activation_keys, :content_view_puppet_modules, :content_view_versions,
                           :environments, :organization, :repositories, components: [:content_view, :environments]]

  respond(:collection => scoped_search(index_relation.uniq, :name, :desc, :includes => content_view_includes))
end

#index_relationObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 40

def index_relation
  content_views = ContentView.readable
  content_views = content_views.where(:organization_id => @organization.id) if @organization
  content_views = content_views.in_environment(@environment) if @environment
  content_views = content_views.non_default if params[:nondefault]
  content_views = content_views.non_composite if params[:noncomposite]
  content_views = content_views.composite if params[:composite]
  content_views = content_views.where(:name => params[:name]) if params[:name]
  content_views = content_views.where("#{ContentView.table_name}.id NOT IN (?)", params[:without]) if params[:without]
  content_views
end

#publishObject



80
81
82
83
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 80

def publish
  task = async_task(::Actions::Katello::ContentView::Publish, @view, params[:description])
  respond_for_async :resource => task
end

#removeObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 143

def remove
  cv_envs = ContentViewEnvironment.where(:environment_id => params[:environment_ids],
                                         :content_view_id => params[:id]
                                        )
  versions = @view.versions.where(:id => params[:content_view_version_ids])

  if cv_envs.empty? && versions.empty?
    fail _("There either were no environments nor versions specified or there were invalid environments/versions specified. "\
           "Please check environment_ids and content_view_version_ids parameters.")
  end

  options = params.slice(:system_content_view_id,
                         :system_environment_id,
                         :key_content_view_id,
                         :key_environment_id
                        ).reject { |_k, v| v.nil? }
  options[:content_view_versions] = versions
  options[:content_view_environments] = cv_envs

  task = async_task(::Actions::Katello::ContentView::Remove, @view, options)
  respond_for_async :resource => task
end

#remove_from_environmentObject



125
126
127
128
129
130
131
132
133
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 125

def remove_from_environment
  unless @view.environments.include?(@environment)
    fail HttpErrors::BadRequest, _("Content view '%{view}' is not in lifecycle environment '%{env}'.") %
          {view: @view.name, env: @environment.name}
  end

  task = async_task(::Actions::Katello::ContentView::RemoveFromEnvironment, @view, @environment)
  respond_for_async :resource => task
end

#showObject



87
88
89
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 87

def show
  respond :resource => @view
end

#updateObject



72
73
74
75
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 72

def update
  sync_task(::Actions::Katello::ContentView::Update, @view, view_params)
  respond :resource => @view.reload
end