Member.add_user should check for an existing access request and remove the requested_at timestamp to make it a real/active member. Currently, it will silently fail to add the user as a member.
In addition to this behaviour, #830 (closed) questioned whether it made sense that users can request access to a group where LDAP sync is enabled. It seems users should request membership of the LDAP group instead (not via GitLab obviously). It may be that we still want to offer the possibility to request access in GitLab in order to notify group admins of the request, but then the notification text sent to admins should probably somehow take into account the fact that the user then has to be added to a LDAP group and it won't be possible to accept or reject the access request from the GitLab UI.
@DouweM This is an issue with Member.add_user not handling existing access requests. I thought it would be an easy fix but because of the current method signature it makes the problem a little bit more thorny.
Basically, members are passed to the method, and members do not included requesters. We could do something like:
member = members.first.source.requesters.find_by(user_id: user.id)member ||= members.find_or_initialize_by(user_id: user.id)
but that is really ugly and requires that the group/project have at least one member. If not, it all breaks down. So are we forced to rewrite the entire method and change the signature? If the group/project object was passed instead we could do it.
Any ideas how we can handle this? If we can't come up with a good permanent fix for 8.11, I'm inclined to add some hack to LDAP sync that looks for a requester first, deletes it (if present), and then goes forward with adding the user. I think the Member.add_user method should detect requests, though. Otherwise, we get a silent failure.
@dstanley Try this patch if you want to fix this now. Make the change in lib/gitlab/ldap/group_sync.rb (8.9 and lower) or lib/ee/gitlab/ldap/sync/group.rb (8.10).
defadd_or_update_user_membership(user,group,access)# Prevent the last owner of a group from being demotedifaccess<::Gitlab::Access::OWNER&&group.last_owner?(user)warn_cannot_remove_last_owner(user,group)elsemember=group.requesters.find_by(user_id: user.id)ifmember.present?member.requested_at=nilmember.saveelse# If you pass the user object, instead of just user ID,# it saves an extra user database query.group.add_users([user],access,skip_notification: true)endendend
member=group.requesters.find_by(user_id: user.id)ifmember.present?member.requested_at=nilmember.saveelse# If you pass the user object, instead of just user ID,# it saves an extra user database query.group.add_users([user],access,skip_notification: true)end
Drew BlessingChanged title: LDAP group sync doesn't add users that have requested access → {+Member.add_userdoesn't detect existing memb+}ers that have requested access
Changed title: LDAP group sync doesn't add users that have requested access → {+Member.add_userdoesn't detect existing memb+}ers that have requested access