2020-04-28 11:27:59 -07:00
|
|
|
class Ajax::ReportController < AjaxController
|
2014-12-28 10:55:50 -08:00
|
|
|
def create
|
|
|
|
params.require :id
|
|
|
|
params.require :type
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2014-12-28 10:55:50 -08:00
|
|
|
|
2022-07-06 03:41:48 -07:00
|
|
|
unless user_signed_in?
|
|
|
|
@response[:status] = :noauth
|
|
|
|
@response[:message] = t(".noauth")
|
2014-12-28 10:55:50 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless %w(answer comment question user).include? params[:type]
|
2022-07-06 03:41:48 -07:00
|
|
|
@response[:message] = t(".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'
|
2020-05-01 00:57:44 -07:00
|
|
|
User.find_by_screen_name! params[:id]
|
2015-09-01 06:14:31 -07:00
|
|
|
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?
|
2022-07-06 03:41:48 -07:00
|
|
|
@response[:message] = t(".notfound", parameter: params[:type])
|
2014-12-28 10:55:50 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-01-23 11:42:16 -08:00
|
|
|
current_user.report object, params[:reason]
|
2014-12-28 10:55:50 -08:00
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
2022-07-06 12:47:53 -07:00
|
|
|
@response[:message] = t(".success", parameter: params[:type].titleize)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:success] = true
|
2014-12-28 10:55:50 -08:00
|
|
|
end
|
|
|
|
end
|