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:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-11-23 16:32:16 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2017-11-23 19:44:05 +0300
commitdfbfd3c7d7d4677ac99a7f8147a673911e8d4e98 (patch)
tree7dfb3b813f9820fa539eb908dd1ca06719a63348 /lib/api/helpers.rb
parent5c2578e68177e0b5ba48f9d2931602747ad58c91 (diff)
Allow request namespace by ID or path
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index b26c61ab8da..52ac416f9ad 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -50,6 +50,10 @@ module API
initial_current_user != current_user
end
+ def user_namespace
+ @user_namespace ||= find_namespace!(params[:id])
+ end
+
def user_group
@group ||= find_group!(params[:id])
end
@@ -112,6 +116,24 @@ module API
end
end
+ def find_namespace(id)
+ if id.to_s =~ /^\d+$/
+ Namespace.find_by(id: id)
+ else
+ Namespace.find_by_full_path(id)
+ end
+ end
+
+ def find_namespace!(id)
+ namespace = find_namespace(id)
+
+ if can?(current_user, :admin_namespace, namespace)
+ namespace
+ else
+ not_found!('Namespace')
+ end
+ end
+
def find_project_label(id)
label = available_labels.find_by_id(id) || available_labels.find_by_title(id)
label || not_found!('Label')