Class: ModeratorController

Inherits:
ApplicationController show all
Defined in:
/var/apps/qpixel/app/controllers/moderator_controller.rb

Overview

Web controller. Provides authenticated actions for use by moderators. A lot of the stuff in here, and hence a lot of the tools, are rather repetitive.

Defined Under Namespace

Classes: VoteData, VoteSummary

Instance Method Summary collapse

Methods inherited from ApplicationController

#dashboard, #keyboard_tools, #upload

Instance Method Details

#handle_spammy_usersObject



83
84
85
86
87
88
89
90
91
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 83

def handle_spammy_users
  spam = User.where(id: params[:spam_ids])
  spam.each do |user|
    user.block('Profile spam', length: 10.years, automatic: false)
    user.soft_delete(current_user)
  end
  flash[:success] = "#{spam.size} users blocked and deleted."
  redirect_to mod_spammers_path
end

#indexObject



12
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 12

def index; end

#nominate_promotionObject



22
23
24
25
26
27
28
29
30
31
32
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 22

def nominate_promotion
  return not_found!(errors: ['no_privilege']) unless current_user.privilege? 'flag_curate'
  return not_found!(errors: ['unavailable_for_type']) unless top_level_post_types.include? @post.post_type_id

  PostHistory.nominated_for_promotion(@post, current_user)
  nominations = helpers.promoted_posts
  nominations.merge!(@post.id => DateTime.now.to_i)
  nominations.select! { |_k, v| DateTime.now.to_i - v <= 3600 * 24 * 28 }
  RequestContext.redis.set 'network/promoted_posts', JSON.dump(nominations)
  render json: { status: 'success', success: true }
end

#pii_correlationObject



93
94
95
96
97
98
99
100
101
102
103
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 93

def pii_correlation
  @user = User.find(params[:id])
  respond_to do |format|
    format.html do
      render layout: 'without_sidebar'
    end
    format.template do
      @target = User.find_by(id: params[:target_id])
    end
  end
end

#promotionsObject



34
35
36
37
38
39
40
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 34

def promotions
  return not_found!(errors: ['no_privilege']) unless current_user.privilege? 'flag_curate'

  # This is network-wide, but the Post selection will default to current site only, so not a problem.
  @promotions = helpers.promoted_posts
  @posts = Post.where(id: @promotions.keys)
end

#recent_commentsObject



18
19
20
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 18

def recent_comments
  @comments = Comment.all.includes(:user, :post).newest_first.paginate(page: params[:page], per_page: 50)
end

#recently_deleted_postsObject



14
15
16
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 14

def recently_deleted_posts
  @posts = Post.unscoped.on(@community).deleted.order(deleted_at: :desc).paginate(page: params[:page], per_page: 50)
end

#remove_promotionObject



42
43
44
45
46
47
48
49
50
51
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 42

def remove_promotion
  return not_found!(errors: ['no_privilege']) unless current_user.privilege? 'flag_curate'

  promotions = helpers.promoted_posts
  return not_found!(errors: ['not_promoted']) unless promotions.keys.include? @post.id.to_s

  promotions = promotions.reject { |k, _v| k == @post.id.to_s }
  RequestContext.redis.set 'network/promoted_posts', JSON.dump(promotions)
  render json: { status: 'success', success: true }
end

#spammy_usersObject



75
76
77
78
79
80
81
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 75

def spammy_users
  script = File.read(Rails.root.join('db/scripts/potential_spam_profiles.sql'))
  hours = { 'day' => 24, 'week' => 168, 'month' => 744 }
  script = script.gsub('$HOURS', hours[params[:period]]&.to_s || '744')
  user_ids = ApplicationRecord.connection.execute(script).to_a.flatten
  @users = User.where(id: user_ids).limit(20)
end

#user_vote_summaryObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File '/var/apps/qpixel/app/controllers/moderator_controller.rb', line 56

def user_vote_summary
  @user = User.find params[:id]
  @users = User.where(id: Vote.by(@user).select(:recv_user_id).distinct)
               .or(User.where(id: Vote.for(@user).select(:user_id).distinct))
  @vote_data = VoteData.new(
    cast: VoteSummary.new(
      breakdown: Vote.by(@user).group(:recv_user_id, :vote_type).count,
      types: Vote.by(@user).group(:vote_type).count,
      total: Vote.by(@user).count
    ),
    received: VoteSummary.new(
      breakdown: Vote.for(@user).group(:user_id, :vote_type).count,
      types: Vote.for(@user).group(:vote_type).count,
      total: Vote.for(@user).count
    )
  )
  render layout: 'without_sidebar'
end