rosa-build/app/controllers/api/v1/platforms_controller.rb

76 lines
1.9 KiB
Ruby
Raw Normal View History

class Api::V1::PlatformsController < Api::V1::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => :allowed
skip_before_filter :authenticate_user!, :only => [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
2013-06-26 13:07:55 +01:00
load_and_authorize_resource :except => :allowed
def allowed
if Platform.allowed?(params[:path] || '', request)
render :nothing => true
else
render :nothing => true, :status => 403
end
end
def index
2012-10-04 14:34:30 +01:00
@platforms = @platforms.accessible_by(current_ability, :related).
by_type(params[:type]).paginate(paginate_params)
end
def show
end
def platforms_for_build
@platforms = Platform.main.opened.paginate(paginate_params)
render :index
end
def create
platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first
@platform.owner = owner || get_owner
2012-10-16 13:35:30 +01:00
create_subject @platform
end
def update
2012-10-10 17:31:22 +01:00
platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first
platform_params[:owner] = owner if owner
2012-10-14 13:39:58 +01:00
update_subject @platform
end
def members
@members = @platform.members.order('name').paginate(paginate_params)
end
def add_member
2012-10-14 13:39:58 +01:00
add_member_to_subject @platform
end
def remove_member
2012-10-14 13:39:58 +01:00
remove_member_from_subject @platform
end
def clone
2012-10-10 17:31:22 +01:00
platform_params = params[:platform] || {}
platform_params[:owner] = current_user
@cloned = @platform.full_clone(platform_params)
if @cloned.persisted?
2012-10-11 16:36:14 +01:00
render_json_response @platform, 'Platform has been cloned successfully'
else
2012-10-11 16:36:14 +01:00
render_validation_error @platform, 'Platform has not been cloned'
end
end
def clear
@platform.clear
2012-10-11 16:36:14 +01:00
render_json_response @platform, 'Platform has been cleared successfully'
end
def destroy
2012-10-14 13:39:58 +01:00
destroy_subject @platform
end
end