summaryrefslogtreecommitdiff
path: root/lib/api/users.rb
diff options
context:
space:
mode:
authorBoyan Tabakov <boyan.tabakov@futurice.com>2012-12-18 21:24:31 +0200
committerBoyan Tabakov <boyan.tabakov@futurice.com>2012-12-18 21:24:31 +0200
commite954438a1d3a45addebf52ab04155459d7d84db0 (patch)
treef88bc4f1aaf560f34fb0f7b106a8e5f3a215ee17 /lib/api/users.rb
parentf4a6f1fd5a9fb9f35bb43956275c5f1da96ce019 (diff)
downloadgitlab-ce-e954438a1d3a45addebf52ab04155459d7d84db0.tar.gz
Extended users API to support updating and deleting users.
Also added tests.
Diffstat (limited to 'lib/api/users.rb')
-rw-r--r--lib/api/users.rb47
1 files changed, 46 insertions, 1 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 140c20f6bd2..7ea90c75e9e 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -34,11 +34,14 @@ module Gitlab
# linkedin - Linkedin
# twitter - Twitter account
# projects_limit - Number of projects user can create
+ # extern_uid - External authentication provider UID
+ # provider - External provider
+ # bio - Bio
# Example Request:
# POST /users
post do
authenticated_as_admin!
- attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username]
+ attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
user = User.new attrs, as: :admin
if user.save
present user, with: Entities::User
@@ -46,6 +49,48 @@ module Gitlab
not_found!
end
end
+
+ # Update user. Available only for admin
+ #
+ # Parameters:
+ # email - Email
+ # name - Name
+ # password - Password
+ # skype - Skype ID
+ # linkedin - Linkedin
+ # twitter - Twitter account
+ # projects_limit - Limit projects wich user can create
+ # extern_uid - External authentication provider UID
+ # provider - External provider
+ # bio - Bio
+ # Example Request:
+ # PUT /users/:id
+ put ":id" do
+ authenticated_as_admin!
+ attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
+ user = User.find_by_id(params[:id])
+
+ if user && user.update_attributes(attrs)
+ present user, with: Entities::User
+ else
+ not_found!
+ end
+ end
+
+ # Delete user. Available only for admin
+ #
+ # Example Request:
+ # DELETE /users/:id
+ delete ":id" do
+ authenticated_as_admin!
+ user = User.find_by_id(params[:id])
+
+ if user
+ user.destroy
+ else
+ not_found!
+ end
+ end
end
resource :user do