Commit 7af1bc3b88e3a32cb07d7aee7962af22c2339c02
Exists in
master
and in
4 other branches
Merge branch 'feature/api_remove_project' of /home/git/repositories/gitlab/gitlabhq
Showing
4 changed files
with
60 additions
and
1 deletions
Show diff stats
doc/api/projects.md
| ... | ... | @@ -244,6 +244,18 @@ Parameters: |
| 244 | 244 | + `public` (optional) |
| 245 | 245 | |
| 246 | 246 | |
| 247 | +## Remove project | |
| 248 | + | |
| 249 | +Removes project with all resources(issues, merge requests etc) | |
| 250 | + | |
| 251 | +``` | |
| 252 | +DELETE /projects/:id | |
| 253 | +``` | |
| 254 | + | |
| 255 | +Parameters: | |
| 256 | + | |
| 257 | ++ `id` (required) - The ID of a project | |
| 258 | + | |
| 247 | 259 | |
| 248 | 260 | ## Team members |
| 249 | 261 | ... | ... |
lib/api/groups.rb
lib/api/projects.rb
| ... | ... | @@ -129,6 +129,16 @@ module API |
| 129 | 129 | end |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | + # Remove project | |
| 133 | + # | |
| 134 | + # Parameters: | |
| 135 | + # id (required) - The ID of a project | |
| 136 | + # Example Request: | |
| 137 | + # DELETE /projects/:id | |
| 138 | + delete ":id" do | |
| 139 | + authorize! :remove_project, user_project | |
| 140 | + user_project.destroy | |
| 141 | + end | |
| 132 | 142 | |
| 133 | 143 | # Mark this project as forked from another |
| 134 | 144 | # | ... | ... |
spec/requests/api/projects_spec.rb
| ... | ... | @@ -730,4 +730,42 @@ describe API::API do |
| 730 | 730 | end |
| 731 | 731 | end |
| 732 | 732 | end |
| 733 | + | |
| 734 | + describe "DELETE /projects/:id" do | |
| 735 | + context "when authenticated as user" do | |
| 736 | + it "should remove project" do | |
| 737 | + delete api("/projects/#{project.id}", user) | |
| 738 | + response.status.should == 200 | |
| 739 | + end | |
| 740 | + | |
| 741 | + it "should not remove a project if not an owner" do | |
| 742 | + user3 = create(:user) | |
| 743 | + project.team << [user3, :developer] | |
| 744 | + delete api("/projects/#{project.id}", user3) | |
| 745 | + response.status.should == 403 | |
| 746 | + end | |
| 747 | + | |
| 748 | + it "should not remove a non existing project" do | |
| 749 | + delete api("/projects/1328", user) | |
| 750 | + response.status.should == 404 | |
| 751 | + end | |
| 752 | + | |
| 753 | + it "should not remove a project not attached to user" do | |
| 754 | + delete api("/projects/#{project.id}", user2) | |
| 755 | + response.status.should == 404 | |
| 756 | + end | |
| 757 | + end | |
| 758 | + | |
| 759 | + context "when authenticated as admin" do | |
| 760 | + it "should remove any existing project" do | |
| 761 | + delete api("/projects/#{project.id}", admin) | |
| 762 | + response.status.should == 200 | |
| 763 | + end | |
| 764 | + | |
| 765 | + it "should not remove a non existing project" do | |
| 766 | + delete api("/projects/1328", admin) | |
| 767 | + response.status.should == 404 | |
| 768 | + end | |
| 769 | + end | |
| 770 | + end | |
| 733 | 771 | end | ... | ... |