2022-12-29 06:49:15 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
class Ajax::ModerationController < AjaxController
|
2014-12-29 00:21:06 +01:00
|
|
|
def destroy_report
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
report = Report.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
report.deleted = true
|
|
|
|
report.save
|
2020-04-28 20:32:36 +02:00
|
|
|
rescue => e
|
2021-12-28 18:32:03 +01:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :fail
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".error")
|
2014-12-29 00:21:06 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2014-12-29 00:21:06 +01:00
|
|
|
end
|
2014-12-29 00:50:14 +01:00
|
|
|
|
2015-04-23 02:56:29 +02:00
|
|
|
def ban
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :err
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".error")
|
2015-04-23 02:56:29 +02:00
|
|
|
|
|
|
|
params.require :user
|
|
|
|
params.require :ban
|
|
|
|
|
2021-08-19 17:50:24 +02:00
|
|
|
duration = params[:duration].to_i
|
2021-08-14 18:04:58 +02:00
|
|
|
duration_unit = params[:duration_unit].to_s
|
|
|
|
reason = params[:reason].to_s
|
2021-08-19 17:50:24 +02:00
|
|
|
target_user = User.find_by_screen_name!(params[:user])
|
2021-08-14 18:04:58 +02:00
|
|
|
unban = params[:ban] == '0'
|
2021-12-30 21:06:21 +01:00
|
|
|
perma = params[:duration].blank?
|
2015-04-23 02:56:29 +02:00
|
|
|
|
2022-12-18 03:21:25 +01:00
|
|
|
if !unban && target_user.has_cached_role?(:administrator)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :nopriv
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".nopriv")
|
2015-04-23 03:01:48 +02:00
|
|
|
return
|
2015-04-23 02:56:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if unban
|
2021-08-19 17:50:24 +02:00
|
|
|
UseCase::User::Unban.call(target_user.id)
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".success.unban")
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:success] = true
|
2021-08-19 17:50:24 +02:00
|
|
|
@response[:status] = :okay
|
|
|
|
return
|
2015-04-23 02:56:29 +02:00
|
|
|
elsif perma
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".success.permanent")
|
2021-08-19 17:50:24 +02:00
|
|
|
expiry = nil
|
2015-04-23 02:56:29 +02:00
|
|
|
else
|
2021-08-19 17:50:24 +02:00
|
|
|
params.require :duration
|
|
|
|
params.require :duration_unit
|
|
|
|
|
|
|
|
raise Errors::InvalidBanDuration unless %w[hours days weeks months].include? duration_unit
|
|
|
|
|
|
|
|
expiry = DateTime.now + duration.public_send(duration_unit)
|
2022-09-03 16:42:17 +02:00
|
|
|
@response[:message] = t(".success.temporary", date: expiry.to_s)
|
2015-04-23 02:56:29 +02:00
|
|
|
end
|
2021-08-19 17:50:24 +02:00
|
|
|
|
|
|
|
UseCase::User::Ban.call(
|
|
|
|
target_user_id: target_user.id,
|
|
|
|
expiry: expiry,
|
|
|
|
reason: reason,
|
|
|
|
source_user_id: current_user.id)
|
|
|
|
|
|
|
|
target_user.save!
|
2015-04-23 02:56:29 +02:00
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
2021-08-19 17:50:24 +02:00
|
|
|
@response[:success] = true
|
2015-04-23 02:56:29 +02:00
|
|
|
end
|
|
|
|
|
2015-02-03 17:48:30 +01:00
|
|
|
def privilege
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :err
|
2015-02-03 17:48:30 +01:00
|
|
|
|
|
|
|
params.require :user
|
|
|
|
params.require :type
|
|
|
|
params.require :status
|
|
|
|
|
|
|
|
status = params[:status] == 'true'
|
|
|
|
|
2020-05-01 22:41:26 +02:00
|
|
|
target_user = User.find_by_screen_name!(params[:user])
|
2015-02-03 17:48:30 +01:00
|
|
|
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".error")
|
2024-02-28 00:40:38 +01:00
|
|
|
return unless %w[moderator administrator].include? params[:type].downcase
|
2015-02-03 17:48:30 +01:00
|
|
|
|
2022-12-18 03:21:25 +01:00
|
|
|
unless current_user.has_cached_role?(:administrator)
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :nopriv
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".nopriv")
|
2015-02-03 17:48:30 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:checked] = status
|
2020-04-19 22:35:58 +02:00
|
|
|
type = params[:type].downcase
|
2024-02-28 00:35:25 +01:00
|
|
|
target_role = type.to_sym
|
2020-04-25 22:20:02 +02:00
|
|
|
|
2020-04-25 23:23:37 +02:00
|
|
|
if status
|
|
|
|
target_user.add_role target_role
|
|
|
|
else
|
|
|
|
target_user.remove_role target_role
|
2015-09-01 15:18:56 +02:00
|
|
|
end
|
2015-02-03 17:48:30 +01:00
|
|
|
target_user.save!
|
|
|
|
|
2022-07-06 11:06:23 +02:00
|
|
|
@response[:message] = t(".success", privilege: params[:type])
|
2015-02-03 17:48:30 +01:00
|
|
|
|
2020-04-28 20:27:59 +02:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:success] = true
|
2015-02-03 17:48:30 +01:00
|
|
|
end
|
2014-12-28 23:26:16 +01:00
|
|
|
end
|