Skip to content

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.rb
index 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 DiscourseAutomation
def post_checked
post = Post.find(params[:post_id])
- guardian.ensure_can_edit!(post)
-
topic = post.topic
raise Discourse::NotFound if topic.blank?
+ post = topic.first_post
+ guardian.ensure_can_edit!(post)
+
topic.custom_fields[DiscourseAutomation::TOPIC_LAST_CHECKED_BY] = current_user.username
topic.custom_fields[DiscourseAutomation::TOPIC_LAST_CHECKED_AT] = Time.zone.now.to_s
topic.save_custom_fields
diff --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.rb
index 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 do
describe "#post_checked" do
fab!(: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" do
freeze_time
@@ -20,6 +22,20 @@ describe DiscourseAutomation::AppendLastCheckedByController do
expect(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" do
sign_in(Fabricate(:user))