2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-26 17:04:55 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe PostRevisionSerializer do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:post) { Fabricate(:post, version: 2) }
|
2018-03-26 17:04:55 -04:00
|
|
|
|
|
|
|
context 'hidden tags' do
|
2019-05-06 23:12:20 -04: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 17:04:55 -04:00
|
|
|
|
|
|
|
let(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name, hidden_tag2.name]) }
|
|
|
|
|
|
|
|
let(:post_revision) do
|
|
|
|
Fabricate(:post_revision,
|
|
|
|
post: post,
|
|
|
|
modifications: { 'tags' => [['public', 'hidden'], ['visible', 'hidden']] }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:post_revision2) do
|
|
|
|
Fabricate(:post_revision,
|
|
|
|
post: post,
|
|
|
|
modifications: { 'tags' => [['visible', 'hidden', 'secret'], ['visible', 'hidden']] }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
staff_tag_group
|
|
|
|
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
|
|
|
|
expect(json[:tags_changes][:previous]).to include(public_tag.name)
|
|
|
|
expect(json[:tags_changes][:previous]).to include(hidden_tag.name)
|
|
|
|
expect(json[:tags_changes][:current]).to include(public_tag2.name)
|
|
|
|
expect(json[:tags_changes][:current]).to include(hidden_tag.name)
|
|
|
|
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
|
|
|
|
expect(json[:tags_changes][:previous]).to eq([public_tag.name])
|
|
|
|
expect(json[:tags_changes][:current]).to eq([public_tag2.name])
|
|
|
|
end
|
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
it 'does not show tag modifications if changes are not visible to the user' do
|
2018-03-26 17:04:55 -04:00
|
|
|
json = PostRevisionSerializer.new(post_revision2, scope: Guardian.new(Fabricate(:user)), root: false).as_json
|
|
|
|
expect(json[:tags_changes]).to_not be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|