Skip to content

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

Revert "FIX: Limit visibility on accepted/not_accepted endpoints (#38… (#38043)

David Taylorb637339b4786
diff --git a/plugins/discourse-policy/app/controllers/discourse_policy/policy_controller.rb b/plugins/discourse-policy/app/controllers/discourse_policy/policy_controller.rb
index 08c83588c8f..41140c8f47c 100644
--- a/plugins/discourse-policy/app/controllers/discourse_policy/policy_controller.rb
+++ b/plugins/discourse-policy/app/controllers/discourse_policy/policy_controller.rb
@@ -5,7 +5,6 @@ class DiscoursePolicy::PolicyController < ::ApplicationController
before_action :ensure_logged_in, :set_post
before_action :ensure_can_accept, only: %i[accept unaccept]
- before_action :ensure_can_see_policy_users, only: %i[accepted not_accepted]
def accept
PolicyUser.add!(current_user, @post.post_policy)
@@ -30,6 +29,15 @@ class DiscoursePolicy::PolicyController < ::ApplicationController
end
def accepted
+ # Check if user has permission to see group members
+ groups = @post.post_policy.groups
+ return render_json_error(I18n.t("discourse_policy.errors.group_not_found")) if groups.blank?
+
+ guardian = Guardian.new(current_user)
+ unless guardian.can_see_groups_members?(groups)
+ return render_json_error(I18n.t("discourse_policy.error.no_permission"))
+ end
+
users =
@post
.post_policy
@@ -41,6 +49,15 @@ class DiscoursePolicy::PolicyController < ::ApplicationController
end
def not_accepted
+ # Check if user has permission to see group members
+ groups = @post.post_policy.groups
+ return render_json_error(I18n.t("discourse_policy.errors.group_not_found")) if groups.blank?
+
+ guardian = Guardian.new(current_user)
+ unless guardian.can_see_groups_members?(groups)
+ return render_json_error(I18n.t("discourse_policy.error.no_permission"))
+ end
+
users =
@post
.post_policy
@@ -53,15 +70,6 @@ class DiscoursePolicy::PolicyController < ::ApplicationController
private
- def ensure_can_see_policy_users
- post_policy = @post.post_policy
- raise Discourse::InvalidAccess if post_policy.private? && !guardian.is_admin?
-
- unless guardian.can_see_groups_members?(post_policy.groups)
- render_json_error(I18n.t("discourse_policy.error.no_permission"))
- end
- end
-
def ensure_can_accept
if !GroupUser.where(
"group_id in (:group_ids) and user_id = :user_id",
diff --git a/plugins/discourse-policy/spec/requests/policy_controller_spec.rb b/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
index 143fe99860d..559f962d21f 100644
--- a/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
+++ b/plugins/discourse-policy/spec/requests/policy_controller_spec.rb
@@ -112,60 +112,6 @@ describe DiscoursePolicy::PolicyController do
end
end
- describe "private policy restrictions" do
- fab!(:admin)
-
- def private_raw
- <<~MD
- [policy group=#{group.name} private=true]
- I always open **doors**!
- [/policy]
- MD
- end
-
- it "denies non-admin access to accepted users for a private policy" do
- post = create_post(raw: private_raw, user: moderator)
- PolicyUser.add!(user1, post.post_policy)
-
- sign_in(user1)
- get "/policy/accepted.json", params: { post_id: post.id, offset: 0 }
- expect(response.status).to eq(403)
- end
-
- it "denies non-admin access to not_accepted users for a private policy" do
- post = create_post(raw: private_raw, user: moderator)
-
- sign_in(user1)
- get "/policy/not-accepted.json", params: { post_id: post.id, offset: 0 }
- expect(response.status).to eq(403)
- end
-
- it "allows admin access to accepted users for a private policy" do
- group.add(admin)
- post = create_post(raw: private_raw, user: moderator)
- PolicyUser.add!(user1, post.post_policy)
-
- sign_in(admin)
- get "/policy/accepted.json", params: { post_id: post.id, offset: 0 }
- expect(response.status).to eq(200)
- expect(response.parsed_body["users"].map { |x| x["id"] }).to include(user1.id)
- end
-
- it "allows admin access to not_accepted users for a private policy" do
- group.add(admin)
- post = create_post(raw: private_raw, user: moderator)
-
- sign_in(admin)
- get "/policy/not-accepted.json", params: { post_id: post.id, offset: 0 }
- expect(response.status).to eq(200)
- expect(response.parsed_body["users"].map { |x| x["id"] }).to contain_exactly(
- user1.id,
- user2.id,
- admin.id,
- )
- end
- end
-
describe "group member visibility restrictions" do
fab!(:owner, :user)
let!(:post) do
@@ -201,12 +147,10 @@ describe DiscoursePolicy::PolicyController do
end
it "allows owner to see group members" do
- PolicyUser.add!(user1, post.post_policy)
-
sign_in(owner)
get "/policy/accepted.json", params: { post_id: post.id, offset: 0 }
expect(response.status).to eq(200)
- expect(response.parsed_body["users"].map { |x| x["id"] }).to contain_exactly(user1.id)
+ expect(response.parsed_body["users"]).to be_an(Array)
end
end
end