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

53 lines
1.4 KiB
Ruby
Raw Normal View History

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