summaryrefslogtreecommitdiff
path: root/app/models/review.rb
blob: 5a30e2963c8f063c83a5b811eaa280c02cf74b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class Review < ApplicationRecord
  include Participable
  include Mentionable

  belongs_to :author, class_name: 'User', foreign_key: :author_id, inverse_of: :reviews
  belongs_to :merge_request, inverse_of: :reviews
  belongs_to :project, inverse_of: :reviews

  has_many :notes, -> { order(:id) }, inverse_of: :review

  delegate :name, to: :author, prefix: true

  participant :author

  def all_references(current_user = nil, extractor: nil)
    ext = super

    notes.each do |note|
      note.all_references(current_user, extractor: ext)
    end

    ext
  end

  def user_mentions
    merge_request.user_mentions.where.not(note_id: nil)
  end
end