A platform for community discussion. Free, open, simple.
SECURITY: Resolve and authorize the topic's first post before setting last-checked attr... (#43996)
Keegan Georgeda06ac82b6d2
diff --git a/plugins/automation/app/controllers/discourse_automation/append_last_checked_by_controller.rb b/plugins/automation/app/controllers/discourse_automation/append_last_checked_by_controller.rbindex ab35bf7abba..c798b47e368 100644--- a/plugins/automation/app/controllers/discourse_automation/append_last_checked_by_controller.rb+++ b/plugins/automation/app/controllers/discourse_automation/append_last_checked_by_controller.rb@@ -7,11 +7,12 @@ module DiscourseAutomationdef post_checkedpost = Post.find(params[:post_id])- guardian.ensure_can_edit!(post)-topic = post.topicraise Discourse::NotFound if topic.blank?+ post = topic.first_post+ guardian.ensure_can_edit!(post)+topic.custom_fields[DiscourseAutomation::TOPIC_LAST_CHECKED_BY] = current_user.usernametopic.custom_fields[DiscourseAutomation::TOPIC_LAST_CHECKED_AT] = Time.zone.now.to_stopic.save_custom_fieldsdiff --git a/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb b/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rbindex 97a326b3512..49772019738 100644--- a/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb+++ b/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb@@ -6,6 +6,8 @@ describe DiscourseAutomation::AppendLastCheckedByController dodescribe "#post_checked" dofab!(:post)fab!(:topic) { post.topic }+ fab!(:reply_author) { Fabricate(:user, refresh_auto_groups: true) }+ fab!(:reply) { Fabricate(:post, topic:, user: reply_author) }it "updates the topic custom fields" dofreeze_time@@ -20,6 +22,20 @@ describe DiscourseAutomation::AppendLastCheckedByController doexpect(topic_last_checked_at).to be_within_one_second_of(Time.zone.now)end+ it "does not let reply authors mark topic documents as checked" do+ sign_in(reply_author)++ expect { put "/append-last-checked-by/#{reply.id}.json" }.not_to change {+ topic.reload.custom_fields.slice(+ DiscourseAutomation::TOPIC_LAST_CHECKED_BY,+ DiscourseAutomation::TOPIC_LAST_CHECKED_AT,+ )+ }++ expect(response.status).to eq(403)+ expect(response.parsed_body).to have_key("errors")+ end+it "returns error if user can not edit the post" dosign_in(Fabricate(:user))