Skip to content

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.rb
index 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 < ApplicationController
def permissions
category = Category.find(params[:id])
+ guardian.ensure_can_see!(category)
+
if category.read_restricted?
permissions =
Group
diff --git a/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb b/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb
index 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 do
end
end
+ 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" do
it "returns a 404" do
get "/chat/api/category-chatables/#{private_category.id}/permissions"