Class: Projects::ParticipantsService

Inherits:
BaseService show all
Defined in:
app/services/projects/participants_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#all_membersObject


54
55
56
57
# File 'app/services/projects/participants_service.rb', line 54

def all_members
  count = project.team.members.flatten.count
  [{ username: "all", name: "All Project and Group Members", count: count }]
end

#execute(noteable_type, noteable_id) ⇒ Object


3
4
5
6
7
8
9
# File 'app/services/projects/participants_service.rb', line 3

def execute(noteable_type, noteable_id)
  @noteable_type = noteable_type
  @noteable_id = noteable_id
  project_members = sorted(project.team.members)
  participants = target_owner + participants_in_target + all_members + groups + project_members
  participants.uniq
end

#groupsObject


47
48
49
50
51
52
# File 'app/services/projects/participants_service.rb', line 47

def groups
  current_user.authorized_groups.sort_by(&:path).map do |group|
    count = group.users.count
    { username: group.path, name: group.name, count: count }
  end
end

#participants_in_targetObject


34
35
36
37
38
39
# File 'app/services/projects/participants_service.rb', line 34

def participants_in_target
  return [] unless target

  users = target.participants(current_user)
  sorted(users)
end

#sorted(users) ⇒ Object


41
42
43
44
45
# File 'app/services/projects/participants_service.rb', line 41

def sorted(users)
  users.uniq.to_a.compact.sort_by(&:username).map do |user|
    { username: user.username, name: user.name }
  end
end

#targetObject


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/projects/participants_service.rb', line 11

def target
  @target ||=
    case @noteable_type
    when "Issue"
      project.issues.find_by_iid(@noteable_id)
    when "MergeRequest"
      project.merge_requests.find_by_iid(@noteable_id)
    when "Commit"
      project.commit(@noteable_id)
    else
      nil
    end
end

#target_ownerObject


25
26
27
28
29
30
31
32
# File 'app/services/projects/participants_service.rb', line 25

def target_owner
  return [] unless target && target.author.present?

  [{
    name: target.author.name,
    username: target.author.username
  }]
end