Commit 55723c22 authored by Douwe Maan's avatar Douwe Maan

Move magic '_any' string to constant

parent 28cffb9f
...@@ -80,9 +80,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController ...@@ -80,9 +80,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController
end end
def access_check def access_check
# Use the magic string '_any' to indicate we do not know what the access.check(git_command, Gitlab::GitAccess::ANY)
# changes are. This is also what gitlab-shell does.
access.check(git_command, '_any')
@project ||= access.project @project ||= access.project
end end
......
...@@ -12,6 +12,10 @@ module Gitlab ...@@ -12,6 +12,10 @@ module Gitlab
TimeoutError = Class.new(StandardError) TimeoutError = Class.new(StandardError)
ProjectMovedError = Class.new(NotFoundError) ProjectMovedError = Class.new(NotFoundError)
# Use the magic string '_any' to indicate we do not know what the
# changes are. This is also what gitlab-shell does.
ANY = '_any'
ERROR_MESSAGES = { ERROR_MESSAGES = {
upload: 'You are not allowed to upload code for this project.', upload: 'You are not allowed to upload code for this project.',
download: 'You are not allowed to download code from this project.', download: 'You are not allowed to download code from this project.',
...@@ -199,7 +203,7 @@ module Gitlab ...@@ -199,7 +203,7 @@ module Gitlab
def ensure_project_on_push!(cmd, changes) def ensure_project_on_push!(cmd, changes)
return if project || deploy_key? return if project || deploy_key?
return unless receive_pack?(cmd) && changes == '_any' && authentication_abilities.include?(:push_code) return unless receive_pack?(cmd) && changes == ANY && authentication_abilities.include?(:push_code)
namespace = Namespace.find_by_full_path(namespace_path) namespace = Namespace.find_by_full_path(namespace_path)
......
...@@ -14,7 +14,7 @@ describe Gitlab::GitAccess do ...@@ -14,7 +14,7 @@ describe Gitlab::GitAccess do
let(:authentication_abilities) { %i[read_project download_code push_code] } let(:authentication_abilities) { %i[read_project download_code push_code] }
let(:redirected_path) { nil } let(:redirected_path) { nil }
let(:auth_result_type) { nil } let(:auth_result_type) { nil }
let(:changes) { '_any' } let(:changes) { Gitlab::GitAccess::ANY }
let(:push_access_check) { access.check('git-receive-pack', changes) } let(:push_access_check) { access.check('git-receive-pack', changes) }
let(:pull_access_check) { access.check('git-upload-pack', changes) } let(:pull_access_check) { access.check('git-upload-pack', changes) }
...@@ -437,7 +437,7 @@ describe Gitlab::GitAccess do ...@@ -437,7 +437,7 @@ describe Gitlab::GitAccess do
let(:project) { nil } let(:project) { nil }
context 'when changes is _any' do context 'when changes is _any' do
let(:changes) { '_any' } let(:changes) { Gitlab::GitAccess::ANY }
context 'when authentication abilities include push code' do context 'when authentication abilities include push code' do
let(:authentication_abilities) { [:push_code] } let(:authentication_abilities) { [:push_code] }
...@@ -483,7 +483,7 @@ describe Gitlab::GitAccess do ...@@ -483,7 +483,7 @@ describe Gitlab::GitAccess do
end end
context 'when project exists' do context 'when project exists' do
let(:changes) { '_any' } let(:changes) { Gitlab::GitAccess::ANY }
let!(:project) { create(:project) } let!(:project) { create(:project) }
it 'does not create a new project' do it 'does not create a new project' do
...@@ -497,7 +497,7 @@ describe Gitlab::GitAccess do ...@@ -497,7 +497,7 @@ describe Gitlab::GitAccess do
let(:project_path) { "nonexistent" } let(:project_path) { "nonexistent" }
let(:project) { nil } let(:project) { nil }
let(:namespace_path) { user.namespace.path } let(:namespace_path) { user.namespace.path }
let(:changes) { '_any' } let(:changes) { Gitlab::GitAccess::ANY }
it 'does not create a new project' do it 'does not create a new project' do
expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count } expect { access.send(:ensure_project_on_push!, cmd, changes) }.not_to change { Project.count }
...@@ -507,7 +507,7 @@ describe Gitlab::GitAccess do ...@@ -507,7 +507,7 @@ describe Gitlab::GitAccess do
context 'when pull' do context 'when pull' do
let(:cmd) { 'git-upload-pack' } let(:cmd) { 'git-upload-pack' }
let(:changes) { '_any' } let(:changes) { Gitlab::GitAccess::ANY }
context 'when project does not exist' do context 'when project does not exist' do
let(:project_path) { "new-project" } let(:project_path) { "new-project" }
......
...@@ -38,7 +38,7 @@ describe Gitlab::GitAccessWiki do ...@@ -38,7 +38,7 @@ describe Gitlab::GitAccessWiki do
end end
describe '#access_check_download!' do describe '#access_check_download!' do
subject { access.check('git-upload-pack', '_any') } subject { access.check('git-upload-pack', Gitlab::GitAccess::ANY) }
before do before do
project.add_developer(user) project.add_developer(user)
......
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