2014-06-23 13:44:49 +00:00
|
|
|
module Projects
|
|
|
|
class ParticipantsService < BaseService
|
2016-08-13 01:17:18 +00:00
|
|
|
attr_reader :noteable
|
2016-10-13 17:40:06 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def execute(noteable)
|
|
|
|
@noteable = noteable
|
2016-08-12 09:19:29 +00:00
|
|
|
|
2015-03-27 11:58:23 +00:00
|
|
|
project_members = sorted(project.team.members)
|
2016-08-13 01:17:18 +00:00
|
|
|
participants = noteable_owner + participants_in_noteable + all_members + groups + project_members
|
2014-06-23 13:44:49 +00:00
|
|
|
participants.uniq
|
|
|
|
end
|
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def noteable_owner
|
|
|
|
return [] unless noteable && noteable.author.present?
|
2016-03-30 21:29:42 +00:00
|
|
|
|
2016-03-29 23:39:25 +00:00
|
|
|
[{
|
2016-08-13 01:17:18 +00:00
|
|
|
name: noteable.author.name,
|
2016-10-13 17:40:06 +00:00
|
|
|
username: noteable.author.username,
|
|
|
|
avatar_url: noteable.author.avatar_url
|
2016-03-29 23:39:25 +00:00
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def participants_in_noteable
|
|
|
|
return [] unless noteable
|
2015-04-17 09:03:33 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
users = noteable.participants(current_user)
|
2014-06-23 13:44:49 +00:00
|
|
|
sorted(users)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted(users)
|
2016-03-29 23:39:25 +00:00
|
|
|
users.uniq.to_a.compact.sort_by(&:username).map do |user|
|
2016-10-13 17:40:06 +00:00
|
|
|
{ username: user.username, name: user.name, avatar_url: user.avatar_url }
|
2015-02-25 16:34:01 +00:00
|
|
|
end
|
2014-06-23 13:44:49 +00:00
|
|
|
end
|
|
|
|
|
2015-02-04 16:10:39 +00:00
|
|
|
def groups
|
2016-03-29 23:39:25 +00:00
|
|
|
current_user.authorized_groups.sort_by(&:path).map do |group|
|
2015-02-25 16:34:01 +00:00
|
|
|
count = group.users.count
|
2016-10-13 17:40:06 +00:00
|
|
|
{ username: group.path, name: group.name, count: count, avatar_url: group.avatar.url }
|
2015-02-25 16:34:01 +00:00
|
|
|
end
|
2015-02-04 16:10:39 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 13:44:49 +00:00
|
|
|
def all_members
|
2015-03-27 11:58:23 +00:00
|
|
|
count = project.team.members.flatten.count
|
2015-06-02 12:56:50 +00:00
|
|
|
[{ username: "all", name: "All Project and Group Members", count: count }]
|
2014-06-23 13:44:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|