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