Show assigned messages count as long as assigns is enabled.

This commit is contained in:
Guo Xiang Tan 2018-05-24 10:51:04 +08:00
parent 863de29e1d
commit e48ed99dfe
2 changed files with 17 additions and 11 deletions

View File

@ -160,12 +160,10 @@ after_initialize do
end
add_to_serializer(:topic_list, 'include_assigned_messages_count?') do
return unless SiteSetting.assigns_public
options = object.instance_variable_get(:@opts)
if assigned_username = options[:assigned]&.downcase
assigned_username == object.current_user&.username_lower
end
scope.is_staff? ||
options.dig(:assigned)&.downcase == scope.current_user&.username_lower
end
add_to_serializer(:topic_view, :assigned_to_user, false) do

View File

@ -29,7 +29,6 @@ RSpec.describe TopicListSerializer do
before do
SiteSetting.assign_enabled = true
SiteSetting.assigns_public = true
end
describe '#assigned_messages_count' do
@ -46,14 +45,23 @@ RSpec.describe TopicListSerializer do
.to eq(1)
end
describe 'when assigns are not public' do
before do
SiteSetting.assigns_public = false
describe 'viewing another user' do
describe 'as a staff' do
let(:guardian) { Guardian.new(Fabricate(:admin)) }
it 'should include the right attribute' do
expect(serializer.as_json[:topic_list][:assigned_messages_count])
.to eq(1)
end
end
it 'should not include the attributes' do
expect(serializer.as_json[:topic_list][:assigned_messages_count])
.to eq(nil)
describe 'as a normal user' do
let(:guardian) { Guardian.new(Fabricate(:user)) }
it 'should not include the attribute' do
expect(serializer.as_json[:topic_list][:assigned_messages_count])
.to eq(nil)
end
end
end
end