Class: Thredded::ModerationController

Inherits:
ApplicationController show all
Defined in:
app/controllers/thredded/moderation_controller.rb

Instance Method Summary collapse

Methods included from UrlsHelper

#delete_post_path, #edit_post_path, #edit_preferences_path, #edit_preferences_url, #mark_unread_path, #permalink_path, #post_path, #post_url, #quote_post_path, #search_path, #send_private_message_path, #topic_path, #topic_url, #unread_topics_path, #user_path

Instance Method Details

#activityObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/thredded/moderation_controller.rb', line 26

def activity
  @posts = Thredded::PostsPageView.new(
    thredded_current_user,
    preload_posts_for_moderation(moderatable_posts).order_newest_first
      .send(Kaminari.config.page_method_name, current_page)
      .preload_first_topic_post
  )
  maybe_set_last_moderated_record_flash
end

#historyObject



18
19
20
21
22
23
24
# File 'app/controllers/thredded/moderation_controller.rb', line 18

def history
  @post_moderation_records = accessible_post_moderation_records
    .order(created_at: :desc)
    .send(Kaminari.config.page_method_name, current_page)
    .preload(:messageboard, :post_user, :moderator, post: :postable)
    .preload_first_topic_post
end

#moderate_postObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/thredded/moderation_controller.rb', line 36

def moderate_post
  moderation_state = params[:moderation_state].to_s
  return head(:bad_request) unless Thredded::Post.moderation_states.include?(moderation_state)
  post = moderatable_posts.find(params[:id].to_s)
  if post.moderation_state != moderation_state
    flash[:last_moderated_record_id] = Thredded::ModeratePost.run!(
      post: post,
      moderation_state: moderation_state,
      moderator: thredded_current_user,
    ).id
  else
    flash[:alert] = "Post was already #{moderation_state}:"
    flash[:last_moderated_record_id] =
      Thredded::PostModerationRecord.order_newest_first.find_by(post_id: post.id)&.id
  end
  redirect_back fallback_location: pending_moderation_path
end

#moderate_userObject



79
80
81
82
83
84
# File 'app/controllers/thredded/moderation_controller.rb', line 79

def moderate_user
  return head(:bad_request) unless Thredded::UserDetail.moderation_states.include?(params[:moderation_state])
  user = Thredded.user_class.find(params[:id])
  user.thredded_user_detail.update!(moderation_state: params[:moderation_state])
  redirect_back fallback_location: user_moderation_path(user.id)
end

#pendingObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/thredded/moderation_controller.rb', line 8

def pending
  @posts = Thredded::PostsPageView.new(
    thredded_current_user,
    preload_posts_for_moderation(moderatable_posts.pending_moderation).order_oldest_first
      .send(Kaminari.config.page_method_name, current_page)
      .preload_first_topic_post
  )
  maybe_set_last_moderated_record_flash
end

#userObject



68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/thredded/moderation_controller.rb', line 68

def user
  @user = Thredded.user_class.find(params[:id])
  # Do not apply policy_scope here, as we want to show blocked posts as well.
  posts_scope = @user.thredded_posts
    .where(messageboard_id: policy_scope(Messageboard.all).pluck(:id))
    .order_newest_first
    .includes(:postable)
    .send(Kaminari.config.page_method_name, current_page)
  @posts = Thredded::PostsPageView.new(thredded_current_user, posts_scope)
end

#usersObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/thredded/moderation_controller.rb', line 54

def users
  @users = Thredded.user_class
    .eager_load(:thredded_user_detail)
    .merge(
      Thredded::UserDetail.order(
        Arel.sql('COALESCE(thredded_user_details.moderation_state, 0) ASC,'\
                 'thredded_user_details.moderation_state_changed_at DESC')
      )
    )
  @query = params[:q].to_s
  @users = DbTextSearch::CaseInsensitive.new(@users, Thredded.user_name_column).prefix(@query) if @query.present?
  @users = @users.send(Kaminari.config.page_method_name, current_page)
end