2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
class PostActionUsersController < ApplicationController
|
|
|
|
def index
|
|
|
|
params.require(:post_action_type_id)
|
|
|
|
params.require(:id)
|
|
|
|
post_action_type_id = params[:post_action_type_id].to_i
|
|
|
|
|
2017-11-14 19:28:54 -05:00
|
|
|
page = params[:page].to_i
|
|
|
|
page_size = (params[:limit] || 200).to_i
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
finder = Post.where(id: params[:id].to_i)
|
|
|
|
finder = finder.with_deleted if guardian.is_staff?
|
|
|
|
|
|
|
|
post = finder.first
|
|
|
|
guardian.ensure_can_see!(post)
|
2017-06-02 14:23:56 -04:00
|
|
|
|
2020-06-19 10:44:21 -04:00
|
|
|
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
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
post_actions = post.post_actions.where(post_action_type_id: post_action_type_id)
|
|
|
|
.includes(:user)
|
2017-11-14 19:28:54 -05:00
|
|
|
.offset(page * page_size)
|
2019-12-13 16:18:28 -05:00
|
|
|
.order('post_actions.created_at ASC')
|
2017-11-14 19:28:54 -05:00
|
|
|
.limit(page_size)
|
2015-09-30 12:28:13 -04:00
|
|
|
|
2017-06-02 14:23:56 -04:00
|
|
|
if !guardian.can_see_post_actors?(post.topic, post_action_type_id)
|
2019-12-13 16:18:28 -05:00
|
|
|
raise Discourse::InvalidAccess unless current_user
|
2017-06-02 14:23:56 -04:00
|
|
|
post_actions = post_actions.where(user_id: current_user.id)
|
|
|
|
end
|
|
|
|
|
2017-11-14 19:28:54 -05:00
|
|
|
action_type = PostActionType.types.key(post_action_type_id)
|
2020-04-17 13:23:33 -04:00
|
|
|
total_count = post["#{action_type}_count"].to_i
|
2017-11-14 19:28:54 -05:00
|
|
|
|
2020-06-19 10:44:21 -04:00
|
|
|
data = {
|
|
|
|
post_action_users: serialize_data(
|
|
|
|
post_actions.to_a,
|
|
|
|
PostActionUserSerializer,
|
|
|
|
unknown_user_ids: unknown_user_ids
|
|
|
|
)
|
|
|
|
}
|
2017-11-14 19:28:54 -05:00
|
|
|
|
|
|
|
if total_count > page_size
|
|
|
|
data[:total_rows_post_action_users] = total_count
|
|
|
|
end
|
|
|
|
|
|
|
|
render_json_dump(data)
|
2015-09-30 12:28:13 -04:00
|
|
|
end
|
|
|
|
end
|