Module: Participable

Extended by:
ActiveSupport::Concern
Included in:
Commit, Issuable, Note, Snippet
Defined in:
app/models/concerns/participable.rb

Overview

Participable concern

Contains functionality related to objects that can have participants, such as an author, an assignee and people mentioned in its description or comments.

Used by Issue, Note, MergeRequest, Snippet and Commit.

Usage:

class Issue < ActiveRecord::Base
  include Participable

  # ...

  participant :author, :assignee, :notes, ->(current_user) { mentioned_users(current_user) }
end

issue = Issue.last
users = issue.participants
# `users` will contain the issue's author, its assignee,
# all users returned by its #mentioned_users method,
# as well as all participants to all of the issue's notes,
# since Note implements Participable as well.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#participants(current_user = self.author) ⇒ Object

Be aware that this method makes a lot of sql queries. Save result into variable if you are going to reuse it inside same request


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/concerns/participable.rb', line 40

def participants(current_user = self.author)
  participants =
    Gitlab::ReferenceExtractor.lazily do
      self.class.participant_attrs.flat_map do |attr|
        value =
          if attr.respond_to?(:call)
            instance_exec(current_user, &attr)
          else
            send(attr)
          end

        participants_for(value, current_user)
      end.compact.uniq
    end

  unless Gitlab::ReferenceExtractor.lazy?
    participants.select! do |user|
      user.can?(:read_project, project)
    end
  end

  participants
end