diff --git a/plugin.rb b/plugin.rb index 0a7ab98..aa71e11 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 diff --git a/spec/serializers/topic_list_serializer_spec.rb b/spec/serializers/topic_list_serializer_spec.rb index 1ef0cb8..4d69661 100644 --- a/spec/serializers/topic_list_serializer_spec.rb +++ b/spec/serializers/topic_list_serializer_spec.rb @@ -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