#671: removed before_filter
This commit is contained in:
parent
992892f2c8
commit
6b3bf41c7a
|
@ -17,23 +17,23 @@ class Api::V1::BaseController < ApplicationController
|
||||||
{:page => params[:page], :per_page => per_page}
|
{:page => params[:page], :per_page => per_page}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_json_response(message, status = 200)
|
def render_json_response(subject, message, status = 200)
|
||||||
id = status != 200 ? nil : @subject.id
|
id = status != 200 ? nil : subject.id
|
||||||
|
|
||||||
render :json => {
|
render :json => {
|
||||||
@subject.class.name.downcase.to_sym => {
|
subject.class.name.downcase.to_sym => {
|
||||||
:id => id,
|
:id => id,
|
||||||
:message => message
|
:message => message
|
||||||
}
|
}
|
||||||
}.to_json, :status => status
|
}.to_json, :status => status
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_validation_error(message)
|
def render_validation_error(subject, message)
|
||||||
errors = @subject.errors.full_messages.join('. ')
|
errors = subject.errors.full_messages.join('. ')
|
||||||
if errors.present?
|
if errors.present?
|
||||||
message << '. ' << errors
|
message << '. ' << errors
|
||||||
end
|
end
|
||||||
render_json_response(message, 422)
|
render_json_response(subject, message, 422)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,6 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
skip_before_filter :authenticate_user!, :only => [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
|
skip_before_filter :authenticate_user!, :only => [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
before_filter :set_subject, :except => [:index, :platforms_for_build, :show, :members]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@platforms = @platforms.accessible_by(current_ability, :related).
|
@platforms = @platforms.accessible_by(current_ability, :related).
|
||||||
|
@ -24,9 +23,9 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
owner = User.where(:id => platform_params[:owner_id]).first
|
owner = User.where(:id => platform_params[:owner_id]).first
|
||||||
@platform.owner = owner || get_owner
|
@platform.owner = owner || get_owner
|
||||||
if @platform.save
|
if @platform.save
|
||||||
render_json_response 'Platform has been created successfully'
|
render_json_response @platform, 'Platform has been created successfully'
|
||||||
else
|
else
|
||||||
render_validation_error 'Platform has not been created'
|
render_validation_error @platform, 'Platform has not been created'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,9 +34,9 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
owner = User.where(:id => platform_params[:owner_id]).first
|
owner = User.where(:id => platform_params[:owner_id]).first
|
||||||
platform_params[:owner] = owner if owner
|
platform_params[:owner] = owner if owner
|
||||||
if @platform.update_attributes(platform_params)
|
if @platform.update_attributes(platform_params)
|
||||||
render_json_response 'Platform has been updated successfully'
|
render_json_response @platform, 'Platform has been updated successfully'
|
||||||
else
|
else
|
||||||
render_validation_error 'Platform has not been updated'
|
render_validation_error @platform, 'Platform has not been updated'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,17 +46,17 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
|
|
||||||
def add_member
|
def add_member
|
||||||
if member.present? && @platform.add_member(member)
|
if member.present? && @platform.add_member(member)
|
||||||
render_json_response "#{member.class.to_s} '#{member.id}' has been added to platform successfully"
|
render_json_response @platform, "#{member.class.to_s} '#{member.id}' has been added to platform successfully"
|
||||||
else
|
else
|
||||||
render_validation_error 'Member has not been added to platform'
|
render_validation_error @platform, 'Member has not been added to platform'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_member
|
def remove_member
|
||||||
if member.present? && @platform.remove_member(member)
|
if member.present? && @platform.remove_member(member)
|
||||||
render_json_response "#{member.class.to_s} '#{member.id}' has been removed from platform successfully"
|
render_json_response @platform, "#{member.class.to_s} '#{member.id}' has been removed from platform successfully"
|
||||||
else
|
else
|
||||||
render_validation_error 'Member has not been removed from platform'
|
render_validation_error @platform, 'Member has not been removed from platform'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,20 +65,20 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
platform_params[:owner] = current_user
|
platform_params[:owner] = current_user
|
||||||
@cloned = @platform.full_clone(platform_params)
|
@cloned = @platform.full_clone(platform_params)
|
||||||
if @cloned.persisted?
|
if @cloned.persisted?
|
||||||
render_json_response 'Platform has been cloned successfully'
|
render_json_response @platform, 'Platform has been cloned successfully'
|
||||||
else
|
else
|
||||||
render_validation_error 'Platform has not been cloned'
|
render_validation_error @platform, 'Platform has not been cloned'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@platform.clear
|
@platform.clear
|
||||||
render_json_response 'Platform has been cleared successfully'
|
render_json_response @platform, 'Platform has been cleared successfully'
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@platform.destroy # later with resque
|
@platform.destroy # later with resque
|
||||||
render_json_response 'Platform has been destroyed successfully'
|
render_json_response @platform, 'Platform has been destroyed successfully'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -95,8 +94,4 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
@member ||= ''
|
@member ||= ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_subject
|
|
||||||
@subject = @platform
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue