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 | 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 | 73 | ## Group members |
| 61 | 74 | |
| 62 | 75 | ... | ... |
lib/api/groups.rb
| ... | ... | @@ -7,12 +7,14 @@ module API |
| 7 | 7 | helpers do |
| 8 | 8 | def find_group(id) |
| 9 | 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 | 12 | group |
| 12 | 13 | else |
| 13 | 14 | render_api_error!("403 Forbidden - #{current_user.username} lacks sufficient access to #{group.name}", 403) |
| 14 | 15 | end |
| 15 | 16 | end |
| 17 | + | |
| 16 | 18 | def validate_access_level?(level) |
| 17 | 19 | Gitlab::Access.options_with_owner.values.include? level.to_i |
| 18 | 20 | end |
| ... | ... | @@ -64,6 +66,19 @@ module API |
| 64 | 66 | present group, with: Entities::GroupDetail |
| 65 | 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 | 82 | # Transfer a project to the Group namespace |
| 68 | 83 | # |
| 69 | 84 | # Parameters: |
| ... | ... | @@ -132,7 +147,6 @@ module API |
| 132 | 147 | member.destroy |
| 133 | 148 | end |
| 134 | 149 | end |
| 135 | - | |
| 136 | 150 | end |
| 137 | 151 | end |
| 138 | 152 | end | ... | ... |