Commit deefde90 authored by Sean McGivern's avatar Sean McGivern

Don't check if anonymous user can update MR

parent f663999b
...@@ -623,6 +623,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -623,6 +623,7 @@ class MergeRequest < ActiveRecord::Base
end end
def can_approve?(user) def can_approve?(user)
return false unless user
return true if approvers_left.include?(user) return true if approvers_left.include?(user)
return false if user == author return false if user == author
return false unless user.can?(:update_merge_request, self) return false unless user.can?(:update_merge_request, self)
......
...@@ -781,6 +781,10 @@ describe MergeRequest, models: true do ...@@ -781,6 +781,10 @@ describe MergeRequest, models: true do
it 'does not allow the approver to approve the MR' do it 'does not allow the approver to approve the MR' do
expect(merge_request.can_approve?(author)).to be_falsey expect(merge_request.can_approve?(author)).to be_falsey
end end
it 'does not allow a logged-out user to approve the MR' do
expect(merge_request.can_approve?(nil)).to be_falsey
end
end end
context 'when that approver is not the MR author' do context 'when that approver is not the MR author' do
...@@ -796,6 +800,10 @@ describe MergeRequest, models: true do ...@@ -796,6 +800,10 @@ describe MergeRequest, models: true do
it 'allows the approver to approve the MR' do it 'allows the approver to approve the MR' do
expect(merge_request.can_approve?(approver)).to be_truthy expect(merge_request.can_approve?(approver)).to be_truthy
end end
it 'does not allow a logged-out user to approve the MR' do
expect(merge_request.can_approve?(nil)).to be_falsey
end
end end
end end
end end
...@@ -834,6 +842,10 @@ describe MergeRequest, models: true do ...@@ -834,6 +842,10 @@ describe MergeRequest, models: true do
expect(merge_request.can_approve?(reporter)).to be_falsey expect(merge_request.can_approve?(reporter)).to be_falsey
expect(merge_request.can_approve?(stranger)).to be_falsey expect(merge_request.can_approve?(stranger)).to be_falsey
end end
it 'does not allow a logged-out user to approve the MR' do
expect(merge_request.can_approve?(nil)).to be_falsey
end
end end
context 'when that approver is not the MR author' do context 'when that approver is not the MR author' do
...@@ -850,6 +862,7 @@ describe MergeRequest, models: true do ...@@ -850,6 +862,7 @@ describe MergeRequest, models: true do
expect(merge_request.can_approve?(developer)).to be_falsey expect(merge_request.can_approve?(developer)).to be_falsey
expect(merge_request.can_approve?(reporter)).to be_falsey expect(merge_request.can_approve?(reporter)).to be_falsey
expect(merge_request.can_approve?(stranger)).to be_falsey expect(merge_request.can_approve?(stranger)).to be_falsey
expect(merge_request.can_approve?(nil)).to be_falsey
end end
end end
end end
...@@ -876,6 +889,10 @@ describe MergeRequest, models: true do ...@@ -876,6 +889,10 @@ describe MergeRequest, models: true do
expect(merge_request.can_approve?(approver)).to be_truthy expect(merge_request.can_approve?(approver)).to be_truthy
end end
it 'does not allow a logged-out user to approve the MR' do
expect(merge_request.can_approve?(nil)).to be_falsey
end
context 'when all of the valid approvers have approved the MR' do context 'when all of the valid approvers have approved the MR' do
before do before do
create(:approval, user: approver, merge_request: merge_request) create(:approval, user: approver, merge_request: merge_request)
...@@ -900,6 +917,7 @@ describe MergeRequest, models: true do ...@@ -900,6 +917,7 @@ describe MergeRequest, models: true do
expect(merge_request.can_approve?(reporter)).to be_falsey expect(merge_request.can_approve?(reporter)).to be_falsey
expect(merge_request.can_approve?(stranger)).to be_falsey expect(merge_request.can_approve?(stranger)).to be_falsey
expect(merge_request.can_approve?(nil)).to be_falsey
end end
end end
end end
...@@ -923,6 +941,7 @@ describe MergeRequest, models: true do ...@@ -923,6 +941,7 @@ describe MergeRequest, models: true do
expect(merge_request.can_approve?(author)).to be_falsey expect(merge_request.can_approve?(author)).to be_falsey
expect(merge_request.can_approve?(reporter)).to be_falsey expect(merge_request.can_approve?(reporter)).to be_falsey
expect(merge_request.can_approve?(stranger)).to be_falsey expect(merge_request.can_approve?(stranger)).to be_falsey
expect(merge_request.can_approve?(nil)).to be_falsey
end end
end 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