debian-mirror-gitlab/app/services/projects/participants_service.rb

79 lines
2.1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Projects
class ParticipantsService < BaseService
2018-10-15 14:42:47 +05:30
include Users::ParticipableService
2017-08-17 22:00:37 +05:30
2016-09-13 17:45:13 +05:30
def execute(noteable)
@noteable = noteable
2019-10-31 01:37:42 +05:30
participants =
noteable_owner +
participants_in_noteable +
all_members +
groups +
project_members
2021-02-22 17:27:13 +05:30
render_participants_as_hash(participants.uniq)
2014-09-02 18:07:02 +05:30
end
2018-11-08 19:23:39 +05:30
def project_members
2019-10-31 01:37:42 +05:30
@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-11-08 19:23:39 +05:30
end
2014-09-02 18:07:02 +05:30
def all_members
2018-11-08 19:23:39 +05:30
[{ username: "all", name: "All Project and Group Members", count: project_members.count }]
2014-09-02 18:07:02 +05:30
end
2019-10-31 01:37:42 +05:30
private
def project_members_through_invited_groups
2021-11-18 22:05:49 +05:30
groups_with_ancestors = if ::Feature.enabled?(:linear_participants_service_ancestor_scopes, current_user, default_enabled: :yaml)
visible_groups.self_and_ancestors
else
Gitlab::ObjectHierarchy
.new(visible_groups)
.base_and_ancestors
end
2019-10-31 01:37:42 +05:30
GroupMember
.active_without_invites_and_requests
2021-11-18 22:05:49 +05:30
.with_source_id(groups_with_ancestors.pluck_primary_key)
2019-10-31 01:37:42 +05:30
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-09-02 18:07:02 +05:30
end
end