diff options
author | Markus Koller <markus.koller.ext@siemens.com> | 2017-12-22 18:54:55 +0300 |
---|---|---|
committer | Markus Koller <markus.koller.ext@siemens.com> | 2018-02-08 15:30:34 +0300 |
commit | b7cd99c376c2f953f30a4bf982b69780e3d6985b (patch) | |
tree | 1a808da75fbc90fc332765cbe338a6ede7335a7a /lib/api/users.rb | |
parent | bb2478c205932429e7e519aaaf2d9b655aecf860 (diff) |
Allow including custom attributes in API responses
Diffstat (limited to 'lib/api/users.rb')
-rw-r--r-- | lib/api/users.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb index 3cc12724b8a..3920171205f 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -2,6 +2,7 @@ module API class Users < Grape::API include PaginationParams include APIGuard + include Helpers::CustomAttributes allow_access_with_scope :read_user, if: -> (request) { request.get? } @@ -70,6 +71,7 @@ module API use :sort_params use :pagination + use :with_custom_attributes end get do authenticated_as_admin! if params[:external].present? || (params[:extern_uid].present? && params[:provider].present?) @@ -94,8 +96,9 @@ module API entity = current_user&.admin? ? Entities::UserWithAdmin : Entities::UserBasic users = users.preload(:identities, :u2f_registrations) if entity == Entities::UserWithAdmin + users, options = with_custom_attributes(users, with: entity) - present paginate(users), with: entity + present paginate(users), options end desc 'Get a single user' do @@ -103,12 +106,16 @@ module API end params do requires :id, type: Integer, desc: 'The ID of the user' + + use :with_custom_attributes end get ":id" do user = User.find_by(id: params[:id]) not_found!('User') unless user && can?(current_user, :read_user, user) opts = current_user&.admin? ? { with: Entities::UserWithAdmin } : { with: Entities::User } + user, opts = with_custom_attributes(user, opts) + present user, opts end |