A platform for community discussion. Free, open, simple.
FIX: ensures moderators can see category permissions (#36772)
Joffrey JAFFEUXa2031bbaacc8
diff --git a/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb b/plugins/chat/app/controllers/chat/api/category_chatables_controller.rbindex 3badc183b82..2104c66da4d 100644--- a/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb+++ b/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb@@ -6,6 +6,8 @@ class Chat::Api::CategoryChatablesController < ApplicationControllerdef permissionscategory = Category.find(params[:id])+ guardian.ensure_can_see!(category)+if category.read_restricted?permissions =Groupdiff --git a/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb b/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rbindex a65a5c574f3..70f09768f5c 100644--- a/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb+++ b/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb@@ -79,6 +79,26 @@ describe Chat::Api::CategoryChatablesController doendend+ context "when signed in as a moderator" do+ fab!(:moderator)++ before { sign_in(moderator) }++ it "returns a 403 if they cannot see the category" do+ get "/chat/api/category-chatables/#{private_category.id}/permissions"++ expect(response.status).to eq(403)+ end++ it "returns a 200 if they can see the category" do+ group.add(moderator)++ get "/chat/api/category-chatables/#{private_category.id}/permissions"++ expect(response.status).to eq(200)+ end+ end+context "as anon" doit "returns a 404" doget "/chat/api/category-chatables/#{private_category.id}/permissions"