FEATURE: Add assigned to user to bookmark serializers (#62)

Add assigned to user to bookmark serializers, and also add to JS bookmark model for the route to assigned user.
This commit is contained in:
Martin Brennan 2020-03-12 15:21:48 +10:00 committed by GitHub
parent 32653be260
commit e7d5c88c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -143,6 +143,18 @@ function initialize(api) {
} }
}); });
api.modifyClass("model:bookmark", {
@computed("assigned_to_user")
assignedToUserPath(assignedToUser) {
return Discourse.getURL(
this.siteSettings.assigns_user_url_path.replace(
"{username}",
assignedToUser.username
)
);
}
});
api.addPostSmallActionIcon("assigned", "user-plus"); api.addPostSmallActionIcon("assigned", "user-plus");
api.addPostSmallActionIcon("unassigned", "user-times"); api.addPostSmallActionIcon("unassigned", "user-times");

View File

@ -238,6 +238,25 @@ after_initialize do
end end
end end
if defined? UserBookmarkSerializer
add_to_class(:user_bookmark_serializer, :assigned_to_user_id) do
id = object.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)
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)
end
end
end
add_to_serializer(:current_user, :can_assign) do add_to_serializer(:current_user, :can_assign) do
object.can_assign? object.can_assign?
end end