diff options
author | Boyan Tabakov <boyan.tabakov@futurice.com> | 2013-07-31 13:52:23 +0300 |
---|---|---|
committer | Boyan Tabakov <boyan.tabakov@futurice.com> | 2013-09-29 11:47:29 +0300 |
commit | 479631aafc525efef151309ac257e60c73230ac0 (patch) | |
tree | 37861481ca8fe6c26f78aa2edee3df1c7156eacd /lib | |
parent | cbb5b000c0c7593673683c08a402ea01a3a7f369 (diff) | |
download | gitlab-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')
-rw-r--r-- | lib/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/api/helpers.rb | 2 | ||||
-rw-r--r-- | lib/api/users.rb | 14 |
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 1f35e9ec5fc..ab949f530ab 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -3,6 +3,9 @@ module API class User < Grape::Entity expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter, :theme_id, :color_scheme_id, :state, :created_at, :extern_uid, :provider + expose :is_admin?, as: :is_admin + expose :can_create_group?, as: :can_create_group + expose :can_create_project?, as: :can_create_project end class UserSafe < Grape::Entity @@ -15,10 +18,6 @@ module API class UserLogin < User expose :private_token - expose :is_admin?, as: :is_admin - expose :can_create_group?, as: :can_create_group - expose :can_create_project?, as: :can_create_project - expose :can_create_team?, as: :can_create_team end class Hook < Grape::Entity diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 4f189f35196..860848b2995 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -82,7 +82,7 @@ module API def attributes_for_keys(keys) attrs = {} keys.each do |key| - attrs[key] = params[key] if params[key].present? + attrs[key] = params[key] if params[key].present? or (params.has_key?(key) and params[key] == false) end attrs end 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! |