Add GroupFinder for collection all groups user has access to
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
70a6af9328
commit
4ca6ebf017
1 changed files with 38 additions and 0 deletions
38
app/finders/groups_finder.rb
Normal file
38
app/finders/groups_finder.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
class GroupsFinder
|
||||||
|
def execute(current_user, options = {})
|
||||||
|
all_groups(current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def all_groups(current_user)
|
||||||
|
if current_user
|
||||||
|
if current_user.authorized_groups.any?
|
||||||
|
# User has access to groups
|
||||||
|
#
|
||||||
|
# Return only:
|
||||||
|
# groups with public projects
|
||||||
|
# groups with internal projects
|
||||||
|
# groups with joined projects
|
||||||
|
#
|
||||||
|
group_ids = Project.public_and_internal_only.pluck(:namespace_id) +
|
||||||
|
current_user.authorized_groups.pluck(:id)
|
||||||
|
Group.where(id: group_ids)
|
||||||
|
else
|
||||||
|
# User has no group membership
|
||||||
|
#
|
||||||
|
# Return only:
|
||||||
|
# groups with public projects
|
||||||
|
# groups with internal projects
|
||||||
|
#
|
||||||
|
Group.where(id: Project.public_and_internal_only.pluck(:namespace_id))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Not authenticated
|
||||||
|
#
|
||||||
|
# Return only:
|
||||||
|
# groups with public projects
|
||||||
|
Group.where(id: Project.public_only.pluck(:namespace_id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue