2014-06-23 09:44:49 -04:00
|
|
|
module Projects
|
|
|
|
class ParticipantsService < BaseService
|
2016-08-12 21:17:18 -04:00
|
|
|
attr_reader :noteable
|
2016-10-13 13:40:06 -04:00
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
def execute(noteable)
|
|
|
|
@noteable = noteable
|
2016-08-12 05:19:29 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
project_members = sorted(project.team.members)
|
2016-08-12 21:17:18 -04:00
|
|
|
participants = noteable_owner + participants_in_noteable + all_members + groups + project_members
|
2014-06-23 09:44:49 -04:00
|
|
|
participants.uniq
|
|
|
|
end
|
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
def noteable_owner
|
|
|
|
return [] unless noteable && noteable.author.present?
|
2016-03-30 17:29:42 -04:00
|
|
|
|
2016-03-29 19:39:25 -04:00
|
|
|
[{
|
2016-08-12 21:17:18 -04:00
|
|
|
name: noteable.author.name,
|
2016-10-13 13:40:06 -04:00
|
|
|
username: noteable.author.username,
|
|
|
|
avatar_url: noteable.author.avatar_url
|
2016-03-29 19:39:25 -04:00
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
def participants_in_noteable
|
|
|
|
return [] unless noteable
|
2015-04-17 05:03:33 -04:00
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
users = noteable.participants(current_user)
|
2014-06-23 09:44:49 -04:00
|
|
|
sorted(users)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted(users)
|
2016-03-29 19:39:25 -04:00
|
|
|
users.uniq.to_a.compact.sort_by(&:username).map do |user|
|
2016-10-13 13:40:06 -04:00
|
|
|
{ username: user.username, name: user.name, avatar_url: user.avatar_url }
|
2015-02-25 11:34:01 -05:00
|
|
|
end
|
2014-06-23 09:44:49 -04:00
|
|
|
end
|
|
|
|
|
2015-02-04 11:10:39 -05:00
|
|
|
def groups
|
2016-03-29 19:39:25 -04:00
|
|
|
current_user.authorized_groups.sort_by(&:path).map do |group|
|
2015-02-25 11:34:01 -05:00
|
|
|
count = group.users.count
|
2017-02-13 06:26:33 -05:00
|
|
|
{ username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
|
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
|