Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
392cc887
Commit
392cc887
authored
Nov 17, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new API endpoint - get a namespace by ID
parent
b8db9c8c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
0 deletions
+125
-0
doc/api/namespaces.md
doc/api/namespaces.md
+32
-0
lib/api/namespaces.rb
lib/api/namespaces.rb
+24
-0
spec/requests/api/namespaces_spec.rb
spec/requests/api/namespaces_spec.rb
+69
-0
No files found.
doc/api/namespaces.md
View file @
392cc887
...
@@ -89,3 +89,35 @@ Example response:
...
@@ -89,3 +89,35 @@ Example response:
}
}
]
]
```
```
## Get namespace by ID
Get a namespace by ID.
```
GET /namespaces/:id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer | yes | ID of the namespace |
Example request:
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/namespaces/2
```
Example response:
```
json
{
"id"
:
2
,
"name"
:
"group1"
,
"path"
:
"group1"
,
"kind"
:
"group"
,
"full_path"
:
"group1"
,
"parent_id"
:
"null"
,
"members_count_with_descendants"
:
2
}
```
lib/api/namespaces.rb
View file @
392cc887
...
@@ -19,6 +19,30 @@ module API
...
@@ -19,6 +19,30 @@ module API
present
paginate
(
namespaces
),
with:
Entities
::
Namespace
,
current_user:
current_user
present
paginate
(
namespaces
),
with:
Entities
::
Namespace
,
current_user:
current_user
end
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
end
end
end
spec/requests/api/namespaces_spec.rb
View file @
392cc887
...
@@ -91,4 +91,73 @@ describe API::Namespaces do
...
@@ -91,4 +91,73 @@ describe API::Namespaces do
end
end
end
end
end
end
describe
'GET /namespaces/:id'
do
let
(
:owned_group
)
{
group1
}
shared_examples
'namespace reader'
do
before
do
owned_group
.
add_owner
(
request_actor
)
end
context
'when namespace exists'
do
it
'returns namespace details'
do
get
api
(
"/namespaces/
#{
owned_group
.
id
}
"
,
request_actor
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
owned_group
.
id
)
expect
(
json_response
[
'name'
]).
to
eq
(
owned_group
.
name
)
end
end
context
"when namespace doesn't exist"
do
it
'returns not-found'
do
get
api
(
'/namespaces/9999'
,
request_actor
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'when unauthenticated'
do
it
'returns authentication error'
do
get
api
(
"/namespaces/
#{
group1
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'when authenticated as regular user'
do
let
(
:request_actor
)
{
user
}
context
'when requested namespace is not owned by user'
do
it
'returns authentication error'
do
get
api
(
"/namespaces/
#{
group2
.
id
}
"
,
request_actor
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'when requested namespace is owned by user'
do
it_behaves_like
'namespace reader'
end
end
context
'when authenticated as admin'
do
let
(
:request_actor
)
{
admin
}
context
'when requested namespace is not owned by user'
do
it
'returns authentication error'
do
get
api
(
"/namespaces/
#{
group2
.
id
}
"
,
request_actor
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'when requested namespace is owned by user'
do
it_behaves_like
'namespace reader'
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment