gitlab-org--gitlab-foss/app/services/projects/participants_service.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

module Projects
class ParticipantsService < BaseService
def execute(note_type, note_id)
2015-02-03 05:38:50 +00:00
participating =
if note_type && note_id
participants_in(note_type, note_id)
else
[]
end
2015-03-27 11:58:23 +00:00
project_members = sorted(project.team.members)
participants = all_members + groups + project_members + participating
participants.uniq
end
def participants_in(type, id)
target =
2015-04-17 09:03:33 +00:00
case type
when "Issue"
project.issues.find_by_iid(id)
2015-04-17 09:03:33 +00:00
when "MergeRequest"
project.merge_requests.find_by_iid(id)
2015-04-17 09:03:33 +00:00
when "Commit"
project.commit(id)
2015-04-17 09:03:33 +00:00
end
return [] unless target
2015-04-17 09:03:33 +00:00
users = target.participants(current_user)
sorted(users)
end
def sorted(users)
users.uniq.to_a.compact.sort_by(&:username).map do |user|
{ username: user.username, name: user.name }
end
end
def groups
2015-03-27 11:58:23 +00:00
current_user.authorized_groups.sort_by(&:path).map do |group|
count = group.users.count
{ username: group.path, name: group.name, count: count }
end
end
def all_members
2015-03-27 11:58:23 +00:00
count = project.team.members.flatten.count
[{ username: "all", name: "All Project and Group Members", count: count }]
end
end
end