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

49 lines
1.3 KiB
Ruby
Raw Normal View History

module Projects
class ParticipantsService < BaseService
2016-08-13 01:17:18 +00:00
attr_reader :noteable
2016-08-13 01:17:18 +00:00
def execute(noteable)
@noteable = noteable
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
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-08-13 01:17:18 +00:00
name: noteable.author.name,
username: noteable.author.username,
avatar_url: noteable.author.avatar_url
}]
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)
sorted(users)
end
def sorted(users)
users.uniq.to_a.compact.sort_by(&:username).map do |user|
{ username: user.username, name: user.name, avatar_url: user.avatar_url }
end
end
def groups
current_user.authorized_groups.sort_by(&:path).map do |group|
count = group.users.count
{ username: group.full_path, name: group.full_name, count: count, avatar_url: group.avatar_url }
end
end
def all_members
2015-03-27 11:58:23 +00:00
count = project.team.members.flatten.count
[{ username: "all", name: "All Project and Group Members", count: count }]
end
end
end