Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb20
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)