Retrospring/app/controllers/moderation_controller.rb

66 lines
1.7 KiB
Ruby
Raw Normal View History

2014-12-25 14:00:33 -08:00
class ModerationController < ApplicationController
2020-04-18 16:45:50 -07:00
before_action :authenticate_user!
2014-12-28 16:25:48 -08:00
2014-12-25 14:00:33 -08:00
def index
2014-12-28 16:25:48 -08:00
@type = params[:type]
@reports = if @type == 'all'
Report.where(deleted: false).reverse_order
else
Report.where(deleted: false).where('LOWER(type) = ?', "reports::#{@type}").reverse_order
end
2014-12-25 14:00:33 -08:00
end
2015-07-23 10:38:42 -07:00
def priority
@user_id = params[:user_id]
if @user_id.nil?
@users = {}
Report.where(deleted: false).each do |report|
target = if report.target.is_a? User
report.target
2015-07-23 12:43:39 -07:00
elsif report.target.respond_to? :user
2015-07-23 10:38:42 -07:00
report.target.user
2015-07-23 12:43:39 -07:00
else
nil
2015-07-23 10:38:42 -07:00
end
2015-07-23 12:43:39 -07:00
next if target.nil?
2015-07-23 10:38:42 -07:00
@users[target] ||= 0
@users[target] += 1
end
@users = @users.sort_by do |k, v|
v
2015-07-23 12:43:39 -07:00
end.reverse
2015-07-23 12:44:20 -07:00
@users = Hash[@users]
2015-07-23 10:38:42 -07:00
else
@user_id = @user_id.to_i
@type = 'all'
@reports = []
Report.where(deleted: false).each do |report|
if report.target.is_a? User
@reports.push report if report.target.id == @user_id
else
next if report.target.user.nil?
@reports.push report if report.target.user.id == @user_id
end
end
@target_user = User.find(@user_id)
render template: 'moderation/index'
end
end
def ip
@user_id = params[:user_id]
@host = User.find(@user_id)
@users = []
return if @host.nil?
@users = User.where('(current_sign_in_ip = ? OR last_sign_in_ip = ?) AND id != ?', @host.current_sign_in_ip, @host.last_sign_in_ip, @user_id)
@users.unshift @host
render template: 'moderation/priority'
end
2014-12-25 14:00:33 -08:00
end