Commit ace5c54ab91cdb9142a27d4543ee839684d29d5d
1 parent
acb402a1
Exists in
master
and in
4 other branches
enhance project creation apis to allow setting of public attribute
Change-Id: Ib71ce8cf993627eada63d7d596fb302ec702f36e
Showing
4 changed files
with
39 additions
and
3 deletions
Show diff stats
doc/api/projects.md
@@ -189,6 +189,7 @@ Parameters: | @@ -189,6 +189,7 @@ Parameters: | ||
189 | + `merge_requests_enabled` (optional) | 189 | + `merge_requests_enabled` (optional) |
190 | + `wiki_enabled` (optional) | 190 | + `wiki_enabled` (optional) |
191 | + `snippets_enabled` (optional) | 191 | + `snippets_enabled` (optional) |
192 | ++ `public` (optional) | ||
192 | 193 | ||
193 | **Project access levels** | 194 | **Project access levels** |
194 | 195 | ||
@@ -221,6 +222,7 @@ Parameters: | @@ -221,6 +222,7 @@ Parameters: | ||
221 | + `merge_requests_enabled` (optional) | 222 | + `merge_requests_enabled` (optional) |
222 | + `wiki_enabled` (optional) | 223 | + `wiki_enabled` (optional) |
223 | + `snippets_enabled` (optional) | 224 | + `snippets_enabled` (optional) |
225 | ++ `public` (optional) | ||
224 | 226 | ||
225 | 227 | ||
226 | 228 |
lib/api/entities.rb
@@ -36,7 +36,7 @@ module API | @@ -36,7 +36,7 @@ module API | ||
36 | expose :owner, using: Entities::UserBasic | 36 | expose :owner, using: Entities::UserBasic |
37 | expose :name, :name_with_namespace | 37 | expose :name, :name_with_namespace |
38 | expose :path, :path_with_namespace | 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 | expose :namespace | 40 | expose :namespace |
41 | expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? } | 41 | expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? } |
42 | end | 42 | end |
lib/api/projects.rb
@@ -67,6 +67,7 @@ module API | @@ -67,6 +67,7 @@ module API | ||
67 | # wiki_enabled (optional) | 67 | # wiki_enabled (optional) |
68 | # snippets_enabled (optional) | 68 | # snippets_enabled (optional) |
69 | # namespace_id (optional) - defaults to user namespace | 69 | # namespace_id (optional) - defaults to user namespace |
70 | + # public (optional) - false by default | ||
70 | # Example Request | 71 | # Example Request |
71 | # POST /projects | 72 | # POST /projects |
72 | post do | 73 | post do |
@@ -79,7 +80,8 @@ module API | @@ -79,7 +80,8 @@ module API | ||
79 | :merge_requests_enabled, | 80 | :merge_requests_enabled, |
80 | :wiki_enabled, | 81 | :wiki_enabled, |
81 | :snippets_enabled, | 82 | :snippets_enabled, |
82 | - :namespace_id] | 83 | + :namespace_id, |
84 | + :public] | ||
83 | @project = ::Projects::CreateContext.new(current_user, attrs).execute | 85 | @project = ::Projects::CreateContext.new(current_user, attrs).execute |
84 | if @project.saved? | 86 | if @project.saved? |
85 | present @project, with: Entities::Project | 87 | present @project, with: Entities::Project |
@@ -103,6 +105,7 @@ module API | @@ -103,6 +105,7 @@ module API | ||
103 | # merge_requests_enabled (optional) | 105 | # merge_requests_enabled (optional) |
104 | # wiki_enabled (optional) | 106 | # wiki_enabled (optional) |
105 | # snippets_enabled (optional) | 107 | # snippets_enabled (optional) |
108 | + # public (optional) | ||
106 | # Example Request | 109 | # Example Request |
107 | # POST /projects/user/:user_id | 110 | # POST /projects/user/:user_id |
108 | post "user/:user_id" do | 111 | post "user/:user_id" do |
@@ -115,7 +118,8 @@ module API | @@ -115,7 +118,8 @@ module API | ||
115 | :wall_enabled, | 118 | :wall_enabled, |
116 | :merge_requests_enabled, | 119 | :merge_requests_enabled, |
117 | :wiki_enabled, | 120 | :wiki_enabled, |
118 | - :snippets_enabled] | 121 | + :snippets_enabled, |
122 | + :public] | ||
119 | @project = ::Projects::CreateContext.new(user, attrs).execute | 123 | @project = ::Projects::CreateContext.new(user, attrs).execute |
120 | if @project.saved? | 124 | if @project.saved? |
121 | present @project, with: Entities::Project | 125 | present @project, with: Entities::Project |
spec/requests/api/projects_spec.rb
@@ -104,6 +104,21 @@ describe API::API do | @@ -104,6 +104,21 @@ describe API::API do | ||
104 | json_response[k.to_s].should == v | 104 | json_response[k.to_s].should == v |
105 | end | 105 | end |
106 | end | 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 | end | 122 | end |
108 | 123 | ||
109 | describe "POST /projects/user/:id" do | 124 | describe "POST /projects/user/:id" do |
@@ -144,6 +159,21 @@ describe API::API do | @@ -144,6 +159,21 @@ describe API::API do | ||
144 | json_response[k.to_s].should == v | 159 | json_response[k.to_s].should == v |
145 | end | 160 | end |
146 | end | 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 | end | 177 | end |
148 | 178 | ||
149 | describe "GET /projects/:id" do | 179 | describe "GET /projects/:id" do |