2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-06-23 13:44:49 +00:00
|
|
|
module Projects
|
|
|
|
class ParticipantsService < BaseService
|
2018-04-26 19:53:13 +00:00
|
|
|
include Users::ParticipableService
|
2016-10-13 17:40:06 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def execute(noteable)
|
|
|
|
@noteable = noteable
|
2016-08-12 09:19:29 +00:00
|
|
|
|
2019-07-04 17:17:06 +00:00
|
|
|
participants =
|
|
|
|
noteable_owner +
|
|
|
|
participants_in_noteable +
|
|
|
|
all_members +
|
|
|
|
groups +
|
|
|
|
project_members
|
|
|
|
|
2020-12-10 15:10:12 +00:00
|
|
|
render_participants_as_hash(participants.uniq)
|
2014-06-23 13:44:49 +00:00
|
|
|
end
|
|
|
|
|
2018-05-29 09:34:24 +00:00
|
|
|
def project_members
|
2019-07-04 17:17:06 +00:00
|
|
|
@project_members ||= sorted(get_project_members)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_project_members
|
|
|
|
members = Member.from_union([project_members_through_ancestral_groups,
|
|
|
|
project_members_through_invited_groups,
|
|
|
|
individual_project_members])
|
|
|
|
|
|
|
|
User.id_in(members.select(:user_id))
|
2018-05-29 09:34:24 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 13:44:49 +00:00
|
|
|
def all_members
|
2018-05-29 09:34:24 +00:00
|
|
|
[{ username: "all", name: "All Project and Group Members", count: project_members.count }]
|
2014-06-23 13:44:49 +00:00
|
|
|
end
|
2019-07-04 17:17:06 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_members_through_invited_groups
|
|
|
|
groups_with_ancestors_ids = Gitlab::ObjectHierarchy
|
|
|
|
.new(visible_groups)
|
|
|
|
.base_and_ancestors
|
|
|
|
.pluck_primary_key
|
|
|
|
|
|
|
|
GroupMember
|
|
|
|
.active_without_invites_and_requests
|
|
|
|
.with_source_id(groups_with_ancestors_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def visible_groups
|
|
|
|
visible_groups = project.invited_groups
|
|
|
|
|
|
|
|
unless project_owner?
|
|
|
|
visible_groups = visible_groups.public_or_visible_to_user(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
visible_groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_members_through_ancestral_groups
|
|
|
|
project.group.present? ? project.group.members_with_parents : Member.none
|
|
|
|
end
|
|
|
|
|
|
|
|
def individual_project_members
|
|
|
|
project.project_members
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_owner?
|
|
|
|
if project.group.present?
|
|
|
|
project.group.owners.include?(current_user)
|
|
|
|
else
|
|
|
|
project.namespace.owner == current_user
|
|
|
|
end
|
|
|
|
end
|
2014-06-23 13:44:49 +00:00
|
|
|
end
|
|
|
|
end
|