diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-18 19:10:37 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-11-18 19:10:37 +0000 |
commit | b59ba979984072af6dfa89121eb12686c83ac44d (patch) | |
tree | 225c096b45ce4d148b2efc7ee2228bf684ae19e3 | |
parent | f614fa97ae5068f0793ce1bcc73d474e44843695 (diff) | |
parent | 434d276dba22924dbcbd903d4fea0d20c409ed98 (diff) | |
download | gitlab-ce-b59ba979984072af6dfa89121eb12686c83ac44d.tar.gz |
Merge branch 'feature/api_projects_all' of /home/git/repositories/gitlab/gitlabhq
-rw-r--r-- | doc/api/projects.md | 18 | ||||
-rw-r--r-- | lib/api/projects.rb | 10 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 26 |
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 |