summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2017-02-07 17:42:37 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2017-02-08 12:42:34 +0200
commitdf974814fbbbf8f088f6bb480344cfdfcec6c1b2 (patch)
treed519ef0a930ed65b86b2ee39857772611a271e01
parent99fceff4f9e98cc7cb725882abec6e5b7c9b0170 (diff)
downloadgitlab-ce-df974814fbbbf8f088f6bb480344cfdfcec6c1b2.tar.gz
Add nested groups to the APIdz-nested-groups-api
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--changelogs/unreleased/dz-nested-groups-api.yml4
-rw-r--r--doc/api/groups.md10
-rw-r--r--lib/api/entities.rb1
-rw-r--r--lib/api/groups.rb1
-rw-r--r--spec/requests/api/groups_spec.rb14
5 files changed, 27 insertions, 3 deletions
diff --git a/changelogs/unreleased/dz-nested-groups-api.yml b/changelogs/unreleased/dz-nested-groups-api.yml
new file mode 100644
index 00000000000..d33ff42700f
--- /dev/null
+++ b/changelogs/unreleased/dz-nested-groups-api.yml
@@ -0,0 +1,4 @@
+---
+title: Add nested groups to the API
+merge_request: 9034
+author:
diff --git a/doc/api/groups.md b/doc/api/groups.md
index 3b38e3e1bee..84ab01c292b 100644
--- a/doc/api/groups.md
+++ b/doc/api/groups.md
@@ -32,7 +32,8 @@ GET /groups
"web_url": "http://localhost:3000/groups/foo-bar",
"request_access_enabled": false,
"full_name": "Foobar Group",
- "full_path": "foo-bar"
+ "full_path": "foo-bar",
+ "parent_id": null
}
]
```
@@ -156,8 +157,9 @@ Example response:
"avatar_url": null,
"web_url": "https://gitlab.example.com/groups/twitter",
"request_access_enabled": false,
- "full_name": "Foobar Group",
- "full_path": "foo-bar",
+ "full_name": "Twitter",
+ "full_path": "twitter",
+ "parent_id": null,
"projects": [
{
"id": 7,
@@ -332,6 +334,7 @@ Parameters:
- `visibility_level` (optional) - The group's visibility. 0 for private, 10 for internal, 20 for public.
- `lfs_enabled` (optional) - Enable/disable Large File Storage (LFS) for the projects in this group
- `request_access_enabled` (optional) - Allow users to request member access.
+- `parent_id` (optional) - The parent group id for creating nested group.
## Transfer project to group
@@ -383,6 +386,7 @@ Example response:
"request_access_enabled": false,
"full_name": "Foobar Group",
"full_path": "foo-bar",
+ "parent_id": null,
"projects": [
{
"id": 9,
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 5d7b8e021bb..3a5819d1bab 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -138,6 +138,7 @@ module API
expose :web_url
expose :request_access_enabled
expose :full_name, :full_path
+ expose :parent_id
expose :statistics, if: :statistics do
with_options format_with: -> (value) { value.to_i } do
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index 7682d286866..077db9a458a 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -73,6 +73,7 @@ module API
params do
requires :name, type: String, desc: 'The name of the group'
requires :path, type: String, desc: 'The path of the group'
+ optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group'
use :optional_params
end
post do
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index a027c23bb88..15592f1f702 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -179,6 +179,7 @@ describe API::Groups, api: true do
expect(json_response['request_access_enabled']).to eq(group1.request_access_enabled)
expect(json_response['full_name']).to eq(group1.full_name)
expect(json_response['full_path']).to eq(group1.full_path)
+ expect(json_response['parent_id']).to eq(group1.parent_id)
expect(json_response['projects']).to be_an Array
expect(json_response['projects'].length).to eq(2)
expect(json_response['shared_projects']).to be_an Array
@@ -398,6 +399,19 @@ describe API::Groups, api: true do
expect(json_response["request_access_enabled"]).to eq(group[:request_access_enabled])
end
+ it "creates a nested group" do
+ parent = create(:group)
+ parent.add_owner(user3)
+ group = attributes_for(:group, { parent_id: parent.id })
+
+ post api("/groups", user3), group
+
+ expect(response).to have_http_status(201)
+
+ expect(json_response["full_path"]).to eq("#{parent.path}/#{group[:path]}")
+ expect(json_response["parent_id"]).to eq(parent.id)
+ end
+
it "does not create group, duplicate" do
post api("/groups", user3), { name: 'Duplicate Test', path: group2.path }