2014-12-28 10:55:50 -08:00
|
|
|
class Ajax::ReportController < ApplicationController
|
2015-05-08 16:31:31 -07:00
|
|
|
rescue_from(ActionController::ParameterMissing) do |param_miss_ex|
|
|
|
|
@status = :parameter_error
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize)
|
2015-05-08 16:31:31 -07:00
|
|
|
@success = false
|
|
|
|
render partial: "ajax/shared/status"
|
|
|
|
end
|
2015-09-01 06:14:31 -07:00
|
|
|
|
2014-12-28 10:55:50 -08:00
|
|
|
def create
|
|
|
|
params.require :id
|
|
|
|
params.require :type
|
|
|
|
|
|
|
|
@status = :err
|
|
|
|
@success = false
|
|
|
|
|
|
|
|
if current_user.nil?
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.report.create.login')
|
2014-12-28 10:55:50 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless %w(answer comment question user).include? params[:type]
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.report.create.unknown')
|
2014-12-28 10:55:50 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-09-01 06:14:31 -07:00
|
|
|
obj = params[:type].strip.capitalize
|
|
|
|
|
2015-09-18 02:08:08 -07:00
|
|
|
object = case obj
|
2015-09-01 06:14:31 -07:00
|
|
|
when 'User'
|
|
|
|
User.find_by_screen_name params[:id]
|
|
|
|
when 'Question'
|
2015-09-18 02:09:26 -07:00
|
|
|
Question.find params[:id]
|
2015-09-01 06:14:31 -07:00
|
|
|
when 'Answer'
|
2015-09-18 02:09:26 -07:00
|
|
|
Answer.find params[:id]
|
2015-09-01 06:14:31 -07:00
|
|
|
when 'Comment'
|
2015-09-18 02:09:26 -07:00
|
|
|
Comment.find params[:id]
|
2015-09-01 06:14:31 -07:00
|
|
|
else
|
2015-09-18 02:09:26 -07:00
|
|
|
Answer.find params[:id]
|
2015-09-01 06:14:31 -07:00
|
|
|
end
|
2014-12-28 16:47:04 -08:00
|
|
|
|
2014-12-28 10:55:50 -08:00
|
|
|
if object.nil?
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.report.create.not_found', parameter: params[:type])
|
2014-12-28 10:55:50 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-09-18 02:09:26 -07:00
|
|
|
current_user.report object, params[:reason]
|
2014-12-28 10:55:50 -08:00
|
|
|
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.report.create.okay', parameter: params[:type])
|
2014-12-28 10:55:50 -08:00
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
end
|