2014-12-28 10:55:50 -08:00
|
|
|
class Ajax::ReportController < ApplicationController
|
|
|
|
def create
|
|
|
|
params.require :id
|
|
|
|
params.require :type
|
|
|
|
|
|
|
|
@status = :err
|
|
|
|
@success = false
|
|
|
|
|
|
|
|
if current_user.nil?
|
|
|
|
@message = "login required"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless %w(answer comment question user).include? params[:type]
|
|
|
|
@message = "unknown type"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-12-28 16:47:04 -08:00
|
|
|
object = if params[:type] == 'user'
|
|
|
|
User.find_by_screen_name params[:id]
|
|
|
|
else
|
|
|
|
params[:type].strip.capitalize.constantize.find params[:id]
|
|
|
|
end
|
|
|
|
|
2014-12-28 10:55:50 -08:00
|
|
|
if object.nil?
|
|
|
|
@message = "Could not find #{params[:type]}"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-04-21 19:59:10 -07:00
|
|
|
current_user.report object, params[:reason]
|
2014-12-28 10:55:50 -08:00
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@message = "#{params[:type].capitalize} reported. A moderator will decide what happens with the #{params[:type]}."
|
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
end
|