Bulk adding members needs to consider user records as well as the ids
Problem
Currently we are observing existing members only if they are passed in as user_ids
(integers) here.
We need to also check for existing users if we only send in user
records as that is possible(not likely) via the methods that call this
Solution
Enhance this area of the code like so
if user_ids.present?
# we should handle the idea of existing members where users are passed as users -
# the below will automatically discard invalid user_ids
users.concat(User.id_in(user_ids))
end
if users.present?
# helps not have to perform another query per user id to see if the member exists later on when fetching
# also keeps from building users when one already exists
existing_members = source.members_and_requesters.where(user_id: users).index_by(&:user_id) # rubocop:disable CodeReuse/ActiveRecord
end