Class: ForemanSalt::SaltModulesController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Concerns::SaltModuleParameters, StateImporter
Defined in:
app/controllers/foreman_salt/salt_modules_controller.rb

Instance Method Summary collapse

Methods included from Concerns::SaltModuleParameters

#salt_module_params

Methods inherited from ApplicationController

#resource_class

Instance Method Details

#action_permissionObject



49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 49

def action_permission
  case params[:action]
  when 'import'
    :import
  when 'apply_changes'
    :import
  else
    super
  end
end

#apply_changesObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 70

def apply_changes
  if params[:changed].blank?
    info _('No changes found')
  else
    params[:changed].each do |environment, states|
      next unless states[:add] || states[:remove]

      add_to_environment(JSON.parse(states[:add]), environment) if states[:add]
      remove_from_environment(JSON.parse(states[:remove]), environment) if states[:remove]
    end

    clean_orphans
    success _('Successfully imported')
  end
  redirect_to salt_modules_path
end

#createObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 18

def create
  logger.info("Params: #{params.inspect}")
  @salt_module = SaltModule.new(salt_module_params)
  if @salt_module.save
    process_success
  else
    process_error
  end
end

#destroyObject



41
42
43
44
45
46
47
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 41

def destroy
  if @salt_module.destroy
    process_success
  else
    process_error
  end
end

#editObject



28
29
30
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 28

def edit
  @salt_environments = @salt_module.salt_environments
end

#importObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 60

def import
  result = fetch_states_from_proxy(@proxy)
  @changes = result[:changes]
  @deletes = result[:deletes]

  return unless @changes.empty?
  info _('No changes found')
  redirect_to salt_modules_path
end

#indexObject



10
11
12
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 10

def index
  @salt_modules = resource_base.search_for(params[:search], order: params[:order]).includes(:salt_environments).paginate(page: params[:page])
end

#newObject



14
15
16
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 14

def new
  @salt_module = SaltModule.new
end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/foreman_salt/salt_modules_controller.rb', line 32

def update
  if @salt_module.update(salt_module_params)
    success _("Successfully updated #{@salt_module}.")
    redirect_to salt_modules_path
  else
    process_error
  end
end