summaryrefslogtreecommitdiff
path: root/lib/api/users.rb
diff options
context:
space:
mode:
authorBoyan Tabakov <boyan.tabakov@futurice.com>2013-07-31 13:52:23 +0300
committerBoyan Tabakov <boyan.tabakov@futurice.com>2013-09-29 11:47:29 +0300
commit479631aafc525efef151309ac257e60c73230ac0 (patch)
tree37861481ca8fe6c26f78aa2edee3df1c7156eacd /lib/api/users.rb
parentcbb5b000c0c7593673683c08a402ea01a3a7f369 (diff)
downloadgitlab-ce-479631aafc525efef151309ac257e60c73230ac0.tar.gz
Extended User API to expose admin and can_create_group for user creation/updating.
Also, is_admin and can_create_group are exposed in the user information. Fixed attributes_for_keys to process properly keys with boolean values (since false.present? is false).
Diffstat (limited to 'lib/api/users.rb')
-rw-r--r--lib/api/users.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 00dc2311ffd..54d3aeecb70 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -40,13 +40,17 @@ module API
# extern_uid - External authentication provider UID
# provider - External provider
# bio - Bio
+ # admin - User is admin - true or false (default)
+ # can_create_group - User can create groups - true or false
# Example Request:
# POST /users
post do
authenticated_as_admin!
required_attributes! [:email, :password, :name, :username]
- attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
+ attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio, :can_create_group, :admin]
user = User.build_user(attrs, as: :admin)
+ admin = attrs.delete(:admin)
+ user.admin = admin unless admin.nil?
if user.save
present user, with: Entities::User
else
@@ -67,16 +71,20 @@ module API
# extern_uid - External authentication provider UID
# provider - External provider
# bio - Bio
+ # admin - User is admin - true or false (default)
+ # can_create_group - User can create groups - true or false
# 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]
+ attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio, :can_create_group, :admin]
user = User.find(params[:id])
not_found!("User not found") unless user
- if user.update_attributes(attrs)
+ admin = attrs.delete(:admin)
+ user.admin = admin unless admin.nil?
+ if user.update_attributes(attrs, as: :admin)
present user, with: Entities::User
else
not_found!