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

95 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

class Api::V1::PlatformsController < Api::V1::BaseController
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
skip_before_action :check_auth, only: :allowed if APP_CONFIG['anonymous_access']
skip_before_action :check_auth, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
2015-03-04 23:19:19 +00:00
skip_before_action :authenticate_user!, only: :allowed
skip_before_action :authenticate_user!, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
before_action :load_platform, except: [:index, :allowed, :platforms_for_build, :create]
def allowed
authorize :platform
2014-04-08 22:07:50 +01:00
if request.authorization.present?
token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
end
if Platform.allowed?(params[:path] || '', token)
2014-01-21 04:51:49 +00:00
render nothing: true
else
2014-01-21 04:51:49 +00:00
render nothing: true, status: 403
end
end
def index
2015-03-26 00:26:24 +00:00
authorize :platform
@platforms = PlatformPolicy::Scope.new(current_user, Platform).show.
2015-03-26 00:26:24 +00:00
by_type(params[:type]).paginate(paginate_params)
end
def show
end
def platforms_for_build
authorize :platform
2015-03-26 00:26:24 +00:00
@platforms = Platform.availables_main_platforms(current_user).paginate(paginate_params)
render :index
end
def create
pp = params[:platform] || {}
owner = User.find_by(id: pp[:owner_id])
@platform = Platform.new(platform_params)
@platform.owner = owner || get_owner
2012-10-16 13:35:30 +01:00
create_subject @platform
end
def update
pp = params[:platform] || {}
owner = User.find_by(id: pp[:owner_id])
pp[: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
2015-03-26 00:26:24 +00:00
private
def platform_params
subject_params(Platform)
end
2015-03-26 00:26:24 +00:00
# Private: before_action hook which loads Platform.
def load_platform
authorize @platform = Platform.find(params[:id])
end
end