summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/projects.md18
-rw-r--r--lib/api/projects.rb10
-rw-r--r--spec/requests/api/projects_spec.rb26
3 files changed, 53 insertions, 1 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md
index d4d883e54ec..9b5d62ac832 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -2,7 +2,7 @@
### List projects
-Get a list of projects owned by the authenticated user.
+Get a list of projects accessible by the authenticated user.
```
GET /projects
@@ -82,6 +82,22 @@ GET /projects
```
+#### List owned projects
+
+Get a list of projects owned by the authenticated user.
+
+```
+GET /projects/owned
+```
+
+#### List ALL projects
+
+Get a list of all GitLab projects (admin only).
+
+```
+GET /projects/all
+```
+
### Get single project
Get a specific project, identified by project ID or NAMESPACE/PROJECT_NAME , which is owned by the authentication user.
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 42560572046..b927e63f4a4 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -31,6 +31,16 @@ module API
present @projects, with: Entities::Project
end
+ # Get all projects for admin user
+ #
+ # Example Request:
+ # GET /projects/all
+ get '/all' do
+ authenticated_as_admin!
+ @projects = paginate Project
+ present @projects, with: Entities::Project
+ end
+
# Get a single project
#
# Parameters:
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 2ae186b967a..e4cef6c587c 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -36,6 +36,32 @@ describe API::API do
end
end
+ describe "GET /projects/all" do
+ context "when unauthenticated" do
+ it "should return authentication error" do
+ get api("/projects/all")
+ response.status.should == 401
+ end
+ end
+
+ context "when authenticated as regular user" do
+ it "should return authentication error" do
+ get api("/projects/all", user)
+ response.status.should == 403
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "should return an array of all projects" do
+ get api("/projects/all", admin)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.first['name'].should == project.name
+ json_response.first['owner']['email'].should == user.email
+ end
+ end
+ end
+
describe "POST /projects" do
context "maximum number of projects reached" do
before do