diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-08 18:02:25 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-10 18:34:12 +0300 |
commit | 5f85487c1526f2921f1cef30aceb2fddf84d3632 (patch) | |
tree | fd2eeccef302f6ec04f85d1620cdfc8e4edf3c5e /app/finders/group_members_finder.rb | |
parent | 059d1ae4c847aa9018c89900b39c2782aa9b623e (diff) |
Show parent group members for nested group
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/finders/group_members_finder.rb')
-rw-r--r-- | app/finders/group_members_finder.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/finders/group_members_finder.rb b/app/finders/group_members_finder.rb new file mode 100644 index 00000000000..9f2206346ce --- /dev/null +++ b/app/finders/group_members_finder.rb @@ -0,0 +1,20 @@ +class GroupMembersFinder < Projects::ApplicationController + def initialize(group) + @group = group + end + + def execute + group_members = @group.members + + return group_members unless @group.parent + + parents_members = GroupMember.non_request. + where(source_id: @group.ancestors.select(:id)). + where.not(user_id: @group.users.select(:id)) + + wheres = ["members.id IN (#{group_members.select(:id).to_sql})"] + wheres << "members.id IN (#{parents_members.select(:id).to_sql})" + + GroupMember.where(wheres.join(' OR ')) + end +end |