Put owner and participating people first
This commit is contained in:
parent
178dfb1917
commit
562c9652d6
1 changed files with 25 additions and 16 deletions
|
@ -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 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
|
||||
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
|
||||
|
||||
users = target.participants(current_user)
|
||||
def target_owner
|
||||
[{
|
||||
name: @target.author.name,
|
||||
username: @target.author.username
|
||||
}]
|
||||
end
|
||||
|
||||
def participants_in(type, id)
|
||||
return [] unless @target
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue