mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 18:29:52 +01:00
9fc3e535d2
Co-authored-by: Karina Kwiatek <6197148+raccube@users.noreply.github.com>
45 lines
1 KiB
Ruby
45 lines
1 KiB
Ruby
class Ajax::ReportController < AjaxController
|
|
def create
|
|
params.require :id
|
|
params.require :type
|
|
|
|
@response[:status] = :err
|
|
|
|
unless user_signed_in?
|
|
@response[:status] = :noauth
|
|
@response[:message] = t(".noauth")
|
|
return
|
|
end
|
|
|
|
unless %w(answer comment question user).include? params[:type]
|
|
@response[:message] = t(".unknown")
|
|
return
|
|
end
|
|
|
|
obj = params[:type].strip.capitalize
|
|
|
|
object = case obj
|
|
when 'User'
|
|
User.find_by_screen_name! params[:id]
|
|
when 'Question'
|
|
Question.find params[:id]
|
|
when 'Answer'
|
|
Answer.find params[:id]
|
|
when 'Comment'
|
|
Comment.find params[:id]
|
|
else
|
|
Answer.find params[:id]
|
|
end
|
|
|
|
if object.nil?
|
|
@response[:message] = t(".notfound", parameter: params[:type])
|
|
return
|
|
end
|
|
|
|
current_user.report object, params[:reason]
|
|
|
|
@response[:status] = :okay
|
|
@response[:message] = t(".success", parameter: params[:type].titleize)
|
|
@response[:success] = true
|
|
end
|
|
end
|