FIX: Change create_post_for_category_and_tag_changes setting to use whispers instead of small actions (#29602)

It currently can leak private tags/categories, to address this we are moving to whispers.
This commit is contained in:
Gabriel Grubba 2024-11-06 09:28:28 -03:00 committed by GitHub
parent 5177aef37d
commit 75beb5a84f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 5 deletions

View File

@ -154,7 +154,8 @@ class PostRevisor
end end
def self.create_small_action_for_category_change(topic:, user:, old_category:, new_category:) def self.create_small_action_for_category_change(topic:, user:, old_category:, new_category:)
if !old_category || !new_category || !SiteSetting.create_post_for_category_and_tag_changes if !old_category || !new_category || !SiteSetting.create_post_for_category_and_tag_changes ||
SiteSetting.whispers_allowed_groups.blank?
return return
end end
@ -165,18 +166,21 @@ class PostRevisor
from: "##{old_category.slug_ref}", from: "##{old_category.slug_ref}",
to: "##{new_category.slug_ref}", to: "##{new_category.slug_ref}",
), ),
post_type: Post.types[:small_action], post_type: Post.types[:whisper],
action_code: "category_changed", action_code: "category_changed",
) )
end end
def self.create_small_action_for_tag_changes(topic:, user:, added_tags:, removed_tags:) def self.create_small_action_for_tag_changes(topic:, user:, added_tags:, removed_tags:)
return if !SiteSetting.create_post_for_category_and_tag_changes if !SiteSetting.create_post_for_category_and_tag_changes ||
SiteSetting.whispers_allowed_groups.blank?
return
end
topic.add_moderator_post( topic.add_moderator_post(
user, user,
tags_changed_raw(added: added_tags, removed: removed_tags), tags_changed_raw(added: added_tags, removed: removed_tags),
post_type: Post.types[:small_action], post_type: Post.types[:whisper],
action_code: "tags_changed", action_code: "tags_changed",
custom_fields: { custom_fields: {
tags_added: added_tags, tags_added: added_tags,

View File

@ -233,7 +233,10 @@ RSpec.describe PostRevisor do
fab!(:tag1) { Fabricate(:tag, name: "First tag") } fab!(:tag1) { Fabricate(:tag, name: "First tag") }
fab!(:tag2) { Fabricate(:tag, name: "Second tag") } fab!(:tag2) { Fabricate(:tag, name: "Second tag") }
before { SiteSetting.create_post_for_category_and_tag_changes = true } before do
SiteSetting.create_post_for_category_and_tag_changes = true
SiteSetting.whispers_allowed_groups = Group::AUTO_GROUPS[:staff]
end
it "Creates a small_action post with correct translation when both adding and removing tags" do it "Creates a small_action post with correct translation when both adding and removing tags" do
post.topic.update!(tags: [tag1]) post.topic.update!(tags: [tag1])
@ -292,6 +295,16 @@ RSpec.describe PostRevisor do
) )
end end
it "Creates a small_action as a whisper when category is changed" do
category = Fabricate(:category)
expect { post_revisor.revise!(admin, category_id: category.id) }.to change {
Post.where(topic_id: post.topic_id, action_code: "category_changed").count
}.by(1)
expect(post.topic.ordered_posts.last.post_type).to eq(Post.types[:whisper])
end
describe "with PMs" do describe "with PMs" do
fab!(:pm) { Fabricate(:private_message_topic) } fab!(:pm) { Fabricate(:private_message_topic) }
let(:first_post) { create_post(user: admin, topic: pm, allow_uncategorized_topics: false) } let(:first_post) { create_post(user: admin, topic: pm, allow_uncategorized_topics: false) }