diff options
author | Alfredo Sumaran <alfredo@gitlab.com> | 2016-03-29 18:39:25 -0500 |
---|---|---|
committer | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2016-04-16 07:21:28 -0400 |
commit | 562c9652d687bb03d0aa5b744016946d7a293a82 (patch) | |
tree | 00fa3db893264593ea7d50ace21b80403cf2e382 /app/services/projects/participants_service.rb | |
parent | 178dfb191798701be59a0a1c7a988565e437abc0 (diff) | |
download | gitlab-ce-562c9652d687bb03d0aa5b744016946d7a293a82.tar.gz |
Put owner and participating people first
Diffstat (limited to 'app/services/projects/participants_service.rb')
-rw-r--r-- | app/services/projects/participants_service.rb | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb index 0004a399f47..ba88ba73c35 100644 --- a/app/services/projects/participants_service.rb +++ b/app/services/projects/participants_service.rb @@ -1,6 +1,7 @@ module Projects class ParticipantsService < BaseService def execute(note_type, note_id) + @target = get_target(note_type, note_id) participating = if note_type && note_id participants_in(note_type, note_id) @@ -8,35 +9,43 @@ module Projects [] end project_members = sorted(project.team.members) - participants = all_members + groups + project_members + participating + participants = target_owner + participating + all_members + groups + project_members participants.uniq end + def get_target(type, id) + case type + when "Issue" + project.issues.find_by_iid(id) + when "MergeRequest" + project.merge_requests.find_by_iid(id) + when "Commit" + project.commit(id) + end + end + + def target_owner + [{ + name: @target.author.name, + username: @target.author.username + }] + end + def participants_in(type, id) - target = - case type - when "Issue" - project.issues.find_by_iid(id) - when "MergeRequest" - project.merge_requests.find_by_iid(id) - when "Commit" - project.commit(id) - end - - return [] unless target + return [] unless @target - users = target.participants(current_user) + users = @target.participants(current_user) sorted(users) end def sorted(users) - users.uniq.to_a.compact.sort_by(&:username).map do |user| + users.uniq.to_a.compact.sort_by(&:username).map do |user| { username: user.username, name: user.name } end end def groups - current_user.authorized_groups.sort_by(&:path).map do |group| + current_user.authorized_groups.sort_by(&:path).map do |group| count = group.users.count { username: group.path, name: group.name, count: count } end |