diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-09 12:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-09 12:07:45 +0000 |
commit | ac1dca43baa7b3b1ac7d60d89ad60fdeefed0b80 (patch) | |
tree | 33aa23ddf7f18ddbfba3d006041c460de88583b7 /lib/api/helpers.rb | |
parent | f4186a753b86625a83e8499af14b5badd63a2ac2 (diff) | |
download | gitlab-ce-ac1dca43baa7b3b1ac7d60d89ad60fdeefed0b80.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 6c3b8cb8dd8..c3b5654e217 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -142,6 +142,12 @@ module API end end + def check_namespace_access(namespace) + return namespace if can?(current_user, :read_namespace, namespace) + + not_found!('Namespace') + end + # rubocop: disable CodeReuse/ActiveRecord def find_namespace(id) if id.to_s =~ /^\d+$/ @@ -153,13 +159,15 @@ module API # rubocop: enable CodeReuse/ActiveRecord def find_namespace!(id) - namespace = find_namespace(id) + check_namespace_access(find_namespace(id)) + end - if can?(current_user, :read_namespace, namespace) - namespace - else - not_found!('Namespace') - end + def find_namespace_by_path(path) + Namespace.find_by_full_path(path) + end + + def find_namespace_by_path!(path) + check_namespace_access(find_namespace_by_path(path)) end def find_branch!(branch_name) |