summaryrefslogtreecommitdiff
path: root/app/models/concerns/approvable_base.rb
blob: d07c4ec43ac9ec99dd9837adc46531e9bf99e378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

module ApprovableBase
  extend ActiveSupport::Concern

  included do
    has_many :approvals, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
    has_many :approved_by_users, through: :approvals, source: :user
  end

  def approved_by?(user)
    return false unless user

    approved_by_users.include?(user)
  end

  def can_be_approved_by?(user)
    user && !approved_by?(user) && user.can?(:approve_merge_request, self)
  end
end