2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe PostRevisionSerializer do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:post) { Fabricate(:post, version: 2) }
|
2018-03-26 16:04:55 -05:00
|
|
|
|
2024-05-22 03:09:20 -05:00
|
|
|
context "with secured categories" do
|
|
|
|
fab!(:group)
|
|
|
|
fab!(:private_category) { Fabricate(:private_category, group: group) }
|
|
|
|
fab!(:post_revision) do
|
|
|
|
Fabricate(
|
|
|
|
:post_revision,
|
|
|
|
post: post,
|
|
|
|
modifications: {
|
|
|
|
"category_id" => [private_category.id, post.topic.category_id],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns category changes to staff" do
|
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(
|
|
|
|
post_revision,
|
|
|
|
scope: Guardian.new(Fabricate(:admin)),
|
|
|
|
root: false,
|
|
|
|
).as_json
|
|
|
|
|
|
|
|
expect(json[:category_id_changes][:previous]).to eq(private_category.id)
|
|
|
|
expect(json[:category_id_changes][:current]).to eq(post.topic.category_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return all category changes to non-staff" do
|
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(
|
|
|
|
post_revision,
|
|
|
|
scope: Guardian.new(Fabricate(:user)),
|
|
|
|
root: false,
|
|
|
|
).as_json
|
|
|
|
|
|
|
|
expect(json[:category_id_changes][:previous]).to eq(nil)
|
|
|
|
expect(json[:category_id_changes][:current]).to eq(post.topic.category_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-20 17:09:21 -05:00
|
|
|
it "handles tags not being an array" do
|
|
|
|
pr = Fabricate(:post_revision, post: post, modifications: { "tags" => ["[]", ""] })
|
|
|
|
|
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(pr, scope: Guardian.new(Fabricate(:user)), root: false).as_json
|
|
|
|
|
|
|
|
expect(json[:tags_changes][:previous]).to eq("[]")
|
|
|
|
expect(json[:tags_changes][:current]).to eq([])
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with hidden tags" do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:public_tag) { Fabricate(:tag, name: "public") }
|
|
|
|
fab!(:public_tag2) { Fabricate(:tag, name: "visible") }
|
|
|
|
fab!(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
|
|
|
fab!(:hidden_tag2) { Fabricate(:tag, name: "secret") }
|
2018-03-26 16:04:55 -05:00
|
|
|
|
2024-05-22 03:09:20 -05:00
|
|
|
fab!(:staff_tag_group) do
|
2018-03-26 16:04:55 -05:00
|
|
|
Fabricate(
|
|
|
|
:tag_group,
|
|
|
|
permissions: {
|
|
|
|
"staff" => 1,
|
|
|
|
},
|
|
|
|
tag_names: [hidden_tag.name, hidden_tag2.name],
|
|
|
|
)
|
2023-01-09 05:18:21 -06:00
|
|
|
end
|
2018-03-26 16:04:55 -05:00
|
|
|
|
|
|
|
let(:post_revision) do
|
|
|
|
Fabricate(
|
|
|
|
:post_revision,
|
|
|
|
post: post,
|
|
|
|
modifications: {
|
|
|
|
"tags" => [%w[public hidden], %w[visible hidden]],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:post_revision2) do
|
|
|
|
Fabricate(
|
|
|
|
:post_revision,
|
|
|
|
post: post,
|
|
|
|
modifications: {
|
|
|
|
"tags" => [%w[visible hidden secret], %w[visible hidden]],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
post.topic.tags = [public_tag2, hidden_tag]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns all tag changes to staff" do
|
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(
|
|
|
|
post_revision,
|
|
|
|
scope: Guardian.new(Fabricate(:admin)),
|
|
|
|
root: false,
|
|
|
|
).as_json
|
2024-05-22 03:09:20 -05:00
|
|
|
|
|
|
|
expect(json[:tags_changes][:previous]).to contain_exactly(public_tag.name, hidden_tag.name)
|
|
|
|
expect(json[:tags_changes][:current]).to contain_exactly(public_tag2.name, hidden_tag.name)
|
2018-03-26 16:04:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return hidden tags to non-staff" do
|
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(
|
|
|
|
post_revision,
|
|
|
|
scope: Guardian.new(Fabricate(:user)),
|
|
|
|
root: false,
|
|
|
|
).as_json
|
2024-05-22 03:09:20 -05:00
|
|
|
|
|
|
|
expect(json[:tags_changes][:previous]).to contain_exactly(public_tag.name)
|
|
|
|
expect(json[:tags_changes][:current]).to contain_exactly(public_tag2.name)
|
2018-03-26 16:04:55 -05:00
|
|
|
end
|
|
|
|
|
2021-05-20 20:43:47 -05:00
|
|
|
it "does not show tag modifications if changes are not visible to the user" do
|
2018-03-26 16:04:55 -05:00
|
|
|
json =
|
|
|
|
PostRevisionSerializer.new(
|
|
|
|
post_revision2,
|
|
|
|
scope: Guardian.new(Fabricate(:user)),
|
|
|
|
root: false,
|
|
|
|
).as_json
|
2024-05-22 03:09:20 -05:00
|
|
|
|
2018-03-26 16:04:55 -05:00
|
|
|
expect(json[:tags_changes]).to_not be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|