Fix UserBookmarkSerializer topic references

This commit is contained in:
Martin Brennan 2020-03-13 11:10:48 +10:00
parent e7d5c88c8b
commit baba785b44
1 changed files with 3 additions and 3 deletions

View File

@ -240,19 +240,19 @@ after_initialize do
if defined? UserBookmarkSerializer
add_to_class(:user_bookmark_serializer, :assigned_to_user_id) do
id = object.topic.custom_fields[TopicAssigner::ASSIGNED_TO_ID]
id = topic.custom_fields[TopicAssigner::ASSIGNED_TO_ID]
# a bit messy but race conditions can give us an array here, avoid
id && id.to_i rescue nil
end
add_to_serializer(:user_bookmark, :assigned_to_user, false) do
DiscourseAssign::Helpers.build_assigned_to_user(assigned_to_user_id, object.topic)
DiscourseAssign::Helpers.build_assigned_to_user(assigned_to_user_id, topic)
end
add_to_serializer(:user_bookmark, 'include_assigned_to_user?') do
if SiteSetting.assigns_public || scope.can_assign?
# subtle but need to catch cases where stuff is not assigned
object.topic.custom_fields.keys.include?(TopicAssigner::ASSIGNED_TO_ID)
topic.custom_fields.keys.include?(TopicAssigner::ASSIGNED_TO_ID)
end
end
end