From df974814fbbbf8f088f6bb480344cfdfcec6c1b2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 7 Feb 2017 17:42:37 +0200 Subject: Add nested groups to the API Signed-off-by: Dmitriy Zaporozhets --- changelogs/unreleased/dz-nested-groups-api.yml | 4 ++++ doc/api/groups.md | 10 +++++++--- lib/api/entities.rb | 1 + lib/api/groups.rb | 1 + spec/requests/api/groups_spec.rb | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/dz-nested-groups-api.yml 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 } -- cgit v1.2.1