A platform for community discussion. Free, open, simple.
SECURITY: Enforce edit permissions and audit trail in TriggerPostAction
Isaac Janzen4b9ee0bc05dc
diff --git a/app/services/user/action/trigger_post_action.rb b/app/services/user/action/trigger_post_action.rbindex f076e3defac..0e4129a873e 100644--- a/app/services/user/action/trigger_post_action.rb+++ b/app/services/user/action/trigger_post_action.rb@@ -27,6 +27,7 @@ class User::Action::TriggerPostAction < Service::ActionBaseenddef edit+ return unless guardian.can_edit_post?(post)# Take what the moderator edited in as gospelPostRevisor.new(post).revise!(user,diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rbindex 308ff7a3944..adecedf8e25 100644--- a/spec/requests/admin/users_controller_spec.rb+++ b/spec/requests/admin/users_controller_spec.rb@@ -602,6 +602,23 @@ RSpec.describe Admin::UsersController doinclude_examples "suspension of active user possible"include_examples "suspension of staff users"++ it "cannot edit an arbitrary static doc post unrelated to the suspended user" do+ static_doc_post = Fabricate(:post)+ SiteSetting.tos_topic_id = static_doc_post.topic_id++ put "/admin/users/#{user.id}/suspend.json",+ params: {+ suspend_until: 5.hours.from_now,+ reason: "reason",+ post_id: static_doc_post.id,+ post_action: "edit",+ post_edit: "edited content",+ }++ expect(response.status).to eq(200)+ expect(static_doc_post.reload.raw).not_to eq("edited content")+ endendcontext "when logged in as a non-staff user" dodiff --git a/spec/services/user/action/trigger_post_action_spec.rb b/spec/services/user/action/trigger_post_action_spec.rbindex cdc19bc373e..b497809906f 100644--- a/spec/services/user/action/trigger_post_action_spec.rb+++ b/spec/services/user/action/trigger_post_action_spec.rb@@ -84,8 +84,19 @@ RSpec.describe User::Action::TriggerPostAction dolet(:post_action) { "edit" }let(:post_edit) { "blabla" }- it "edits the post with what the moderator wrote" do- expect { action }.to change { post.reload.raw }.to eq("blabla")+ context "when user cannot edit a post" do+ fab!(:regular_user, :user)+ let(:guardian) { regular_user.guardian }++ it "does nothing" do+ expect { action }.not_to change { post.reload.raw }+ end+ end++ context "when user can edit a post" do+ it "edits the post with what the moderator wrote" do+ expect { action }.to change { post.reload.raw }.to eq("blabla")+ endendendend