debian-mirror-gitlab/app/services/projects/participants_service.rb

49 lines
1.3 KiB
Ruby
Raw Normal View History

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