2014-12-28 14:26:16 -08:00
|
|
|
class Ajax::ModerationController < 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:50 -07:00
|
|
|
|
2014-12-28 14:26:16 -08:00
|
|
|
def vote
|
|
|
|
params.require :id
|
|
|
|
params.require :upvote
|
|
|
|
|
|
|
|
report = Report.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.report_vote(report, params[:upvote])
|
|
|
|
rescue
|
|
|
|
@status = :fail
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.vote.fail')
|
2014-12-28 14:26:16 -08:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@count = report.votes
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.vote.okay')
|
2014-12-28 14:26:16 -08:00
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_vote
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
report = Report.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.report_unvote report
|
|
|
|
rescue
|
|
|
|
@status = :fail
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_vote.fail')
|
2014-12-28 14:26:16 -08:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@count = report.votes
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_vote.okay')
|
2014-12-28 14:26:16 -08:00
|
|
|
@success = true
|
|
|
|
end
|
2014-12-28 15:21:06 -08:00
|
|
|
|
|
|
|
def destroy_report
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
report = Report.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
report.deleted = true
|
|
|
|
report.save
|
|
|
|
rescue
|
|
|
|
@status = :fail
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_report.fail')
|
2014-12-28 15:21:06 -08:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_report.okay')
|
2014-12-28 15:21:06 -08:00
|
|
|
@success = true
|
|
|
|
end
|
2014-12-28 15:50:14 -08:00
|
|
|
|
|
|
|
def create_comment
|
|
|
|
params.require :id
|
|
|
|
params.require :comment
|
|
|
|
|
|
|
|
report = Report.find(params[:id])
|
|
|
|
|
|
|
|
@success = false
|
|
|
|
|
|
|
|
begin
|
|
|
|
current_user.report_comment(report, params[:comment])
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
@status = :rec_inv
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.create_comment.rec_inv')
|
2014-12-28 15:50:14 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.create_comment.okay')
|
2014-12-28 15:50:14 -08:00
|
|
|
@success = true
|
|
|
|
@render = render_to_string(partial: 'moderation/discussion', locals: { report: report })
|
|
|
|
@count = report.moderation_comments.all.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_comment
|
2014-12-28 16:05:30 -08:00
|
|
|
params.require :comment
|
|
|
|
|
|
|
|
@status = :err
|
|
|
|
@success = false
|
|
|
|
comment = ModerationComment.find(params[:comment])
|
|
|
|
|
|
|
|
unless current_user == comment.user
|
|
|
|
@status = :nopriv
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_comment.nopriv')
|
2014-12-28 16:05:30 -08:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
comment.destroy
|
2014-12-28 15:50:14 -08:00
|
|
|
|
2014-12-28 16:05:30 -08:00
|
|
|
@status = :okay
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.destroy_comment.okay')
|
2014-12-28 16:05:30 -08:00
|
|
|
@success = true
|
2014-12-28 15:50:14 -08:00
|
|
|
end
|
2015-02-03 08:48:30 -08:00
|
|
|
|
2015-04-22 17:56:29 -07:00
|
|
|
def ban
|
|
|
|
@status = :err
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.ban.error')
|
2015-04-22 17:56:29 -07:00
|
|
|
@success = false
|
|
|
|
|
|
|
|
params.require :user
|
|
|
|
params.require :ban
|
|
|
|
params.require :permaban
|
|
|
|
|
|
|
|
reason = params[:reason]
|
|
|
|
target = User.find_by_screen_name(params[:user])
|
|
|
|
unban = params[:ban] == "0"
|
|
|
|
perma = params[:permaban] == "1"
|
|
|
|
|
2020-04-19 13:35:58 -07:00
|
|
|
buntil = DateTime.strptime params[:until], "%m/%d/%Y %I:%M %p" unless unban || perma
|
2015-04-22 17:56:29 -07:00
|
|
|
|
2020-04-19 13:35:58 -07:00
|
|
|
if !unban && target.has_role?(:administrator)
|
2015-04-22 17:56:29 -07:00
|
|
|
@status = :nopriv
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.ban.nopriv')
|
2015-04-22 17:56:29 -07:00
|
|
|
@success = false
|
2015-04-22 18:01:48 -07:00
|
|
|
return
|
2015-04-22 17:56:29 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
if unban
|
|
|
|
target.unban
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.ban.unban')
|
2015-04-22 17:56:29 -07:00
|
|
|
@success = true
|
|
|
|
elsif perma
|
|
|
|
target.ban nil, reason
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.ban.perma')
|
2015-04-22 17:56:29 -07:00
|
|
|
else
|
|
|
|
target.ban buntil, reason
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.ban.temp', date: buntil.to_s)
|
2015-04-22 17:56:29 -07:00
|
|
|
end
|
|
|
|
target.save!
|
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@success = target.banned? == !unban
|
|
|
|
end
|
|
|
|
|
2015-02-03 08:48:30 -08:00
|
|
|
def privilege
|
|
|
|
@status = :err
|
|
|
|
@success = false
|
|
|
|
|
|
|
|
params.require :user
|
|
|
|
params.require :type
|
|
|
|
params.require :status
|
|
|
|
|
|
|
|
status = params[:status] == 'true'
|
|
|
|
|
|
|
|
target_user = User.find_by_screen_name(params[:user])
|
|
|
|
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.privilege.nope')
|
2020-04-25 13:20:02 -07:00
|
|
|
return unless %w(moderator admin).include? params[:type].downcase
|
2015-02-03 08:48:30 -08:00
|
|
|
|
2020-04-25 14:23:37 -07:00
|
|
|
unless current_user.has_role?(:administrator)
|
2015-02-03 08:48:30 -08:00
|
|
|
@status = :nopriv
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.privilege.nopriv')
|
2015-02-03 08:48:30 -08:00
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@checked = status
|
2020-04-19 13:35:58 -07:00
|
|
|
type = params[:type].downcase
|
|
|
|
target_role = {"admin" => "administrator"}.fetch(type, type).to_sym
|
2020-04-25 13:20:02 -07:00
|
|
|
|
2020-04-25 14:23:37 -07:00
|
|
|
if status
|
|
|
|
target_user.add_role target_role
|
|
|
|
else
|
|
|
|
target_user.remove_role target_role
|
2015-09-01 06:18:56 -07:00
|
|
|
end
|
2015-02-03 08:48:30 -08:00
|
|
|
target_user.save!
|
|
|
|
|
2015-06-07 09:24:01 -07:00
|
|
|
@message = I18n.t('messages.moderation.privilege.checked', privilege: params[:type])
|
2015-02-03 08:48:30 -08:00
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@success = true
|
|
|
|
end
|
2014-12-28 14:26:16 -08:00
|
|
|
end
|