debian-mirror-gitlab/app/finders/groups_finder.rb

34 lines
695 B
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
class GroupsFinder < UnionFinder
2017-08-17 22:00:37 +05:30
def initialize(current_user = nil, params = {})
@current_user = current_user
@params = params
end
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
def execute
groups = find_union(all_groups, Group).with_route.order_id_desc
by_parent(groups)
2016-06-02 11:05:42 +05:30
end
private
2017-08-17 22:00:37 +05:30
attr_reader :current_user, :params
def all_groups
2016-06-02 11:05:42 +05:30
groups = []
2017-08-17 22:00:37 +05:30
if current_user
groups << Group.member_self_and_descendants(current_user.id)
groups << current_user.groups_through_project_authorizations
end
2016-06-02 11:05:42 +05:30
groups << Group.unscoped.public_to_user(current_user)
groups
end
2017-08-17 22:00:37 +05:30
def by_parent(groups)
return groups unless params[:parent]
groups.where(parent: params[:parent])
end
2016-06-02 11:05:42 +05:30
end