2017-03-03 05:35:04 -05:00
|
|
|
# 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)
|
2016-03-21 18:11:24 -04:00
|
|
|
@group = group
|
2016-03-20 16:03:53 -04:00
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
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
|
2017-03-03 05:35:04 -05:00
|
|
|
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
|
2017-03-03 05:35:04 -05:00
|
|
|
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
|
2017-03-03 05:35:04 -05:00
|
|
|
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
|
2017-03-03 05:35:04 -05:00
|
|
|
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
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
def union(items)
|
|
|
|
find_union(items, Project)
|
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|