Class: PostActionUsersController

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

Constant Summary collapse

INDEX_LIMIT =
200

Constants inherited from ApplicationController

ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE

Constants included from CanonicalURL::ControllerExtensions

CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS

Instance Attribute Summary

Attributes inherited from ApplicationController

#theme_id

Instance Method Summary collapse

Methods inherited from ApplicationController

#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale

Methods included from VaryHeader

#ensure_vary_header

Methods included from ReadOnlyMixin

#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, included, #staff_writes_only_mode?

Methods included from Hijack

#hijack

Methods included from GlobalPath

#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path

Methods included from JsonError

#create_errors_json

Methods included from CanonicalURL::ControllerExtensions

#canonical_url, #default_canonical, included

Methods included from CurrentUser

#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/post_action_users_controller.rb', line 6

def index
  params.require(:post_action_type_id)
  params.require(:id)
  post_action_type_id = params[:post_action_type_id].to_i

  page = params[:page].to_i
  page_size = fetch_limit_from_params(default: INDEX_LIMIT, max: INDEX_LIMIT)

  # Find the post, and then determine if they can see the post (if deleted)
  post = Post.with_deleted.where(id: params[:id].to_i).first
  guardian.ensure_can_see!(post)

  unknown_user_ids = Set.new
  if current_user.present?
    result = DB.query_single(<<~SQL, user_id: current_user.id)
      SELECT mu.muted_user_id AS id FROM muted_users AS mu WHERE mu.user_id = :user_id
      UNION
      SELECT iu.ignored_user_id AS id FROM ignored_users AS iu WHERE iu.user_id = :user_id
    SQL
    unknown_user_ids.merge(result)
  end

  post_actions =
    post
      .post_actions
      .where(post_action_type_id: post_action_type_id)
      .includes(:user)
      .offset(page * page_size)
      .order("post_actions.created_at ASC")
      .limit(page_size)

  if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
    raise Discourse::InvalidAccess unless current_user
    post_actions = post_actions.where(user_id: current_user.id)
  end

  action_type = PostActionType.types.key(post_action_type_id)
  total_count = post["#{action_type}_count"].to_i

  data = {
    post_action_users:
      serialize_data(
        post_actions.to_a,
        PostActionUserSerializer,
        unknown_user_ids: unknown_user_ids,
      ),
  }

  data[:total_rows_post_action_users] = total_count if total_count > page_size

  render_json_dump(data)
end