Commit dc825ae33016b91235e210c2d37323c076fcf572
Exists in
master
and in
4 other branches
Merge branch 'feature/api_remove_group' of /home/git/repositories/gitlab/gitlabhq
Showing
4 changed files
with
68 additions
and
2 deletions
Show diff stats
CHANGELOG
| @@ -12,6 +12,7 @@ v 6.2.0 | @@ -12,6 +12,7 @@ v 6.2.0 | ||
| 12 | - Update logic for validates_merge_request for tree of MR (Andrew Kumanyaev) | 12 | - Update logic for validates_merge_request for tree of MR (Andrew Kumanyaev) |
| 13 | - Rake tasks for web hooks management (Jonhnny Weslley) | 13 | - Rake tasks for web hooks management (Jonhnny Weslley) |
| 14 | - Extended User API to expose admin and can_create_group for user creation/updating (Boyan Tabakov) | 14 | - Extended User API to expose admin and can_create_group for user creation/updating (Boyan Tabakov) |
| 15 | + - API: Remove group | ||
| 15 | 16 | ||
| 16 | v 6.1.0 | 17 | v 6.1.0 |
| 17 | - Project specific IDs for issues, mr, milestones | 18 | - Project specific IDs for issues, mr, milestones |
doc/api/groups.md
| @@ -57,6 +57,19 @@ Parameters: | @@ -57,6 +57,19 @@ Parameters: | ||
| 57 | + `project_id` (required) - The ID of a project | 57 | + `project_id` (required) - The ID of a project |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | +## Remove group | ||
| 61 | + | ||
| 62 | +Removes group with all projects inside. | ||
| 63 | + | ||
| 64 | +``` | ||
| 65 | +DELETE /groups/:id | ||
| 66 | +``` | ||
| 67 | + | ||
| 68 | +Parameters: | ||
| 69 | + | ||
| 70 | ++ `id` (required) - The ID of a user group | ||
| 71 | + | ||
| 72 | + | ||
| 60 | ## Group members | 73 | ## Group members |
| 61 | 74 | ||
| 62 | 75 |
lib/api/groups.rb
| @@ -7,12 +7,14 @@ module API | @@ -7,12 +7,14 @@ module API | ||
| 7 | helpers do | 7 | helpers do |
| 8 | def find_group(id) | 8 | def find_group(id) |
| 9 | group = Group.find(id) | 9 | group = Group.find(id) |
| 10 | - if current_user.admin or current_user.groups.include? group | 10 | + |
| 11 | + if can?(current_user, :read_group, group) | ||
| 11 | group | 12 | group |
| 12 | else | 13 | else |
| 13 | render_api_error!("403 Forbidden - #{current_user.username} lacks sufficient access to #{group.name}", 403) | 14 | render_api_error!("403 Forbidden - #{current_user.username} lacks sufficient access to #{group.name}", 403) |
| 14 | end | 15 | end |
| 15 | end | 16 | end |
| 17 | + | ||
| 16 | def validate_access_level?(level) | 18 | def validate_access_level?(level) |
| 17 | Gitlab::Access.options_with_owner.values.include? level.to_i | 19 | Gitlab::Access.options_with_owner.values.include? level.to_i |
| 18 | end | 20 | end |
| @@ -64,6 +66,19 @@ module API | @@ -64,6 +66,19 @@ module API | ||
| 64 | present group, with: Entities::GroupDetail | 66 | present group, with: Entities::GroupDetail |
| 65 | end | 67 | end |
| 66 | 68 | ||
| 69 | + | ||
| 70 | + # Remove group | ||
| 71 | + # | ||
| 72 | + # Parameters: | ||
| 73 | + # id (required) - The ID of a group | ||
| 74 | + # Example Request: | ||
| 75 | + # DELETE /groups/:id | ||
| 76 | + delete ":id" do | ||
| 77 | + group = find_group(params[:id]) | ||
| 78 | + authorize! :manage_group, group | ||
| 79 | + group.destroy | ||
| 80 | + end | ||
| 81 | + | ||
| 67 | # Transfer a project to the Group namespace | 82 | # Transfer a project to the Group namespace |
| 68 | # | 83 | # |
| 69 | # Parameters: | 84 | # Parameters: |
| @@ -132,7 +147,6 @@ module API | @@ -132,7 +147,6 @@ module API | ||
| 132 | member.destroy | 147 | member.destroy |
| 133 | end | 148 | end |
| 134 | end | 149 | end |
| 135 | - | ||
| 136 | end | 150 | end |
| 137 | end | 151 | end |
| 138 | end | 152 | end |
spec/requests/api/groups_spec.rb
| @@ -106,6 +106,44 @@ describe API::API do | @@ -106,6 +106,44 @@ describe API::API do | ||
| 106 | end | 106 | end |
| 107 | end | 107 | end |
| 108 | 108 | ||
| 109 | + describe "DELETE /groups/:id" do | ||
| 110 | + context "when authenticated as user" do | ||
| 111 | + it "should remove group" do | ||
| 112 | + delete api("/groups/#{group1.id}", user1) | ||
| 113 | + response.status.should == 200 | ||
| 114 | + end | ||
| 115 | + | ||
| 116 | + it "should not remove a group if not an owner" do | ||
| 117 | + user3 = create(:user) | ||
| 118 | + group1.add_user(user3, Gitlab::Access::MASTER) | ||
| 119 | + delete api("/groups/#{group1.id}", user3) | ||
| 120 | + response.status.should == 403 | ||
| 121 | + end | ||
| 122 | + | ||
| 123 | + it "should not remove a non existing group" do | ||
| 124 | + delete api("/groups/1328", user1) | ||
| 125 | + response.status.should == 404 | ||
| 126 | + end | ||
| 127 | + | ||
| 128 | + it "should not remove a group not attached to user1" do | ||
| 129 | + delete api("/groups/#{group2.id}", user1) | ||
| 130 | + response.status.should == 403 | ||
| 131 | + end | ||
| 132 | + end | ||
| 133 | + | ||
| 134 | + context "when authenticated as admin" do | ||
| 135 | + it "should remove any existing group" do | ||
| 136 | + delete api("/groups/#{group2.id}", admin) | ||
| 137 | + response.status.should == 200 | ||
| 138 | + end | ||
| 139 | + | ||
| 140 | + it "should not remove a non existing group" do | ||
| 141 | + delete api("/groups/1328", admin) | ||
| 142 | + response.status.should == 404 | ||
| 143 | + end | ||
| 144 | + end | ||
| 145 | + end | ||
| 146 | + | ||
| 109 | describe "POST /groups/:id/projects/:project_id" do | 147 | describe "POST /groups/:id/projects/:project_id" do |
| 110 | let(:project) { create(:project) } | 148 | let(:project) { create(:project) } |
| 111 | before(:each) do | 149 | before(:each) do |