Commit 2b40c12c authored by Mark Chao's avatar Mark Chao

Compatibility switch for approval related methods

Only call ApprovalState when enabled
parent a94094a6
# frozen_string_literal: true
module ApprovableForRule
include VisibleApprovableForRule
FORWARDABLE_METHODS = %w{
approval_needed?
approved?
approvals_left
can_approve?
has_approved?
any_approver_allowed?
authors_can_approve?
}.freeze
FORWARDABLE_METHODS.each do |method|
define_method(method) do |*args|
return super(*args) if ::Feature.disabled?(:approval_rule)
approval_state.public_send(method, *args) # rubocop:disable GitlabSecurity/PublicSend
end
end
def approvers_overwritten?
return super if ::Feature.disabled?(:approval_rule)
approval_state.approval_rules_overwritten?
end
end
# frozen_string_literal: true
# This module may only be used by presenters or modules
# that include the Approvable concern
module VisibleApprovableForRule
def approvers_left
return super if ::Feature.disabled?(:approval_rule)
approval_state.unactioned_approvers
end
def overall_approvers(exclude_code_owners: false)
return super if ::Feature.disabled?(:approval_rule)
options = { target: :users }
options[:code_owner] = false if exclude_code_owners
approvers = approval_state.filtered_approvers(options)
approvers.uniq!
approvers
end
def all_approvers_including_groups
return super if ::Feature.disabled?(:approval_rule)
approval_state.approvers
end
def approvers_from_groups
return super if ::Feature.disabled?(:approval_rule)
groups = approval_state.wrapped_approval_rules.flat_map(&:groups)
User.joins(:group_members).where(members: { source_id: groups })
end
end
......@@ -7,6 +7,7 @@ module EE
include ::Approvable
include ::Gitlab::Utils::StrongMemoize
prepend ApprovableForRule
prepended do
include Elastic::MergeRequestsSearch
......
......@@ -3,6 +3,7 @@
module EE
module MergeRequestPresenter
include ::VisibleApprovable
prepend VisibleApprovableForRule
def approvals_path
if requires_approve?
......
......@@ -5,6 +5,10 @@ describe Approvable do
let(:project) { merge_request.project }
let(:author) { merge_request.author }
before do
stub_feature_flags(approval_rule: false)
end
describe '#approvers_overwritten?' do
subject { merge_request.approvers_overwritten? }
......
......@@ -5,6 +5,10 @@ describe VisibleApprovable do
let!(:project) { create(:project, :repository) }
let!(:user) { project.creator }
before do
stub_feature_flags(approval_rule: false)
end
describe '#requires_approve' do
subject { resource.requires_approve? }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment