Sha256: 8d9406dda8649d7e72c1af7d6a85145ec679d16a65cbedfd1a195c75b86dff6a

Contents?: true

Size: 1.07 KB

Versions: 25

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module ForemanAnsible
  module Concerns
    # Shared task methods between api controllers
    module ApiCommon
      extend ActiveSupport::Concern

      def find_ansible_roles
        ids = params.fetch(:ansible_role_ids, []) || []
        @ansible_roles = AnsibleRole.authorized(:view_ansible_roles).find(ids)
      rescue ActiveRecord::RecordNotFound => e
        not_found(e.message)
      end

      def find_ansible_role
        @ansible_role = AnsibleRole.authorized(:view_ansible_roles).find(params[:ansible_role_id])
      rescue ActiveRecord::RecordNotFound => e
        not_found(e.message)
      end

      def find_host_ansible_role
        find_ansible_role
        @host = Host.authorized(:view_hosts).find(params[:id])
      rescue ActiveRecord::RecordNotFound => e
        not_found(e.message)
      end

      def find_hostgroup_ansible_role
        find_ansible_role
        @hostgroup = Hostgroup.authorized(:view_hostgroups).find(params[:id])
      rescue ActiveRecord::RecordNotFound => e
        not_found(e.message)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-15.0.1 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-15.0.0 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.2.2 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.2.1 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.7 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.2.0 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.1.1 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.1.0 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.5 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-14.0.0 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.4 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.3 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.2 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.1 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-13.0.0 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-12.0.7 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-12.0.6 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-12.0.5 app/controllers/foreman_ansible/concerns/api_common.rb
foreman_ansible-12.0.4 app/controllers/foreman_ansible/concerns/api_common.rb