2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-01 00:28:13 +08:00
|
|
|
class PostActionUsersController < ApplicationController
|
2023-07-28 19:53:46 +08:00
|
|
|
INDEX_LIMIT = 200
|
|
|
|
|
2015-10-01 00:28:13 +08:00
|
|
|
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
|
2023-07-28 19:53:46 +08:00
|
|
|
page_size = fetch_limit_from_params(default: INDEX_LIMIT, max: INDEX_LIMIT)
|
2017-11-15 08:28:54 +08:00
|
|
|
|
2020-11-06 01:18:26 +08:00
|
|
|
# Find the post, and then determine if they can see the post (if deleted)
|
2024-02-20 07:48:09 +08:00
|
|
|
post = Post.with_deleted.find_by(id: params[:id].to_i)
|
2015-10-01 00:28:13 +08:00
|
|
|
guardian.ensure_can_see!(post)
|
2017-06-03 02:23:56 +08:00
|
|
|
|
2015-10-01 00:28:13 +08:00
|
|
|
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)
|
2019-12-14 05:18:28 +08:00
|
|
|
.order("post_actions.created_at ASC")
|
2017-11-15 08:28:54 +08:00
|
|
|
.limit(page_size)
|
2015-10-01 00:28:13 +08:00
|
|
|
|
2024-02-20 07:48:09 +08:00
|
|
|
post_actions =
|
|
|
|
DiscoursePluginRegistry.apply_modifier(:post_action_users_list, post_actions, post)
|
|
|
|
|
2017-06-03 02:23:56 +08:00
|
|
|
if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
|
2024-02-20 07:48:09 +08:00
|
|
|
raise Discourse::InvalidAccess if current_user.blank?
|
2017-06-03 02:23:56 +08:00
|
|
|
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)
|
2020-04-18 01:23:33 +08:00
|
|
|
total_count = post["#{action_type}_count"].to_i
|
2024-02-20 07:48:09 +08:00
|
|
|
post_actions = post_actions.to_a
|
2020-06-19 22:44:21 +08:00
|
|
|
data = {
|
|
|
|
post_action_users:
|
|
|
|
serialize_data(
|
2024-02-20 07:48:09 +08:00
|
|
|
post_actions,
|
2020-06-19 22:44:21 +08:00
|
|
|
PostActionUserSerializer,
|
2024-02-20 07:48:09 +08:00
|
|
|
unknown_user_ids: current_user_muting_or_ignoring_users(post_actions.map(&:user_id)),
|
2020-06-19 22:44:21 +08:00
|
|
|
),
|
|
|
|
}
|
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)
|
2015-10-01 00:28:13 +08:00
|
|
|
end
|
2024-02-20 07:48:09 +08:00
|
|
|
|
|
|
|
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
|
2015-10-01 00:28:13 +08:00
|
|
|
end
|