FIX: Include `assigned_messages_count` only when viewing assigned list.
This commit is contained in:
parent
e48ed99dfe
commit
4e53bf1962
|
@ -162,8 +162,10 @@ after_initialize do
|
|||
add_to_serializer(:topic_list, 'include_assigned_messages_count?') do
|
||||
options = object.instance_variable_get(:@opts)
|
||||
|
||||
if assigned_user = options.dig(:assigned)
|
||||
scope.is_staff? ||
|
||||
options.dig(:assigned)&.downcase == scope.current_user&.username_lower
|
||||
assigned_user.downcase == scope.current_user&.username_lower
|
||||
end
|
||||
end
|
||||
|
||||
add_to_serializer(:topic_view, :assigned_to_user, false) do
|
||||
|
|
|
@ -45,7 +45,40 @@ RSpec.describe TopicListSerializer do
|
|||
.to eq(1)
|
||||
end
|
||||
|
||||
describe 'when not viewing assigned list' do
|
||||
let(:topic_list) do
|
||||
TopicQuery.new(user).list_private_messages_assigned(user)
|
||||
end
|
||||
|
||||
describe 'as an admin user' do
|
||||
let(:guardian) { Guardian.new(Fabricate(:admin)) }
|
||||
|
||||
it 'should not include the attribute' do
|
||||
expect(serializer.as_json[:topic_list][:assigned_messages_count])
|
||||
.to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'as an anon user' do
|
||||
let(:guardian) { Guardian.new }
|
||||
|
||||
it 'should not include the attribute' do
|
||||
expect(serializer.as_json[:topic_list][:assigned_messages_count])
|
||||
.to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'viewing another user' do
|
||||
describe 'as an anon user' do
|
||||
let(:guardian) { Guardian.new }
|
||||
|
||||
it 'should not include the attribute' do
|
||||
expect(serializer.as_json[:topic_list][:assigned_messages_count])
|
||||
.to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'as a staff' do
|
||||
let(:guardian) { Guardian.new(Fabricate(:admin)) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue