Commit ace5c54ab91cdb9142a27d4543ee839684d29d5d

Authored by Angus MacArthur
1 parent acb402a1

enhance project creation apis to allow setting of public attribute

Change-Id: Ib71ce8cf993627eada63d7d596fb302ec702f36e
doc/api/projects.md
... ... @@ -189,6 +189,7 @@ Parameters:
189 189 + `merge_requests_enabled` (optional)
190 190 + `wiki_enabled` (optional)
191 191 + `snippets_enabled` (optional)
  192 ++ `public` (optional)
192 193  
193 194 **Project access levels**
194 195  
... ... @@ -221,6 +222,7 @@ Parameters:
221 222 + `merge_requests_enabled` (optional)
222 223 + `wiki_enabled` (optional)
223 224 + `snippets_enabled` (optional)
  225 ++ `public` (optional)
224 226  
225 227  
226 228  
... ...
lib/api/entities.rb
... ... @@ -36,7 +36,7 @@ module API
36 36 expose :owner, using: Entities::UserBasic
37 37 expose :name, :name_with_namespace
38 38 expose :path, :path_with_namespace
39   - expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
  39 + expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at, :public
40 40 expose :namespace
41 41 expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? }
42 42 end
... ...
lib/api/projects.rb
... ... @@ -67,6 +67,7 @@ module API
67 67 # wiki_enabled (optional)
68 68 # snippets_enabled (optional)
69 69 # namespace_id (optional) - defaults to user namespace
  70 + # public (optional) - false by default
70 71 # Example Request
71 72 # POST /projects
72 73 post do
... ... @@ -79,7 +80,8 @@ module API
79 80 :merge_requests_enabled,
80 81 :wiki_enabled,
81 82 :snippets_enabled,
82   - :namespace_id]
  83 + :namespace_id,
  84 + :public]
83 85 @project = ::Projects::CreateContext.new(current_user, attrs).execute
84 86 if @project.saved?
85 87 present @project, with: Entities::Project
... ... @@ -103,6 +105,7 @@ module API
103 105 # merge_requests_enabled (optional)
104 106 # wiki_enabled (optional)
105 107 # snippets_enabled (optional)
  108 + # public (optional)
106 109 # Example Request
107 110 # POST /projects/user/:user_id
108 111 post "user/:user_id" do
... ... @@ -115,7 +118,8 @@ module API
115 118 :wall_enabled,
116 119 :merge_requests_enabled,
117 120 :wiki_enabled,
118   - :snippets_enabled]
  121 + :snippets_enabled,
  122 + :public]
119 123 @project = ::Projects::CreateContext.new(user, attrs).execute
120 124 if @project.saved?
121 125 present @project, with: Entities::Project
... ...
spec/requests/api/projects_spec.rb
... ... @@ -104,6 +104,21 @@ describe API::API do
104 104 json_response[k.to_s].should == v
105 105 end
106 106 end
  107 +
  108 + it "should set a project as public" do
  109 + project = attributes_for(:project, { public: true })
  110 + post api("/projects", user), project
  111 + json_response['public'].should be_true
  112 +
  113 + end
  114 +
  115 + it "should set a project as private" do
  116 + project = attributes_for(:project, { public: false })
  117 + post api("/projects", user), project
  118 + json_response['public'].should be_false
  119 +
  120 + end
  121 +
107 122 end
108 123  
109 124 describe "POST /projects/user/:id" do
... ... @@ -144,6 +159,21 @@ describe API::API do
144 159 json_response[k.to_s].should == v
145 160 end
146 161 end
  162 +
  163 + it "should set a project as public" do
  164 + project = attributes_for(:project, { public: true })
  165 + post api("/projects/user/#{user.id}", admin), project
  166 + json_response['public'].should be_true
  167 +
  168 + end
  169 +
  170 + it "should set a project as private" do
  171 + project = attributes_for(:project, { public: false })
  172 + post api("/projects/user/#{user.id}", admin), project
  173 + json_response['public'].should be_false
  174 +
  175 + end
  176 +
147 177 end
148 178  
149 179 describe "GET /projects/:id" do
... ...