2014-06-23 09:44:49 -04:00
|
|
|
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)
|
2015-03-13 11:22:03 -04:00
|
|
|
participants = all_members + groups + project_members + participating
|
2014-06-23 09:44:49 -04:00
|
|
|
participants.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def participants_in(type, id)
|
2015-04-21 09:15:49 -04:00
|
|
|
target =
|
2015-04-17 05:03:33 -04:00
|
|
|
case type
|
|
|
|
when "Issue"
|
2015-04-21 09:15:49 -04:00
|
|
|
project.issues.find_by_iid(id)
|
2015-04-17 05:03:33 -04:00
|
|
|
when "MergeRequest"
|
2015-04-21 09:15:49 -04:00
|
|
|
project.merge_requests.find_by_iid(id)
|
2015-04-17 05:03:33 -04:00
|
|
|
when "Commit"
|
2015-04-21 09:15:49 -04:00
|
|
|
project.commit(id)
|
2015-04-17 05:03:33 -04:00
|
|
|
end
|
2015-04-21 09:15:49 -04:00
|
|
|
|
|
|
|
return [] unless target
|
2015-04-17 05:03:33 -04:00
|
|
|
|
2015-04-21 09:15:49 -04:00
|
|
|
users = target.participants(current_user)
|
2014-06-23 09:44:49 -04:00
|
|
|
sorted(users)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted(users)
|
2015-02-25 11:34:01 -05:00
|
|
|
users.uniq.to_a.compact.sort_by(&:username).map do |user|
|
|
|
|
{ username: user.username, name: user.name }
|
|
|
|
end
|
2014-06-23 09:44:49 -04:00
|
|
|
end
|
|
|
|
|
2015-02-04 11:10:39 -05:00
|
|
|
def groups
|
2015-03-27 07:58:23 -04:00
|
|
|
current_user.authorized_groups.sort_by(&:path).map do |group|
|
2015-02-25 11:34:01 -05:00
|
|
|
count = group.users.count
|
2015-06-02 08:56:50 -04:00
|
|
|
{ username: group.path, name: group.name, count: count }
|
2015-02-25 11:34:01 -05:00
|
|
|
end
|
2015-02-04 11:10:39 -05:00
|
|
|
end
|
|
|
|
|
2014-06-23 09:44:49 -04:00
|
|
|
def all_members
|
2015-03-27 07:58:23 -04:00
|
|
|
count = project.team.members.flatten.count
|
2015-06-02 08:56:50 -04:00
|
|
|
[{ username: "all", name: "All Project and Group Members", count: count }]
|
2014-06-23 09:44:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|