2012-09-27 13:13:59 +01:00
|
|
|
class Api::V1::PlatformsController < Api::V1::BaseController
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
2016-03-24 15:59:12 +00:00
|
|
|
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']
|
2015-03-26 22:33:40 +00:00
|
|
|
before_action :load_platform, except: [:index, :allowed, :platforms_for_build, :create]
|
2013-06-26 13:04:06 +01:00
|
|
|
|
|
|
|
def allowed
|
2015-03-26 22:33:40 +00:00
|
|
|
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
|
2013-06-26 13:04:06 +01:00
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
render nothing: true, status: 403
|
2013-06-26 13:04:06 +01:00
|
|
|
end
|
|
|
|
end
|
2012-08-17 14:40:57 +01:00
|
|
|
|
|
|
|
def index
|
2015-03-26 00:26:24 +00:00
|
|
|
authorize :platform
|
2015-03-26 22:33:40 +00:00
|
|
|
@platforms = PlatformPolicy::Scope.new(current_user, Platform).show.
|
2015-03-26 00:26:24 +00:00
|
|
|
by_type(params[:type]).paginate(paginate_params)
|
2012-08-17 14:40:57 +01:00
|
|
|
end
|
2012-09-26 18:15:11 +01:00
|
|
|
|
|
|
|
def show
|
2012-10-08 19:02:44 +01:00
|
|
|
end
|
2012-09-26 18:15:11 +01:00
|
|
|
|
2012-10-08 19:02:44 +01:00
|
|
|
def platforms_for_build
|
2015-03-26 22:33:40 +00:00
|
|
|
authorize :platform
|
2015-03-26 00:26:24 +00:00
|
|
|
@platforms = Platform.availables_main_platforms(current_user).paginate(paginate_params)
|
|
|
|
render :index
|
2012-09-26 18:15:11 +01:00
|
|
|
end
|
2012-10-09 15:46:20 +01:00
|
|
|
|
2012-10-10 18:45:56 +01:00
|
|
|
def create
|
2015-05-19 21:26:38 +01:00
|
|
|
pp = params[:platform] || {}
|
|
|
|
owner = User.find_by(id: pp[:owner_id])
|
|
|
|
@platform = Platform.new(platform_params)
|
2012-10-10 18:45:56 +01:00
|
|
|
@platform.owner = owner || get_owner
|
2012-10-16 13:35:30 +01:00
|
|
|
create_subject @platform
|
2012-10-10 18:45:56 +01:00
|
|
|
end
|
|
|
|
|
2012-10-09 15:46:20 +01:00
|
|
|
def update
|
2015-05-19 21:26:38 +01:00
|
|
|
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
|
2012-10-09 15:46:20 +01:00
|
|
|
end
|
|
|
|
|
2012-10-09 16:06:27 +01:00
|
|
|
def members
|
|
|
|
@members = @platform.members.order('name').paginate(paginate_params)
|
|
|
|
end
|
|
|
|
|
2012-10-09 17:23:48 +01:00
|
|
|
def add_member
|
2012-10-14 13:39:58 +01:00
|
|
|
add_member_to_subject @platform
|
2012-10-09 17:23:48 +01:00
|
|
|
end
|
|
|
|
|
2012-10-09 18:07:10 +01:00
|
|
|
def remove_member
|
2012-10-14 13:39:58 +01:00
|
|
|
remove_member_from_subject @platform
|
2012-10-09 18:07:10 +01:00
|
|
|
end
|
|
|
|
|
2012-10-10 16:13:14 +01:00
|
|
|
def clone
|
2012-10-10 17:31:22 +01:00
|
|
|
platform_params = params[:platform] || {}
|
|
|
|
platform_params[:owner] = current_user
|
2012-10-10 16:13:14 +01:00
|
|
|
@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'
|
2012-10-10 16:13:14 +01:00
|
|
|
else
|
2012-10-11 16:36:14 +01:00
|
|
|
render_validation_error @platform, 'Platform has not been cloned'
|
2012-10-10 16:13:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear
|
|
|
|
@platform.clear
|
2012-10-11 16:36:14 +01:00
|
|
|
render_json_response @platform, 'Platform has been cleared successfully'
|
2012-10-10 16:13:14 +01:00
|
|
|
end
|
|
|
|
|
2012-10-10 16:43:14 +01:00
|
|
|
def destroy
|
2012-10-14 13:39:58 +01:00
|
|
|
destroy_subject @platform
|
2012-10-10 16:43:14 +01:00
|
|
|
end
|
|
|
|
|
2015-03-26 00:26:24 +00:00
|
|
|
private
|
|
|
|
|
2015-05-19 21:26:38 +01:00
|
|
|
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
|
|
|
|
|
2012-08-17 14:40:57 +01:00
|
|
|
end
|