parent
1a9a2bd5c1
commit
fe131c5ea2
|
@ -14,17 +14,11 @@ module TopicTagsMixin
|
||||||
if scope.is_staff?
|
if scope.is_staff?
|
||||||
tags
|
tags
|
||||||
else
|
else
|
||||||
tags - (@options[:hidden_tag_names] || hidden_tag_names)
|
tags - scope.hidden_tag_names
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic
|
def topic
|
||||||
object.is_a?(Topic) ? object : object.topic
|
object.is_a?(Topic) ? object : object.topic
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def hidden_tag_names
|
|
||||||
@hidden_tag_names ||= DiscourseTagging.hidden_tag_names(scope)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,27 +9,12 @@ class TopicListSerializer < ApplicationSerializer
|
||||||
:per_page,
|
:per_page,
|
||||||
:top_tags,
|
:top_tags,
|
||||||
:tags,
|
:tags,
|
||||||
:shared_drafts,
|
:shared_drafts
|
||||||
:topics
|
|
||||||
|
|
||||||
|
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
|
||||||
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
|
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
|
||||||
has_many :tags, serializer: TagSerializer, 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
|
def can_create_topic
|
||||||
scope.can_create?(Topic)
|
scope.can_create?(Topic)
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,4 +23,14 @@ module TagGuardian
|
||||||
def can_admin_tag_groups?
|
def can_admin_tag_groups?
|
||||||
is_staff? && SiteSetting.tagging_enabled
|
is_staff? && SiteSetting.tagging_enabled
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue