Class: SccAccountsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SccAccountsController
- Includes:
- Foreman::Controller::AutoCompleteSearch
- Defined in:
- app/controllers/scc_accounts_controller.rb
Instance Method Summary collapse
- #bulk_subscribe ⇒ Object
-
#create ⇒ Object
POST /scc_accounts.
- #create_nested_product_tree(scc_products, subscribed_only:) ⇒ Object
-
#destroy ⇒ Object
DELETE /scc_accounts/1.
-
#edit ⇒ Object
GET /scc_accounts/1/edit.
- #get_product_tree_hash(scc_product_base) ⇒ Object
-
#index ⇒ Object
GET /scc_accounts.
-
#new ⇒ Object
GET /scc_accounts/new.
- #scc_product_hash(scc_product) ⇒ Object
-
#sync ⇒ Object
PUT /scc_accounts/1/sync.
-
#test_connection ⇒ Object
POST /scc_accounts/test_connection.
-
#update ⇒ Object
PATCH/PUT /scc_accounts/1.
Instance Method Details
#bulk_subscribe ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/scc_accounts_controller.rb', line 82 def bulk_subscribe scc_products_to_subscribe = @scc_account.scc_products.where(id: scc_bulk_subscribe_params[:scc_subscribe_product_ids]) if scc_products_to_subscribe.count > 0 ForemanTasks.async_task(::Actions::BulkAction, ::Actions::SccManager::SubscribeProduct, scc_products_to_subscribe) success _('Task to subscribe products started.') else warning _('No products selected.') end rescue ::Foreman::Exception => e error _('Failed to add task to queue: %s') % e.to_s rescue ForemanTasks::Lock::LockConflict => e error _('Lock on SCC account already taken: %s') % e.to_s ensure redirect_to scc_accounts_path end |
#create ⇒ Object
POST /scc_accounts
27 28 29 30 31 32 33 |
# File 'app/controllers/scc_accounts_controller.rb', line 27 def create @scc_account = SccAccount.new(scc_account_params) @scc_account.save_with_logic! process_success rescue ActiveRecord::RecordInvalid process_error end |
#create_nested_product_tree(scc_products, subscribed_only:) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/scc_accounts_controller.rb', line 102 def create_nested_product_tree(scc_products, subscribed_only:) if subscribed_only scc_products_base = scc_products.where(:product_type => 'base').where.not(:product_id => nil).includes([:scc_extensions]) else scc_products_base = scc_products.where(:product_type => 'base').includes([:scc_extensions]) end tree = [] scc_products_base.each do |p| tree.push(get_product_tree_hash(p)) end tree end |
#destroy ⇒ Object
DELETE /scc_accounts/1
61 62 63 64 65 66 67 |
# File 'app/controllers/scc_accounts_controller.rb', line 61 def destroy if @scc_account.destroy process_success else process_error end end |
#edit ⇒ Object
GET /scc_accounts/1/edit
36 37 |
# File 'app/controllers/scc_accounts_controller.rb', line 36 def edit end |
#get_product_tree_hash(scc_product_base) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/controllers/scc_accounts_controller.rb', line 139 def get_product_tree_hash(scc_product_base) if scc_product_base.scc_extensions.blank? scc_product_hash(scc_product_base) else children = [] scc_product_base.scc_extensions.each do |ext| children.push(get_product_tree_hash(ext)) end scc_product_base_hash = scc_product_hash(scc_product_base) scc_product_base_hash['children'] = children scc_product_base_hash end end |
#index ⇒ Object
GET /scc_accounts
10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/scc_accounts_controller.rb', line 10 def index @scc_accounts = resource_base.where(organization: @organization) .search_for(params[:search], order: params[:order]) .paginate(:page => params[:page], :per_page => params[:per_page]) # overwrite the product list with filtered products that do not include products with empty repositories @scc_accounts.each do |scc_account| scc_account.scc_products_with_repos_count = scc_account.scc_products.only_products_with_repos.count end end |
#new ⇒ Object
GET /scc_accounts/new
21 22 23 24 |
# File 'app/controllers/scc_accounts_controller.rb', line 21 def new @scc_account = SccAccount.new @scc_account.organization = @organization end |
#scc_product_hash(scc_product) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/scc_accounts_controller.rb', line 116 def scc_product_hash(scc_product) scc_product_json = scc_product.as_json(:only => [:scc_id, :id, :arch, :version, :product_id, :subscription_valid], :include => { :scc_repositories => { :only => [:id, :name, :subscription_valid] } }) .merge('name' => scc_product.pretty_name, 'product_category' => scc_product.product_category) # find if and which Katello root repository is associated with this SCC product repo_ids_katello = scc_product&.product&.root_repository_ids scc_product_json['scc_repositories'].each do |repo| if repo_ids_katello.blank? repo['katello_repository_id'] = nil else repo_ids_scc = scc_product.scc_repositories.find(repo['id']).katello_root_repository_ids if repo_ids_scc.blank? repo['katello_repository_id'] = nil else # we need to extract the library instance id for the correct repo link in the UI root_repo_id = (repo_ids_scc & repo_ids_katello).first repo['katello_repository_id'] = ::Katello::Repository.where({ root_id: root_repo_id, library_instance: nil }).pick(:id) end end end scc_product_json end |
#sync ⇒ Object
PUT /scc_accounts/1/sync
70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/scc_accounts_controller.rb', line 70 def sync sync_task = ForemanTasks.async_task(::Actions::SccManager::Sync, @scc_account) @scc_account.update! sync_task: sync_task success _('Sync task started.') rescue ::Foreman::Exception => e error _('Failed to add task to queue: %s') % e.to_s rescue ForemanTasks::Lock::LockConflict => e error _('Lock on SCC account already taken: %s') % e.to_s ensure redirect_to scc_accounts_path end |
#test_connection ⇒ Object
POST /scc_accounts/test_connection
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/scc_accounts_controller.rb', line 40 def test_connection @scc_account = SccAccount.new(scc_account_params) @scc_account.password = SccAccount.find(params[:scc_account_id]).password if params[:scc_account_id].present? && scc_account_params[:password].empty? respond_to do |format| if @scc_account.test_connection format.json { render json: nil, status: :ok } else format.json { render json: nil, status: :not_found } end end end |
#update ⇒ Object
PATCH/PUT /scc_accounts/1
53 54 55 56 57 58 |
# File 'app/controllers/scc_accounts_controller.rb', line 53 def update @scc_account.update_attributes_with_logic!(scc_account_params) process_success rescue ActiveRecord::RecordInvalid process_error end |