Commit d6a5e3dad7a8d5aa1eb2220c2c60f068455dbaed
Exists in
master
and in
4 other branches
Merge pull request #1735 from NARKOZ/api
API fixes
Showing
5 changed files
with
17 additions
and
20 deletions
Show diff stats
CHANGELOG
@@ -28,7 +28,7 @@ v 3.0.0 | @@ -28,7 +28,7 @@ v 3.0.0 | ||
28 | - Reject ssh keys that break gitolite | 28 | - Reject ssh keys that break gitolite |
29 | - [API] list one project hook | 29 | - [API] list one project hook |
30 | - [API] edit project hook | 30 | - [API] edit project hook |
31 | - - [API] add project snippets list | 31 | + - [API] list project snippets |
32 | - [API] allow to authorize using private token in HTTP header | 32 | - [API] allow to authorize using private token in HTTP header |
33 | - [API] add user creation | 33 | - [API] add user creation |
34 | 34 |
doc/api/users.md
@@ -74,14 +74,12 @@ POST /users | @@ -74,14 +74,12 @@ POST /users | ||
74 | 74 | ||
75 | Parameters: | 75 | Parameters: |
76 | + `email` (required) - Email | 76 | + `email` (required) - Email |
77 | -+ `name` (required) - Name | ||
78 | + `password` (required) - Password | 77 | + `password` (required) - Password |
79 | -+ `password_confirmation` (required) - Password confirmation | 78 | ++ `name` - Name |
80 | + `skype` - Skype ID | 79 | + `skype` - Skype ID |
81 | + `linkedin` - Linkedin | 80 | + `linkedin` - Linkedin |
82 | + `twitter` - Twitter account | 81 | + `twitter` - Twitter account |
83 | -+ `projects_limit` - Limit projects wich user can create | ||
84 | - | 82 | ++ `projects_limit` - Number of projects user can create |
85 | 83 | ||
86 | Will return created user with status `201 Created` on success, or `404 Not | 84 | Will return created user with status `201 Created` on success, or `404 Not |
87 | found` on fail. | 85 | found` on fail. |
lib/api/users.rb
@@ -23,24 +23,23 @@ module Gitlab | @@ -23,24 +23,23 @@ module Gitlab | ||
23 | @user = User.find(params[:id]) | 23 | @user = User.find(params[:id]) |
24 | present @user, with: Entities::User | 24 | present @user, with: Entities::User |
25 | end | 25 | end |
26 | - | 26 | + |
27 | # Create user. Available only for admin | 27 | # Create user. Available only for admin |
28 | # | 28 | # |
29 | # Parameters: | 29 | # Parameters: |
30 | # email (required) - Email | 30 | # email (required) - Email |
31 | - # name (required) - Name | ||
32 | # password (required) - Password | 31 | # password (required) - Password |
33 | - # password_confirmation (required) - Password confirmation | 32 | + # name - Name |
34 | # skype - Skype ID | 33 | # skype - Skype ID |
35 | # linkedin - Linkedin | 34 | # linkedin - Linkedin |
36 | # twitter - Twitter account | 35 | # twitter - Twitter account |
37 | - # projects_limit - Limit projects wich user can create | 36 | + # projects_limit - Number of projects user can create |
38 | # Example Request: | 37 | # Example Request: |
39 | # POST /users | 38 | # POST /users |
40 | post do | 39 | post do |
41 | authenticated_as_admin! | 40 | authenticated_as_admin! |
42 | - attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit] | ||
43 | - user = User.new attrs | 41 | + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit] |
42 | + user = User.new attrs, as: :admin | ||
44 | if user.save | 43 | if user.save |
45 | present user, with: Entities::User | 44 | present user, with: Entities::User |
46 | else | 45 | else |
spec/requests/api/projects_spec.rb
@@ -46,7 +46,7 @@ describe Gitlab::API do | @@ -46,7 +46,7 @@ describe Gitlab::API do | ||
46 | response.status.should == 201 | 46 | response.status.should == 201 |
47 | end | 47 | end |
48 | 48 | ||
49 | - it "should repsond with 404 on failure" do | 49 | + it "should respond with 404 on failure" do |
50 | post api("/projects", user) | 50 | post api("/projects", user) |
51 | response.status.should == 404 | 51 | response.status.should == 404 |
52 | end | 52 | end |
@@ -188,16 +188,16 @@ describe Gitlab::API do | @@ -188,16 +188,16 @@ describe Gitlab::API do | ||
188 | }.to change {project.hooks.count}.by(1) | 188 | }.to change {project.hooks.count}.by(1) |
189 | end | 189 | end |
190 | end | 190 | end |
191 | - | 191 | + |
192 | describe "PUT /projects/:id/hooks/:hook_id" do | 192 | describe "PUT /projects/:id/hooks/:hook_id" do |
193 | it "should update an existing project hook" do | 193 | it "should update an existing project hook" do |
194 | put api("/projects/#{project.code}/hooks/#{hook.id}", user), | 194 | put api("/projects/#{project.code}/hooks/#{hook.id}", user), |
195 | - url: 'http://example.com' | 195 | + url: 'http://example.org' |
196 | response.status.should == 200 | 196 | response.status.should == 200 |
197 | - json_response['url'].should == 'http://example.com' | 197 | + json_response['url'].should == 'http://example.org' |
198 | end | 198 | end |
199 | end | 199 | end |
200 | - | 200 | + |
201 | 201 | ||
202 | describe "DELETE /projects/:id/hooks" do | 202 | describe "DELETE /projects/:id/hooks" do |
203 | it "should delete hook from project" do | 203 | it "should delete hook from project" do |
spec/requests/api/users_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::API do | @@ -4,7 +4,7 @@ describe Gitlab::API do | ||
4 | include ApiHelpers | 4 | include ApiHelpers |
5 | 5 | ||
6 | let(:user) { Factory :user } | 6 | let(:user) { Factory :user } |
7 | - let(:admin) {Factory :admin} | 7 | + let(:admin) { Factory :admin } |
8 | let(:key) { Factory :key, user: user } | 8 | let(:key) { Factory :key, user: user } |
9 | 9 | ||
10 | describe "GET /users" do | 10 | describe "GET /users" do |
@@ -42,9 +42,9 @@ describe Gitlab::API do | @@ -42,9 +42,9 @@ describe Gitlab::API do | ||
42 | end | 42 | end |
43 | 43 | ||
44 | it "should create user" do | 44 | it "should create user" do |
45 | - expect{ | ||
46 | - post api("/users", admin), Factory.attributes(:user) | ||
47 | - }.to change{User.count}.by(1) | 45 | + expect { |
46 | + post api("/users", admin), Factory.attributes(:user, projects_limit: 3) | ||
47 | + }.to change { User.count }.by(1) | ||
48 | end | 48 | end |
49 | 49 | ||
50 | it "shouldn't available for non admin users" do | 50 | it "shouldn't available for non admin users" do |