Class: Mutations::AnsibleVariableOverrides::Delete

Inherits:
DeleteMutation
  • Object
show all
Defined in:
app/graphql/mutations/ansible_variable_overrides/delete.rb

Instance Method Summary collapse

Instance Method Details

#resolve(id:, host_id:, variable_id:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/graphql/mutations/ansible_variable_overrides/delete.rb', line 14

def resolve(id:, host_id:, variable_id:)
  host = Host.find_by :id => host_id
  variable = AnsibleVariable.find_by :id => variable_id
  return resource_not_found(_('Host not found by id: %s'), host_id) unless host
  return resource_not_found(_('Ansible Variable not found by id: %s'), variable_id) unless variable
  authorize!(host, :view)
  authorize!(variable, :edit)

  result = super id: id
  resolver = ::ForemanAnsible::OverrideResolver.new(host, [variable.id])
  result.merge :overriden_ansible_variable => ::Presenters::OverridenAnsibleVariablePresenter.new(variable, resolver)
end

#resource_not_found(message) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/graphql/mutations/ansible_variable_overrides/delete.rb', line 27

def resource_not_found(message)
  {
    :overriden_ansible_variable => nil,
    :errros => [{
      :path => ['base'],
      :message => message
    }]
  }
end