Commit f141711cfd47808d5f954e1ccf057a858b36d63a
1 parent
073c8a29
Exists in
master
and in
4 other branches
API: new feature - remove group
Showing
2 changed files
with
29 additions
and
2 deletions
Show diff stats
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 |