diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-12-13 21:59:39 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-12-26 11:57:11 +0300 |
commit | 7b4b3d5f268534c028f55ef1014a84fe6a916cb0 (patch) | |
tree | 87408a9ae15c6263fbcfad84e97e2dc26446200b /app/models/group.rb | |
parent | 645412b57f558d58418aad278c9a3bf421439e1c (diff) |
Include group parents into read access for project and group
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index ac8a82c8c1e..50c949d84aa 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -155,15 +155,17 @@ class Group < Namespace end def has_owner?(user) - owners.include?(user) + members_with_parents.owners.where(user_id: user).any? end def has_master?(user) - members.masters.where(user_id: user).any? + members_with_parents.masters.where(user_id: user).any? end + # Check if user is a last owner of the group. + # Parent owners are ignored for nested groups. def last_owner?(user) - has_owner?(user) && owners.size == 1 + owners.include?(user) && owners.size == 1 end def avatar_type @@ -189,6 +191,14 @@ class Group < Namespace end def refresh_members_authorized_projects - UserProjectAccessChangedService.new(users.pluck(:id)).execute + UserProjectAccessChangedService.new(users_with_parents.pluck(:id)).execute + end + + def members_with_parents + GroupMember.where(requested_at: nil, source_id: parents.map(&:id).push(id)) + end + + def users_with_parents + User.where(id: members_with_parents.pluck(:user_id)) end end |