FIX: don't show members of a group in the user summary

This commit is contained in:
Régis Hanol 2015-12-08 11:55:34 +01:00
parent 4b036bb7bf
commit b09ee9cb82

View file

@ -66,14 +66,17 @@ class TopicViewSerializer < ApplicationSerializer
}
if object.topic.private_message?
result[:allowed_users] = object.topic.allowed_users.map do |user|
BasicUserSerializer.new(user, scope: scope, root: false)
end
end
allowed_user_ids = Set.new
if object.topic.private_message?
result[:allowed_groups] = object.topic.allowed_groups.map do |ag|
BasicGroupSerializer.new(ag, scope: scope, root: false)
result[:allowed_groups] = object.topic.allowed_groups.map do |group|
allowed_user_ids.merge(GroupUser.where(group: group).pluck(:user_id))
BasicGroupSerializer.new(group, scope: scope, root: false)
end
result[:allowed_users] = object.topic.allowed_users.select do |user|
!allowed_user_ids.include?(user.id)
end.map do |user|
BasicUserSerializer.new(user, scope: scope, root: false)
end
end
@ -83,7 +86,6 @@ class TopicViewSerializer < ApplicationSerializer
end
end
if object.suggested_topics.try(:topics).present?
result[:suggested_topics] = object.suggested_topics.topics.map do |user|
SuggestedTopicSerializer.new(user, scope: scope, root: false)