Commit 825081174aa70b5cbfe5947ebf268f14702b6211
1 parent
0187ae4e
Exists in
master
and in
4 other branches
#1585 Api for user creation: base implementation
Showing
2 changed files
with
30 additions
and
0 deletions
Show diff stats
lib/api/helpers.rb
... | ... | @@ -22,6 +22,10 @@ module Gitlab |
22 | 22 | unauthorized! unless current_user |
23 | 23 | end |
24 | 24 | |
25 | + def authenticated_as_admin! | |
26 | + forbidden! unless current_user.is_admin? | |
27 | + end | |
28 | + | |
25 | 29 | def authorize! action, subject |
26 | 30 | unless abilities.allowed?(current_user, action, subject) |
27 | 31 | forbidden! | ... | ... |
lib/api/users.rb
... | ... | @@ -23,6 +23,30 @@ module Gitlab |
23 | 23 | @user = User.find(params[:id]) |
24 | 24 | present @user, with: Entities::User |
25 | 25 | end |
26 | + | |
27 | + # Create user. Available only for admin | |
28 | + # | |
29 | + # Parameters: | |
30 | + # email (required) - Email | |
31 | + # name (required) - Name | |
32 | + # password (required) - Password | |
33 | + # password_confirmation (required) - Password confirmation | |
34 | + # skype - Skype ID | |
35 | + # linkedin (required) - Linkedin | |
36 | + # twitter - Twitter account | |
37 | + # projects_limit - Limit projects wich user can create | |
38 | + # Example Request: | |
39 | + # POST /users | |
40 | + post do | |
41 | + authenticated_as_admin! | |
42 | + attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit] | |
43 | + user = User.new attrs | |
44 | + if user.save | |
45 | + present user, with: Entities::User | |
46 | + else | |
47 | + not_found! | |
48 | + end | |
49 | + end | |
26 | 50 | end |
27 | 51 | |
28 | 52 | resource :user do |
... | ... | @@ -78,6 +102,8 @@ module Gitlab |
78 | 102 | key = current_user.keys.find params[:id] |
79 | 103 | key.delete |
80 | 104 | end |
105 | + | |
106 | + | |
81 | 107 | end |
82 | 108 | end |
83 | 109 | end | ... | ... |