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