Fix missing avatars on topic list page.

Introduced in b50fab2d72
This commit is contained in:
Guo Xiang Tan 2018-11-19 14:54:40 +08:00
parent 1a9a2bd5c1
commit fe131c5ea2
4 changed files with 36 additions and 24 deletions

View File

@ -14,17 +14,11 @@ module TopicTagsMixin
if scope.is_staff?
tags
else
tags - (@options[:hidden_tag_names] || hidden_tag_names)
tags - scope.hidden_tag_names
end
end
def topic
object.is_a?(Topic) ? object : object.topic
end
private
def hidden_tag_names
@hidden_tag_names ||= DiscourseTagging.hidden_tag_names(scope)
end
end

View File

@ -9,27 +9,12 @@ class TopicListSerializer < ApplicationSerializer
:per_page,
:top_tags,
:tags,
:shared_drafts,
:topics
:shared_drafts
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
has_many :tags, serializer: TagSerializer, embed: :objects
def topics
opts = {
scope: scope,
root: false
}
if SiteSetting.tagging_enabled && !scope.is_staff?
opts.merge!(hidden_tag_names: DiscourseTagging.hidden_tag_names(scope))
end
object.topics.map do |topic|
TopicListItemSerializer.new(topic, opts)
end
end
def can_create_topic
scope.can_create?(Topic)
end

View File

@ -23,4 +23,14 @@ module TagGuardian
def can_admin_tag_groups?
is_staff? && SiteSetting.tagging_enabled
end
def hidden_tag_names
@hidden_tag_names ||= begin
if SiteSetting.tagging_enabled && !is_staff?
DiscourseTagging.hidden_tag_names(self)
else
[]
end
end
end
end

View File

@ -0,0 +1,23 @@
require 'rails_helper'
RSpec.describe TopicListSerializer do
let(:user) { Fabricate(:user) }
let(:topic) do
Fabricate(:topic).tap do |t|
t.allowed_user_ids = [t.user_id]
end
end
it 'should return the right payload' do
topic_list = TopicList.new(nil, user, [topic])
serialized = described_class.new(topic_list,
scope: Guardian.new(user)
).as_json
expect(serialized[:users].first[:id]).to eq(topic.user_id)
expect(serialized[:primar_groups]).to eq([])
expect(serialized[:topic_list][:topics].first[:id]).to eq(topic.id)
end
end