Commit b59ba979984072af6dfa89121eb12686c83ac44d
Exists in
master
and in
4 other branches
Merge branch 'feature/api_projects_all' of /home/git/repositories/gitlab/gitlabhq
Showing
3 changed files
with
53 additions
and
1 deletions
Show diff stats
doc/api/projects.md
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | ### List projects | 3 | ### List projects |
4 | 4 | ||
5 | -Get a list of projects owned by the authenticated user. | 5 | +Get a list of projects accessible by the authenticated user. |
6 | 6 | ||
7 | ``` | 7 | ``` |
8 | GET /projects | 8 | GET /projects |
@@ -82,6 +82,22 @@ GET /projects | @@ -82,6 +82,22 @@ GET /projects | ||
82 | ``` | 82 | ``` |
83 | 83 | ||
84 | 84 | ||
85 | +#### List owned projects | ||
86 | + | ||
87 | +Get a list of projects owned by the authenticated user. | ||
88 | + | ||
89 | +``` | ||
90 | +GET /projects/owned | ||
91 | +``` | ||
92 | + | ||
93 | +#### List ALL projects | ||
94 | + | ||
95 | +Get a list of all GitLab projects (admin only). | ||
96 | + | ||
97 | +``` | ||
98 | +GET /projects/all | ||
99 | +``` | ||
100 | + | ||
85 | ### Get single project | 101 | ### Get single project |
86 | 102 | ||
87 | Get a specific project, identified by project ID or NAMESPACE/PROJECT_NAME , which is owned by the authentication user. | 103 | Get a specific project, identified by project ID or NAMESPACE/PROJECT_NAME , which is owned by the authentication user. |
lib/api/projects.rb
@@ -31,6 +31,16 @@ module API | @@ -31,6 +31,16 @@ module API | ||
31 | present @projects, with: Entities::Project | 31 | present @projects, with: Entities::Project |
32 | end | 32 | end |
33 | 33 | ||
34 | + # Get all projects for admin user | ||
35 | + # | ||
36 | + # Example Request: | ||
37 | + # GET /projects/all | ||
38 | + get '/all' do | ||
39 | + authenticated_as_admin! | ||
40 | + @projects = paginate Project | ||
41 | + present @projects, with: Entities::Project | ||
42 | + end | ||
43 | + | ||
34 | # Get a single project | 44 | # Get a single project |
35 | # | 45 | # |
36 | # Parameters: | 46 | # Parameters: |
spec/requests/api/projects_spec.rb
@@ -36,6 +36,32 @@ describe API::API do | @@ -36,6 +36,32 @@ describe API::API do | ||
36 | end | 36 | end |
37 | end | 37 | end |
38 | 38 | ||
39 | + describe "GET /projects/all" do | ||
40 | + context "when unauthenticated" do | ||
41 | + it "should return authentication error" do | ||
42 | + get api("/projects/all") | ||
43 | + response.status.should == 401 | ||
44 | + end | ||
45 | + end | ||
46 | + | ||
47 | + context "when authenticated as regular user" do | ||
48 | + it "should return authentication error" do | ||
49 | + get api("/projects/all", user) | ||
50 | + response.status.should == 403 | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + context "when authenticated as admin" do | ||
55 | + it "should return an array of all projects" do | ||
56 | + get api("/projects/all", admin) | ||
57 | + response.status.should == 200 | ||
58 | + json_response.should be_an Array | ||
59 | + json_response.first['name'].should == project.name | ||
60 | + json_response.first['owner']['email'].should == user.email | ||
61 | + end | ||
62 | + end | ||
63 | + end | ||
64 | + | ||
39 | describe "POST /projects" do | 65 | describe "POST /projects" do |
40 | context "maximum number of projects reached" do | 66 | context "maximum number of projects reached" do |
41 | before do | 67 | before do |