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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
e6f34523
Commit
e6f34523
authored
Jul 09, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds with_projects optional parameter to /groups/:id API endpoint
parent
21a511e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
5 deletions
+55
-5
changelogs/unreleased/42415-omit-projects-from-get-group-endpoint.yml
...nreleased/42415-omit-projects-from-get-group-endpoint.yml
+5
-0
doc/api/groups.md
doc/api/groups.md
+25
-0
lib/api/groups.rb
lib/api/groups.rb
+2
-1
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+23
-4
No files found.
changelogs/unreleased/42415-omit-projects-from-get-group-endpoint.yml
0 → 100644
View file @
e6f34523
---
title
:
Adds with_projects optional parameter to GET /groups/:id API endpoint
merge_request
:
20494
author
:
type
:
changed
doc/api/groups.md
View file @
e6f34523
...
@@ -210,6 +210,7 @@ Parameters:
...
@@ -210,6 +210,7 @@ Parameters:
| --------- | ---- | -------- | ----------- |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the group
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the group
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`with_custom_attributes`
| boolean | no | Include
[
custom attributes
](
custom_attributes.md
)
in response (admins only) |
|
`with_custom_attributes`
| boolean | no | Include
[
custom attributes
](
custom_attributes.md
)
in response (admins only) |
|
`with_projects`
| boolean | no | Include details from projects that belong to the specified group (defaults to
`true`
). |
```
bash
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/groups/4
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/groups/4
...
@@ -361,6 +362,30 @@ Example response:
...
@@ -361,6 +362,30 @@ Example response:
}
}
```
```
When adding the parameter
`with_projects=false`
, projects will not be returned.
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/groups/4?with_projects
=
false
```
Example response:
```
json
{
"id"
:
4
,
"name"
:
"Twitter"
,
"path"
:
"twitter"
,
"description"
:
"Aliquid qui quis dignissimos distinctio ut commodi voluptas est."
,
"visibility"
:
"public"
,
"avatar_url"
:
null
,
"web_url"
:
"https://gitlab.example.com/groups/twitter"
,
"request_access_enabled"
:
false
,
"full_name"
:
"Twitter"
,
"full_path"
:
"twitter"
,
"parent_id"
:
null
}
```
## New group
## New group
Creates a new project group. Available only for users who can create groups.
Creates a new project group. Available only for users who can create groups.
...
...
lib/api/groups.rb
View file @
e6f34523
...
@@ -150,12 +150,13 @@ module API
...
@@ -150,12 +150,13 @@ module API
end
end
params
do
params
do
use
:with_custom_attributes
use
:with_custom_attributes
optional
:with_projects
,
type:
Boolean
,
default:
true
,
desc:
'Omit project details'
end
end
get
":id"
do
get
":id"
do
group
=
find_group!
(
params
[
:id
])
group
=
find_group!
(
params
[
:id
])
options
=
{
options
=
{
with:
Entities
::
GroupDetail
,
with:
params
[
:with_projects
]
?
Entities
::
GroupDetail
:
Entities
::
Group
,
current_user:
current_user
current_user:
current_user
}
}
...
...
spec/requests/api/groups_spec.rb
View file @
e6f34523
...
@@ -251,14 +251,22 @@ describe API::Groups do
...
@@ -251,14 +251,22 @@ describe API::Groups do
projects
projects
end
end
def
response_project_ids
(
json_response
,
key
)
json_response
[
key
].
map
do
|
project
|
project
[
'id'
].
to_i
end
end
context
'when unauthenticated'
do
context
'when unauthenticated'
do
it
'returns 404 for a private group'
do
it
'returns 404 for a private group'
do
get
api
(
"/groups/
#{
group2
.
id
}
"
)
get
api
(
"/groups/
#{
group2
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
it
'returns 200 for a public group'
do
it
'returns 200 for a public group'
do
get
api
(
"/groups/
#{
group1
.
id
}
"
)
get
api
(
"/groups/
#{
group1
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
...
@@ -268,7 +276,7 @@ describe API::Groups do
...
@@ -268,7 +276,7 @@ describe API::Groups do
get
api
(
"/groups/
#{
public_group
.
id
}
"
)
get
api
(
"/groups/
#{
public_group
.
id
}
"
)
expect
(
json_response
[
'projects'
].
map
{
|
p
|
p
[
'id'
].
to_i
}
)
expect
(
response_project_ids
(
json_response
,
'projects'
)
)
.
to
contain_exactly
(
projects
[
:public
].
id
)
.
to
contain_exactly
(
projects
[
:public
].
id
)
end
end
...
@@ -278,7 +286,7 @@ describe API::Groups do
...
@@ -278,7 +286,7 @@ describe API::Groups do
get
api
(
"/groups/
#{
group1
.
id
}
"
)
get
api
(
"/groups/
#{
group1
.
id
}
"
)
expect
(
json_response
[
'shared_projects'
].
map
{
|
p
|
p
[
'id'
].
to_i
}
)
expect
(
response_project_ids
(
json_response
,
'shared_projects'
)
)
.
to
contain_exactly
(
projects
[
:public
].
id
)
.
to
contain_exactly
(
projects
[
:public
].
id
)
end
end
end
end
...
@@ -309,6 +317,17 @@ describe API::Groups do
...
@@ -309,6 +317,17 @@ describe API::Groups do
expect
(
json_response
[
'shared_projects'
][
0
][
'id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'shared_projects'
][
0
][
'id'
]).
to
eq
(
project
.
id
)
end
end
it
"returns one of user1's groups without projects when with_projects option is set to false"
do
project
=
create
(
:project
,
namespace:
group2
,
path:
'Foo'
)
create
(
:project_group_link
,
project:
project
,
group:
group1
)
get
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
with_projects:
false
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'projects'
]).
to
be_nil
expect
(
json_response
[
'shared_projects'
]).
to
be_nil
end
it
"does not return a non existing group"
do
it
"does not return a non existing group"
do
get
api
(
"/groups/1328"
,
user1
)
get
api
(
"/groups/1328"
,
user1
)
...
@@ -327,7 +346,7 @@ describe API::Groups do
...
@@ -327,7 +346,7 @@ describe API::Groups do
get
api
(
"/groups/
#{
public_group
.
id
}
"
,
user2
)
get
api
(
"/groups/
#{
public_group
.
id
}
"
,
user2
)
expect
(
json_response
[
'projects'
].
map
{
|
p
|
p
[
'id'
].
to_i
}
)
expect
(
response_project_ids
(
json_response
,
'projects'
)
)
.
to
contain_exactly
(
projects
[
:public
].
id
,
projects
[
:internal
].
id
)
.
to
contain_exactly
(
projects
[
:public
].
id
,
projects
[
:internal
].
id
)
end
end
...
@@ -337,7 +356,7 @@ describe API::Groups do
...
@@ -337,7 +356,7 @@ describe API::Groups do
get
api
(
"/groups/
#{
group1
.
id
}
"
,
user2
)
get
api
(
"/groups/
#{
group1
.
id
}
"
,
user2
)
expect
(
json_response
[
'shared_projects'
].
map
{
|
p
|
p
[
'id'
].
to_i
}
)
expect
(
response_project_ids
(
json_response
,
'shared_projects'
)
)
.
to
contain_exactly
(
projects
[
:public
].
id
,
projects
[
:internal
].
id
)
.
to
contain_exactly
(
projects
[
:public
].
id
,
projects
[
:internal
].
id
)
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