Skip to content

A platform for community discussion. Free, open, simple.

FIX: Bound user-actions index limit at 100 (#42361)

Mark VanLandinghamca893a8608cf
diff --git a/app/controllers/user_actions_controller.rb b/app/controllers/user_actions_controller.rb
index 32c1245a632..1d601d274ff 100644
--- a/app/controllers/user_actions_controller.rb
+++ b/app/controllers/user_actions_controller.rb
@@ -11,7 +11,7 @@ class UserActionsController < ApplicationController
)
offset = [0, user_actions_params[:offset].to_i].max
action_types = (user_actions_params[:filter] || "").split(",").map(&:to_i)
- limit = user_actions_params.fetch(:limit, 30).to_i
+ limit = [user_actions_params.fetch(:limit, 30).to_i, 100].min
ensure_user_actions_visible!(user, action_types)
diff --git a/spec/requests/user_actions_controller_spec.rb b/spec/requests/user_actions_controller_spec.rb
index ab751688a54..d4fa4a2b16f 100644
--- a/spec/requests/user_actions_controller_spec.rb
+++ b/spec/requests/user_actions_controller_spec.rb
@@ -13,6 +13,36 @@ RSpec.describe UserActionsController do
end
end
+ context "when requesting more actions than the maximum page size" do
+ fab!(:user)
+
+ let(:params) { { username: user.username, filter: UserAction::REPLY, limit: 200 } }
+
+ before do
+ topic = Fabricate(:topic, user: user)
+
+ 101.times do
+ post = Fabricate(:post, topic: topic, user: user)
+ UserAction.create!(
+ action_type: UserAction::REPLY,
+ user: user,
+ acting_user: user,
+ target_topic: topic,
+ target_post: post,
+ )
+ end
+
+ user.user_stat.update!(post_count: 101)
+ end
+
+ it "returns no more than 100 actions" do
+ user_actions
+
+ expect(response).to have_http_status :ok
+ expect(response.parsed_body["user_actions"].length).to eq(100)
+ end
+ end
+
context "when 'username' is specified" do
let(:username) { post.user.username }
let(:params) { { username: username } }