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

48 lines
1.2 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
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,
username: noteable.author.username
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|
2015-04-26 12:48:37 +05:30
{ username: user.username, name: user.name }
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
2015-09-11 14:41:01 +05:30
{ username: group.path, name: group.name, count: count }
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