2017-08-17 22:00:37 +05:30
|
|
|
# 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-06-02 11:05:42 +05:30
|
|
|
@group = group
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def init_collection
|
|
|
|
only_owned = options.fetch(:only_owned, false)
|
|
|
|
only_shared = options.fetch(:only_shared, false)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
projects = []
|
|
|
|
|
|
|
|
if current_user
|
2017-08-17 22:00:37 +05:30
|
|
|
if group.users.include?(current_user)
|
|
|
|
projects << group.projects unless only_shared
|
|
|
|
projects << group.shared_projects unless only_owned
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
|
|
|
unless only_shared
|
2017-08-17 22:00:37 +05:30
|
|
|
projects << group.projects.visible_to_user(current_user)
|
|
|
|
projects << group.projects.public_to_user(current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
unless only_owned
|
2017-08-17 22:00:37 +05:30
|
|
|
projects << group.shared_projects.visible_to_user(current_user)
|
|
|
|
projects << group.shared_projects.public_to_user(current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
projects << group.projects.public_only unless only_shared
|
|
|
|
projects << group.shared_projects.public_only unless only_owned
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
projects
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def union(items)
|
|
|
|
find_union(items, Project)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|