diff options
author | Rémy Coutable <remy@rymai.me> | 2018-06-06 13:50:34 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-06-06 13:50:34 +0300 |
commit | f4b03f0992d39db9f9f77798cb285d732c352074 (patch) | |
tree | 51bc0ace569b24a49910c02e0d918c90317f9685 /lib/api | |
parent | 71242199a2c4a8130e02d51bc97cb505f6768e52 (diff) | |
parent | c8f0e4b5da0c9d578035e74b524f5adcb80efcf6 (diff) |
Merge branch '45821-avatar_api' into 'master'
Add Avatar API
Closes #45821
See merge request gitlab-org/gitlab-ce!19121
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/avatar.rb | 21 | ||||
-rw-r--r-- | lib/api/entities.rb | 6 |
3 files changed, 28 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 7ea575a9661..e2ad3c5f4e3 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -83,6 +83,7 @@ module API # Keep in alphabetical order mount ::API::AccessRequests mount ::API::Applications + mount ::API::Avatar mount ::API::AwardEmoji mount ::API::Badges mount ::API::Boards diff --git a/lib/api/avatar.rb b/lib/api/avatar.rb new file mode 100644 index 00000000000..70219bc8ea0 --- /dev/null +++ b/lib/api/avatar.rb @@ -0,0 +1,21 @@ +module API + class Avatar < Grape::API + resource :avatar do + desc 'Return avatar url for a user' do + success Entities::Avatar + end + params do + requires :email, type: String, desc: 'Public email address of the user' + optional :size, type: Integer, desc: 'Single pixel dimension for Gravatar images' + end + get do + forbidden!('Unauthorized access') unless can?(current_user, :read_users_list) + + user = User.find_by_public_email(params[:email]) + user ||= User.new(email: params[:email]) + + present user, with: Entities::Avatar, size: params[:size] + end + end + end +end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index c76d3ff45d0..22afcb9edf2 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -694,6 +694,12 @@ module API expose :notes, using: Entities::Note end + class Avatar < Grape::Entity + expose :avatar_url do |avatarable, options| + avatarable.avatar_url(only_path: false, size: options[:size]) + end + end + class AwardEmoji < Grape::Entity expose :id expose :name |