Last active
December 30, 2015 20:29
-
-
Save thomasmckay/7881429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_filter :find_system_group, :only => [:index] | |
before_filter :find_organization, :only => [:index] | |
before_filter :authorize | |
def rules | |
index_systems = lambda do | |
if @system_group | |
@system_group && @system_group.readable? | |
else | |
@organization && System.any_readable?(@organization) | |
end | |
end | |
{ | |
:index => index_systems | |
} | |
end | |
api :GET, "/environments/:environment_id/consumers", "List systems (compatibilty)" | |
api :GET, "/environments/:environment_id/systems", "List systems in environment" | |
api :GET, "/organizations/:organization_id/systems", "List systems in organization" | |
api :GET, "/system_groups/:system_group_id/systems", "List systems in organization" | |
api :GET, "/systems", "List systems" | |
param :name, String, :desc => "Filter systems by name" | |
param :pool_id, String, :desc => "Filter systems by subscribed pool" | |
param :search, String, :desc => "Filter systems by advanced search query" | |
param :uuid, String, :desc => "Filter systems by uuid" | |
param :organization_id, String, :desc => "specify the organization", :required => true | |
param :environment_id, String, :desc => "specify the environment" | |
def index | |
query_string = params[:name] ? "name:#{params[:name]}" : params[:search] | |
filters = [] | |
if params[:environment_id] | |
find_environment | |
filters << {:terms => {:environment_id => [params[:environment_id]] }} | |
elsif params[:system_group_id] | |
find_system_group | |
filters << {:terms => {:system_group_ids => [params[:system_group_id]] }} | |
else | |
filters << {:terms => {:environment_id => KTEnvironment.systems_readable(@organization).collect { |item| item.id } }} | |
end | |
filters << {:terms => {:uuid => System.all_by_pool_uuid(params['pool_id']) }} if params['pool_id'] | |
filters << {:terms => {:uuid => [params['uuid']] }} if params['uuid'] | |
options = { | |
:filters => filters, | |
:load_records? => true | |
} | |
respond_for_index(:collection => item_search(System, params, options)) | |
end | |
def find_system_group | |
if params[:system_group_id] | |
@system_group = SystemGroup.find(params[:system_group_id]) | |
fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:id] if @system_group.nil? | |
end | |
end | |
def find_environment | |
if params[:environment_id] | |
@environment = KTEnvironment.find(params[:environment_id]) | |
fail HttpErrors::NotFound, _("Couldn't find content environment '%s'") % params[:id] if @environment.nil? | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment