Sha256: 01dbaad22e72c491ae6f2ce5f3741bb3df0d597859382878dc3464b858183d39
Contents?: true
Size: 1.01 KB
Versions: 58
Compression:
Stored size: 1.01 KB
Contents
module Mutations module Hosts class AssignAnsibleRoles < ::Mutations::UpdateMutation resource_class Host::Managed argument :ansible_role_ids, [Integer], required: true field :host, Types::Host, 'The updated host.', null: false def resolve(id:, ansible_role_ids:) host = load_object_by(id: id) authorize!(host, :edit) existing = host.host_ansible_roles updated_ids = [] attrs = [] ansible_role_ids.each do |role_id| current = existing.find_by :ansible_role_id => role_id attrs << { :id => current&.id, :position => attrs.count + 1, :ansible_role_id => role_id } updated_ids << current.id if current end existing.where.not(:id => updated_ids).each do |item| attrs << { :id => item.id, :position => attrs.count + 1, :_destroy => true } end host.host_ansible_roles_attributes = attrs save_object(host) end def result_key :host end end end end
Version data entries
58 entries across 58 versions & 1 rubygems