discourse/app/controllers/post_action_users_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
class PostActionUsersController < ApplicationController
INDEX_LIMIT = 200
def index
params.require(:post_action_type_id)
params.require(:id)
post_action_type_id = params[:post_action_type_id].to_i
2017-11-15 08:28:54 +08:00
page = params[:page].to_i
page_size = fetch_limit_from_params(default: INDEX_LIMIT, max: INDEX_LIMIT)
2017-11-15 08:28:54 +08:00
# Find the post, and then determine if they can see the post (if deleted)
post = Post.with_deleted.find_by(id: params[:id].to_i)
guardian.ensure_can_see!(post)
post_actions =
post
.post_actions
.where(post_action_type_id: post_action_type_id)
.includes(:user)
2017-11-15 08:28:54 +08:00
.offset(page * page_size)
.order("post_actions.created_at ASC")
2017-11-15 08:28:54 +08:00
.limit(page_size)
post_actions =
DiscoursePluginRegistry.apply_modifier(:post_action_users_list, post_actions, post)
if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
raise Discourse::InvalidAccess if current_user.blank?
post_actions = post_actions.where(user_id: current_user.id)
end
2017-11-15 08:28:54 +08:00
action_type = PostActionType.types.key(post_action_type_id)
total_count = post["#{action_type}_count"].to_i
post_actions = post_actions.to_a
data = {
post_action_users:
serialize_data(
post_actions,
PostActionUserSerializer,
unknown_user_ids: current_user_muting_or_ignoring_users(post_actions.map(&:user_id)),
),
}
2017-11-15 08:28:54 +08:00
data[:total_rows_post_action_users] = total_count if total_count > page_size
render_json_dump(data)
end
private
def current_user_muting_or_ignoring_users(user_ids)
return [] if current_user.blank?
UserCommScreener.new(
acting_user: current_user,
target_user_ids: user_ids,
).actor_preventing_communication
end
end