gitlab-org--gitlab-foss/app/finders/group_projects_finder.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

# GroupProjectsFinder
#
# Used to filter Projects by set of params
#
# Arguments:
# current_user - which user use
# project_ids_relation: int[] - project ids to use
# group
# options:
# only_owned: boolean
# only_shared: boolean
# params:
# sort: string
# visibility_level: int
# tags: string[]
# personal: boolean
# search: string
# non_archived: boolean
#
class GroupProjectsFinder < ProjectsFinder
attr_reader :group, :options
def initialize(group:, params: {}, options: {}, current_user: nil, project_ids_relation: nil)
super(params: params, current_user: current_user, project_ids_relation: project_ids_relation)
@group = group
2016-03-20 16:03:53 -04:00
@options = options
end
private
def init_collection
only_owned = options.fetch(:only_owned, false)
only_shared = options.fetch(:only_shared, false)
2016-03-20 16:03:53 -04:00
projects = []
if current_user
if group.users.include?(current_user)
projects << group.projects unless only_shared
projects << group.shared_projects unless only_owned
2016-03-20 16:03:53 -04:00
else
2016-03-20 16:30:08 -04:00
unless only_shared
projects << group.projects.visible_to_user(current_user)
projects << group.projects.public_to_user(current_user)
2016-03-20 16:03:53 -04:00
end
2016-03-20 16:30:08 -04:00
unless only_owned
projects << group.shared_projects.visible_to_user(current_user)
projects << group.shared_projects.public_to_user(current_user)
2016-03-20 16:03:53 -04:00
end
end
else
projects << group.projects.public_only unless only_shared
projects << group.shared_projects.public_only unless only_owned
2016-03-20 16:03:53 -04:00
end
projects
end
def union(items)
find_union(items, Project)
end
2016-03-20 16:03:53 -04:00
end