From 55de145736dd7b40f0f670e5c4692a74abe82271 Mon Sep 17 00:00:00 2001 From: Alex Lossent Date: Thu, 9 Jun 2016 17:29:40 +0200 Subject: [PATCH] Make sure that Group.last_owner? returns up-to-date information Group.last_owner? is used by the LDAP sync process to detect when a user is the last owner and should not be removed or demoted. The new LDAP group sync introduced in 8.7 manipulates several times the group member list using a single instance of the group object, and if last_owner? uses cached information then the result is not up to date and the last owner can be removed from the group. --- app/models/group.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/group.rb b/app/models/group.rb index eb5c666554627b..03cc58e928c407 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -135,7 +135,8 @@ def has_master?(user) end def last_owner?(user) - has_owner?(user) && owners.size == 1 + # make sure not to use cached information + members.owners.size == 1 && members.owners.where(user_id: user).any? end def avatar_type -- GitLab