Module: Participable

Extended by:
ActiveSupport::Concern
Included in:
AwardEmoji, Commit, DesignManagement::Design, Issuable, Note, Review, 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.

Usage:

class Issue < ApplicationRecord
  include Participable

  # ...

  participant :author
  participant :assignee
  participant :notes

  participant -> (current_user, ext) do
    ext.analyze('...')
  end
end

issue = Issue.last
users = issue.participants

Instance Method Summary collapse

Instance Method Details

#participant?(user) ⇒ Boolean

Checks if the user is a participant in a discussion.

This method processes attributes of objects in breadth-first order.

Returns a Boolean.

Returns:

  • (Boolean)


75
76
77
78
# File 'app/models/concerns/participable.rb', line 75

def participant?(user)
  can_read_participable?(user) &&
    all_participants_hash[user].include?(user)
end

#participants(user = nil) ⇒ Object

Returns the users participating in a discussion.

This method processes attributes of objects in breadth-first order.

Returns an Array of User instances.



59
60
61
# File 'app/models/concerns/participable.rb', line 59

def participants(user = nil)
  filtered_participants_hash[user]
end

#visible_participants(user) ⇒ Object

Returns only participants visible for the user

Returns an Array of User instances.



66
67
68
# File 'app/models/concerns/participable.rb', line 66

def visible_participants(user)
  filter_by_ability(raw_participants(user, verify_access: true))
end