Commit 41526de5 authored by Mark Chao's avatar Mark Chao

Split namespace check out of project check

For group wiki which only need namespace check.
parent 4786fe61
...@@ -24,6 +24,7 @@ module Gitlab ...@@ -24,6 +24,7 @@ module Gitlab
deploy_key_upload: 'This deploy key does not have write access to this project.', deploy_key_upload: 'This deploy key does not have write access to this project.',
no_repo: 'A repository for this project does not exist yet.', no_repo: 'A repository for this project does not exist yet.',
project_not_found: 'The project you were looking for could not be found.', project_not_found: 'The project you were looking for could not be found.',
namespace_not_found: 'The namespace you were looking for could not be found.',
command_not_allowed: "The command you're trying to execute is not allowed.", command_not_allowed: "The command you're trying to execute is not allowed.",
upload_pack_disabled_over_http: 'Pulling over HTTP is not allowed.', upload_pack_disabled_over_http: 'Pulling over HTTP is not allowed.',
receive_pack_disabled_over_http: 'Pushing over HTTP is not allowed.', receive_pack_disabled_over_http: 'Pushing over HTTP is not allowed.',
...@@ -73,6 +74,7 @@ module Gitlab ...@@ -73,6 +74,7 @@ module Gitlab
return custom_action if custom_action return custom_action if custom_action
check_db_accessibility!(cmd) check_db_accessibility!(cmd)
check_namespace!
check_project!(changes, cmd) check_project!(changes, cmd)
check_repository_existence! check_repository_existence!
...@@ -111,7 +113,6 @@ module Gitlab ...@@ -111,7 +113,6 @@ module Gitlab
private private
def check_project!(changes, cmd) def check_project!(changes, cmd)
check_namespace!
ensure_project_on_push!(cmd, changes) ensure_project_on_push!(cmd, changes)
check_project_accessibility! check_project_accessibility!
add_project_moved_message! add_project_moved_message!
...@@ -156,7 +157,7 @@ module Gitlab ...@@ -156,7 +157,7 @@ module Gitlab
def check_namespace! def check_namespace!
return if namespace_path.present? return if namespace_path.present?
raise NotFoundError, ERROR_MESSAGES[:project_not_found] raise NotFoundError, ERROR_MESSAGES[:namespace_not_found]
end end
def check_active_user! def check_active_user!
......
...@@ -39,11 +39,17 @@ module Gitlab ...@@ -39,11 +39,17 @@ module Gitlab
private private
override :check_namespace!
def check_namespace!
return unless snippet.is_a?(ProjectSnippet)
super
end
override :check_project! override :check_project!
def check_project!(cmd, changes) def check_project!(cmd, changes)
return unless snippet.is_a?(ProjectSnippet) return unless snippet.is_a?(ProjectSnippet)
check_namespace!
check_project_accessibility! check_project_accessibility!
add_project_moved_message! add_project_moved_message!
end end
......
...@@ -10,7 +10,7 @@ describe Gitlab::GitAccess do ...@@ -10,7 +10,7 @@ describe Gitlab::GitAccess do
let(:actor) { user } let(:actor) { user }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:project_path) { project.path } let(:project_path) { project&.path }
let(:namespace_path) { project&.namespace&.path } let(:namespace_path) { project&.namespace&.path }
let(:protocol) { 'ssh' } let(:protocol) { 'ssh' }
let(:authentication_abilities) { %i[read_project download_code push_code] } let(:authentication_abilities) { %i[read_project download_code push_code] }
...@@ -89,13 +89,14 @@ describe Gitlab::GitAccess do ...@@ -89,13 +89,14 @@ describe Gitlab::GitAccess do
end end
end end
context 'when namespace does not exist' do context 'when namespace and project are nil' do
let(:project) { nil }
let(:namespace_path) { nil } let(:namespace_path) { nil }
it 'does not allow push and pull access' do it 'does not allow push and pull access' do
aggregate_failures do aggregate_failures do
expect { push_access_check }.to raise_not_found expect { push_access_check }.to raise_namespace_not_found
expect { pull_access_check }.to raise_not_found expect { pull_access_check }.to raise_namespace_not_found
end end
end end
end end
...@@ -228,13 +229,6 @@ describe Gitlab::GitAccess do ...@@ -228,13 +229,6 @@ describe Gitlab::GitAccess do
let(:project) { nil } let(:project) { nil }
let(:project_path) { "new-project" } let(:project_path) { "new-project" }
it 'blocks push and pull with "not found"' do
aggregate_failures do
expect { pull_access_check }.to raise_not_found
expect { push_access_check }.to raise_not_found
end
end
context 'when user is allowed to create project in namespace' do context 'when user is allowed to create project in namespace' do
let(:namespace_path) { user.namespace.path } let(:namespace_path) { user.namespace.path }
let(:access) do let(:access) do
...@@ -1219,6 +1213,10 @@ describe Gitlab::GitAccess do ...@@ -1219,6 +1213,10 @@ describe Gitlab::GitAccess do
raise_error(Gitlab::GitAccess::NotFoundError, Gitlab::GitAccess::ERROR_MESSAGES[:project_not_found]) raise_error(Gitlab::GitAccess::NotFoundError, Gitlab::GitAccess::ERROR_MESSAGES[:project_not_found])
end end
def raise_namespace_not_found
raise_error(Gitlab::GitAccess::NotFoundError, Gitlab::GitAccess::ERROR_MESSAGES[:namespace_not_found])
end
def build_authentication_abilities def build_authentication_abilities
[ [
:read_project, :read_project,
......
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