Class: ModeratorController

Inherits:
ApplicationController show all
Defined in:
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

#indexObject



9
# File 'app/controllers/moderator_controller.rb', line 9

def index; end

#nominate_promotionObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/moderator_controller.rb', line 20

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

#promotionsObject



32
33
34
35
36
37
38
# File 'app/controllers/moderator_controller.rb', line 32

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



16
17
18
# File 'app/controllers/moderator_controller.rb', line 16

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

#recently_deleted_postsObject



11
12
13
14
# File 'app/controllers/moderator_controller.rb', line 11

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

#remove_promotionObject



40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/moderator_controller.rb', line 40

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

#user_vote_summaryObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/moderator_controller.rb', line 54

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