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

83 lines
2.2 KiB
Ruby
Raw Normal View History

class Api::V1::PlatformsController < Api::V1::BaseController
before_filter :authenticate_user!
2014-01-21 04:51:49 +00:00
skip_before_filter :authenticate_user!, only: :allowed
2014-04-08 22:07:50 +01:00
skip_before_filter :authenticate_user!, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
load_and_authorize_resource except: :allowed
def allowed
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
2014-08-28 21:22:11 +01:00
@platforms = @platforms.accessible_by(current_ability, :related)
.by_type(params[:type]).paginate(paginate_params)
2014-08-28 21:46:42 +01:00
respond_to :json
end
def show
2014-08-28 21:46:42 +01:00
respond_to :json
end
def platforms_for_build
@platforms = Platform.availables_main_platforms(current_user, current_ability).paginate(paginate_params)
2014-08-28 21:22:11 +01:00
respond_to do |format|
format.json { render :index }
end
end
def create
platform_params = params[:platform] || {}
2014-01-21 04:51:49 +00:00
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] || {}
2014-01-21 04:51:49 +00:00
owner = User.where(id: platform_params[:owner_id]).first
2012-10-10 17:31:22 +01:00
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)
2014-08-28 21:46:42 +01:00
respond_to :json
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