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"
|
|
|
|
|
2015-04-23 12:21:58 -07:00
|
|
|
buntil = DateTime.strptime params[:until], "%m/%d/%Y %I:%M %p" unless unban or perma
|
2015-04-22 17:56:29 -07:00
|
|
|
|
|
|
|
if not unban and target.admin?
|
|
|
|
@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')
|
2015-06-19 05:46:23 -07:00
|
|
|
return unless %w(blogger supporter moderator admin contributor translator).include? params[:type].downcase
|
2015-02-03 08:48:30 -08:00
|
|
|
|
2015-04-22 17:56:29 -07:00
|
|
|
if %w(supporter moderator admin).include?(params[:type].downcase) and !current_user.admin?
|
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
|
2015-09-01 06:14:50 -07:00
|
|
|
case params[:type].downcase
|
|
|
|
when 'blogger'
|
|
|
|
target_user.blogger = status
|
|
|
|
when 'contributor'
|
|
|
|
target_user.contributor = status
|
|
|
|
when 'translator'
|
|
|
|
target_user.translator = status
|
|
|
|
when 'supporter'
|
|
|
|
target_user.translator = status
|
|
|
|
when 'moderator'
|
|
|
|
target_user.translator = status
|
|
|
|
when 'admin'
|
|
|
|
target_user.translator = status
|
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
|