A platform for community discussion. Free, open, simple.
FIX: `set_notifications` missing guardian topic visibility check (#37786)
Joffrey JAFFEUX24875a45d5f6
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 0737ab1e86f..4e1dafcab2e 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -880,6 +880,7 @@ class TopicsController < ApplicationControllerendtopic = Topic.find(params[:topic_id].to_i)+ guardian.ensure_can_see!(topic)TopicUser.change(user, topic.id, notification_level: params[:notification_level].to_i)render json: success_jsonenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 94ef1e3c724..1d27bc05ba3 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -6514,6 +6514,31 @@ RSpec.describe TopicsController do)endend++ it "does not allow a regular user to set notifications on a private message they cannot see" do+ sign_in(user)++ post "/t/#{pm.id}/notifications.json",+ params: {+ notification_level: NotificationLevels.topic_levels[:watching],+ }++ expect(response.status).to eq(403)+ expect(TopicUser.find_by(user: user, topic: pm)).to be_blank+ end++ it "does not allow a regular user to set notifications on a topic in a restricted category" do+ restricted_topic = Fabricate(:topic, category: staff_category)+ sign_in(user)++ post "/t/#{restricted_topic.id}/notifications.json",+ params: {+ notification_level: NotificationLevels.topic_levels[:watching],+ }++ expect(response.status).to eq(403)+ expect(TopicUser.find_by(user: user, topic: restricted_topic)).to be_blank+ endenddescribe ".defer_topic_view" do