2020-07-15 18:09:09 +00:00
|
|
|
# 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
|
|
|
|
|
2020-07-16 15:09:38 +00:00
|
|
|
def approved_by?(user)
|
2020-07-15 18:09:09 +00:00
|
|
|
return false unless user
|
|
|
|
|
|
|
|
approved_by_users.include?(user)
|
|
|
|
end
|
2020-07-20 18:09:27 +00:00
|
|
|
|
|
|
|
def can_be_approved_by?(user)
|
|
|
|
user && !approved_by?(user) && user.can?(:approve_merge_request, self)
|
|
|
|
end
|
2020-07-15 18:09:09 +00:00
|
|
|
end
|