Skip to content

Commit 7426e61

Browse files
committed
Make sure it checks against the tag only when it's a tag
1 parent ef2e987 commit 7426e61

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/policies/ci/build_policy.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ class BuildPolicy < CommitStatusPolicy
55

66
access = ::Gitlab::UserAccess.new(@user, project: @subject.project)
77

8-
!access.can_merge_to_branch?(@subject.ref) ||
8+
if @subject.tag?
99
!access.can_create_tag?(@subject.ref)
10+
else
11+
!access.can_merge_to_branch?(@subject.ref)
12+
end
1013
end
1114

1215
rule { protected_action }.prevent :update_build

spec/policies/ci/build_policy_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,30 @@
138138
before do
139139
create(:protected_tag, :no_one_can_create,
140140
name: 'some-ref', project: project)
141+
142+
build.update(tag: true)
141143
end
142144

143145
it_behaves_like 'protected ref'
144146
end
145147

148+
context 'when build is against a protected tag but it is not a tag' do
149+
before do
150+
create(:protected_tag, :no_one_can_create,
151+
name: 'some-ref', project: project)
152+
end
153+
154+
context 'when build is a manual action' do
155+
let(:build) do
156+
create(:ci_build, :manual, ref: 'some-ref', pipeline: pipeline)
157+
end
158+
159+
it 'includes ability to update build' do
160+
expect(policy).to be_allowed :update_build
161+
end
162+
end
163+
end
164+
146165
context 'when branch build is assigned to is not protected' do
147166
context 'when build is a manual action' do
148167
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }

0 commit comments

Comments
 (0)