Project

General

Profile

« Previous | Next » 

Revision 453dc693

Added by Joseph Magen over 9 years ago

fixes #3492 - API v2 nested routes for each controller

View differences:

app/controllers/api/v2/hosts_controller.rb
wrap_parameters :host, :include => (Host::Base.attribute_names + ['image_file', 'is_owned_by', 'overwrite', 'progress_report_id'])
include Api::Version2
#TODO - should TaxonomyScope be here. It wasn't here previously
include Api::TaxonomyScope
include Foreman::Controller::SmartProxyAuth
before_filter :find_resource, :except => %w{index create facts}
before_filter :find_optional_nested_object, :except => [:facts]
before_filter :find_resource, :except => [:index, :create, :facts]
before_filter :permissions_check, :only => %w{power boot puppetrun}
add_puppetmaster_filters :facts
api :GET, "/hosts/", N_("List all hosts")
api :GET, "/hostgroups/:hostgroup_id/hosts", N_("List all hosts for a host group")
api :GET, "/locations/:location_id/hosts", N_("List hosts per location")
api :GET, "/organizations/:organization_id/hosts", N_("List hosts per organization")
api :GET, "/environments/:environment_id/hosts", N_("List hosts per environment")
param :hostgroup_id, String, :desc => N_("ID of host group")
param :location_id, String, :desc => N_("ID of location")
param :organization_id, String, :desc => N_("ID of organization")
param :environment_id, String, :desc => N_("ID of environment")
param_group :search_and_pagination, ::Api::V2::BaseController
def index
@hosts = resource_scope.search_for(*search_options).paginate(paginate_options)
@hosts = resource_scope_for_index
end
api :GET, "/hosts/:id/", N_("Show a host")
......
private
def resource_scope(controller = controller_name)
Host.authorized("#{action_permission}_#{controller}", Host)
end
def action_permission
case params[:action]
when 'puppetrun'
......
deny_access unless Host.authorized(permission).find(@host.id)
end
private
def resource_class
Host::Managed
end
def allowed_nested_id
%w(hostgroup_id location_id organization_id environment_id)
end
end
end
end

Also available in: Unified diff