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-17 04:43:55 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2017-11-23 16:34:34 +0300
commit392cc887097bfd0c28b547700b9a67c32cf14e69 (patch)
treec63c9bb1b2420f0140371ccd90e91c173b1e274c /lib/api/namespaces.rb
parentb8db9c8c8c406d4abc03ba7246bbfecbecfbc784 (diff)
Add new API endpoint - get a namespace by ID
Diffstat (limited to 'lib/api/namespaces.rb')
-rw-r--r--lib/api/namespaces.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/api/namespaces.rb b/lib/api/namespaces.rb
index f1eaff6b0eb..21dc5009d0e 100644
--- a/lib/api/namespaces.rb
+++ b/lib/api/namespaces.rb
@@ -19,6 +19,30 @@ module API
present paginate(namespaces), with: Entities::Namespace, current_user: current_user
end
+
+ desc 'Get a namespace by ID' do
+ success Entities::Namespace
+ end
+ params do
+ requires :id, type: Integer, desc: "Namespace's ID"
+ end
+ get ':id' do
+ namespace = Namespace.find(params[:id])
+ authenticate_get_namespace!(namespace)
+
+ present namespace, with: Entities::Namespace, current_user: current_user
+ end
+ end
+
+ helpers do
+ def authenticate_get_namespace!(namespace)
+ return if current_user.admin?
+ forbidden!('No access granted') unless user_can_access_namespace?(namespace)
+ end
+
+ def user_can_access_namespace?(namespace)
+ namespace.has_owner?(current_user)
+ end
end
end
end