Commit 3b9d4255 authored by Mark Chao's avatar Mark Chao

Dry feature check into a method

parent 34c5a8db
...@@ -16,7 +16,7 @@ module ApprovableForRule ...@@ -16,7 +16,7 @@ module ApprovableForRule
FORWARDABLE_METHODS.each do |method| FORWARDABLE_METHODS.each do |method|
define_method(method) do |*args| define_method(method) do |*args|
return super(*args) if ::Feature.disabled?(:approval_rules, project) return super(*args) if approval_rules_disabled?
approval_state.public_send(method, *args) # rubocop:disable GitlabSecurity/PublicSend approval_state.public_send(method, *args) # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
# that include the Approvable concern # that include the Approvable concern
module VisibleApprovableForRule module VisibleApprovableForRule
def approvers_left def approvers_left
return super if ::Feature.disabled?(:approval_rules, project) return super if approval_rules_disabled?
approval_state.unactioned_approvers approval_state.unactioned_approvers
end end
def overall_approvers(exclude_code_owners: false) def overall_approvers(exclude_code_owners: false)
return super if ::Feature.disabled?(:approval_rules, project) return super if approval_rules_disabled?
options = { target: :users } options = { target: :users }
options[:code_owner] = false if exclude_code_owners options[:code_owner] = false if exclude_code_owners
...@@ -21,15 +21,19 @@ module VisibleApprovableForRule ...@@ -21,15 +21,19 @@ module VisibleApprovableForRule
end end
def all_approvers_including_groups def all_approvers_including_groups
return super if ::Feature.disabled?(:approval_rules, project) return super if approval_rules_disabled?
approval_state.approvers approval_state.approvers
end end
def approvers_from_groups def approvers_from_groups
return super if ::Feature.disabled?(:approval_rules, project) return super if approval_rules_disabled?
groups = approval_state.wrapped_approval_rules.flat_map(&:groups) groups = approval_state.wrapped_approval_rules.flat_map(&:groups)
User.joins(:group_members).where(members: { source_id: groups }) User.joins(:group_members).where(members: { source_id: groups })
end end
def approval_rules_disabled?
::Feature.disabled?(:approval_rules, project)
end
end end
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