diff options
author | Imre <ifarkas@gitlab.com> | 2018-05-18 10:49:02 +0200 |
---|---|---|
committer | Imre Farkas <ifarkas@gitlab.com> | 2018-06-06 10:12:52 +0200 |
commit | c8f0e4b5da0c9d578035e74b524f5adcb80efcf6 (patch) | |
tree | 4e0a2624c77f42bebf1d06098074c61115828b2f /lib/api | |
parent | fe0ebf76c49e2512b211c5d43152275c536f7e3a (diff) | |
download | gitlab-ce-c8f0e4b5da0c9d578035e74b524f5adcb80efcf6.tar.gz |
Add Avatar API
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 c4537036a3a..b192f417014 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -692,6 +692,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 |