Commit bf470fc9 authored by Igor Drozdov's avatar Igor Drozdov

Allow to delete any-approval rule using API call

User defined rules are allowed to be deleted
parent 17389160
...@@ -50,4 +50,8 @@ module ApprovalRuleLike ...@@ -50,4 +50,8 @@ module ApprovalRuleLike
def any_approver? def any_approver?
raise NotImplementedError raise NotImplementedError
end end
def user_defined?
regular? || any_approver?
end
end end
...@@ -4,7 +4,7 @@ class ApprovalMergeRequestRulePolicy < BasePolicy ...@@ -4,7 +4,7 @@ class ApprovalMergeRequestRulePolicy < BasePolicy
delegate { @subject.merge_request } delegate { @subject.merge_request }
condition(:editable) do condition(:editable) do
can?(:update_merge_request, @subject.merge_request) && @subject.regular? can?(:update_merge_request, @subject.merge_request) && @subject.user_defined?
end end
rule { editable }.enable :edit_approval_rule rule { editable }.enable :edit_approval_rule
......
...@@ -15,7 +15,15 @@ describe ApprovalMergeRequestRulePolicy do ...@@ -15,7 +15,15 @@ describe ApprovalMergeRequestRulePolicy do
expect(permissions(merge_request.author, approval_rule)).to be_allowed(:edit_approval_rule) expect(permissions(merge_request.author, approval_rule)).to be_allowed(:edit_approval_rule)
end end
context 'when rule is not regular type' do context 'when rule is any-approval' do
let(:approval_rule) { build(:any_approver_rule, merge_request: merge_request) }
it 'allows updating approval rule' do
expect(permissions(merge_request.author, approval_rule)).to be_allowed(:edit_approval_rule)
end
end
context 'when rule is not user editable' do
let(:approval_rule) { create(:code_owner_rule, merge_request: merge_request) } let(:approval_rule) { create(:code_owner_rule, merge_request: merge_request) }
it 'disallows updating approval rule' do it 'disallows updating approval rule' do
......
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