Commit 6b270432 authored by James Edwards-Jones's avatar James Edwards-Jones

Protected Tags EE merge fixes

parent d2560ed6
...@@ -29,6 +29,10 @@ class Projects::ProtectedBranchesController < Projects::ProtectedRefsController ...@@ -29,6 +29,10 @@ class Projects::ProtectedBranchesController < Projects::ProtectedRefsController
self.protected_ref = @project.protected_branches.find(params[:id]) self.protected_ref = @project.protected_branches.find(params[:id])
end end
def access_levels
[:merge_access_levels, :push_access_levels]
end
def protected_ref_params def protected_ref_params
params.require(:protected_branch).permit(:name, params.require(:protected_branch).permit(:name,
merge_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id], merge_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id],
......
...@@ -28,7 +28,7 @@ class Projects::ProtectedRefsController < Projects::ApplicationController ...@@ -28,7 +28,7 @@ class Projects::ProtectedRefsController < Projects::ApplicationController
if protected_ref.valid? if protected_ref.valid?
respond_to do |format| respond_to do |format|
format.json { render json: protected_ref, status: :ok, include: [:merge_access_levels, :push_access_levels] } format.json { render json: protected_ref, status: :ok, include: access_levels }
end end
else else
respond_to do |format| respond_to do |format|
......
...@@ -29,6 +29,10 @@ class Projects::ProtectedTagsController < Projects::ProtectedRefsController ...@@ -29,6 +29,10 @@ class Projects::ProtectedTagsController < Projects::ProtectedRefsController
self.protected_ref = @project.protected_tags.find(params[:id]) self.protected_ref = @project.protected_tags.find(params[:id])
end end
def access_levels
[:create_access_levels]
end
def protected_ref_params def protected_ref_params
params.require(:protected_tag).permit(:name, create_access_levels_attributes: [:access_level, :id]) params.require(:protected_tag).permit(:name, create_access_levels_attributes: [:access_level, :id])
end end
......
...@@ -126,7 +126,7 @@ module Gitlab ...@@ -126,7 +126,7 @@ module Gitlab
push_rule = project.push_rule push_rule = project.push_rule
# Prevent tag removal # Prevent tag removal
if Gitlab::Git.tag_name(@ref) if @tag_name
if tag_deletion_denied_by_push_rule?(push_rule) if tag_deletion_denied_by_push_rule?(push_rule)
return 'You cannot delete a tag' return 'You cannot delete a tag'
end end
...@@ -134,7 +134,7 @@ module Gitlab ...@@ -134,7 +134,7 @@ module Gitlab
commit_validation = push_rule.try(:commit_validation?) commit_validation = push_rule.try(:commit_validation?)
# if newrev is blank, the branch was deleted # if newrev is blank, the branch was deleted
return if Gitlab::Git.blank_ref?(@newrev) || !(commit_validation || validate_path_locks?) return if deletion? || !(commit_validation || validate_path_locks?)
commits.each do |commit| commits.each do |commit|
if commit_validation if commit_validation
...@@ -154,8 +154,8 @@ module Gitlab ...@@ -154,8 +154,8 @@ module Gitlab
def tag_deletion_denied_by_push_rule?(push_rule) def tag_deletion_denied_by_push_rule?(push_rule)
push_rule.try(:deny_delete_tag) && push_rule.try(:deny_delete_tag) &&
protocol != 'web' && protocol != 'web' &&
Gitlab::Git.blank_ref?(@newrev) && deletion? &&
protected_tag?(Gitlab::Git.tag_name(@ref)) tag_exists?
end end
# If commit does not pass push rule validation the whole push should be rejected. # If commit does not pass push rule validation the whole push should be rejected.
......
...@@ -38,11 +38,9 @@ RSpec.shared_examples "protected branches > access control > EE" do ...@@ -38,11 +38,9 @@ RSpec.shared_examples "protected branches > access control > EE" do
click_on "Protect" click_on "Protect"
within(".js-protected-branch-edit-form") do set_allowed_to(git_operation, users.map(&:name), form: ".js-protected-branch-edit-form")
set_allowed_to(git_operation, users.map(&:name)) set_allowed_to(git_operation, groups.map(&:name), form: ".js-protected-branch-edit-form")
set_allowed_to(git_operation, groups.map(&:name)) set_allowed_to(git_operation, roles.values, form: ".js-protected-branch-edit-form")
set_allowed_to(git_operation, roles.values)
end
wait_for_ajax wait_for_ajax
......
...@@ -9,7 +9,8 @@ feature 'Protected Branches', feature: true, js: true do ...@@ -9,7 +9,8 @@ feature 'Protected Branches', feature: true, js: true do
before { login_as(user) } before { login_as(user) }
def set_allowed_to(operation, option = 'Masters') def set_allowed_to(operation, option = 'Masters', form: '#new_protected_branch')
within form do
find(".js-allowed-to-#{operation}").click find(".js-allowed-to-#{operation}").click
wait_for_ajax wait_for_ajax
...@@ -17,6 +18,7 @@ feature 'Protected Branches', feature: true, js: true do ...@@ -17,6 +18,7 @@ feature 'Protected Branches', feature: true, js: true do
find(".js-allowed-to-#{operation}").click # needed to submit form in some cases find(".js-allowed-to-#{operation}").click # needed to submit form in some cases
end end
end
def set_protected_branch_name(branch_name) def set_protected_branch_name(branch_name)
find(".js-protected-branch-select").click find(".js-protected-branch-select").click
......
...@@ -144,16 +144,12 @@ describe Gitlab::Checks::ChangeAccess, lib: true do ...@@ -144,16 +144,12 @@ describe Gitlab::Checks::ChangeAccess, lib: true do
end end
context 'tag deletion' do context 'tag deletion' do
let(:changes) do
{
oldrev: 'be93687618e4b132087f430a4d8fc3a609c9b77c',
newrev: '0000000000000000000000000000000000000000',
ref: 'refs/tags/v1.0.0'
}
end
let(:push_rule) { create(:push_rule, deny_delete_tag: true) } let(:push_rule) { create(:push_rule, deny_delete_tag: true) }
let(:oldrev) { 'be93687618e4b132087f430a4d8fc3a609c9b77c' }
let(:newrev) { '0000000000000000000000000000000000000000' }
let(:ref) { 'refs/tags/v1.0.0' }
before { allow(user_access).to receive(:can_do_action?).with(:admin_project).and_return(true) } before { project.add_master(user) }
it 'returns an error if the rule denies tag deletion' do it 'returns an error if the rule denies tag deletion' do
expect(subject.status).to be(false) expect(subject.status).to be(false)
......
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