Feature #36303

Include avatar URL in Users API

Added by Go MAEDA 7 months ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:REST API
Target version:5.0.0
Resolution:Fixed

Description

I suggest including the avatar URL in the user's API.

{
  "user": {
    "id": 1,
    "login": "admin",
    "firstname": "Redmine",
    "lastname": "Admin",
    "created_on": "2006-07-19T17:12:21Z",
    "updated_on": "2021-12-13T10:03:30Z",
    "last_login_on": "2021-12-11T07:06:41Z",
    "passwd_changed_on": null,
    "avatar_url": "https://www.gravatar.com/avatar/982b6086063a22d85509455d8e31cca2" 
  }
}

Currently, it is difficult to display a user's Gravatar image when developing an application using the REST API. This is because Users API response doesn't include Gravatar URL. Although you can generate a Gravatar URL if you know the email address, email addresses are usually hidden for non-admin users.

This feature is very useful for developers who are building Redmine clients using REST API.

36303.patch Magnifier (2.96 KB) Yuichi HARADA, 2021-12-22 06:09

36303-v2.patch Magnifier (3.14 KB) Go MAEDA, 2021-12-30 10:19

36303-v3.patch Magnifier (3.29 KB) Go MAEDA, 2022-01-20 14:53


Related issues

Related to Redmine - Defect #37157: Internal server error when trying to retrieve AnonymousUs... Closed

Associated revisions

Revision 21375
Added by Go MAEDA 5 months ago

Include avatar URL in Users API (#36303).

Contributed by Yuichi HARADA.

History

#1 Updated by Yuichi HARADA 6 months ago

With the following patch, get the avatar URL even by non-admin users.

diff --git a/app/views/users/index.api.rsb b/app/views/users/index.api.rsb
index 4b51ba47a8..cd89a6bf9c 100644
--- a/app/views/users/index.api.rsb
+++ b/app/views/users/index.api.rsb
@@ -11,6 +11,7 @@ api.array :users, api_meta(:total_count => @user_count, :offset => @offset, :lim
       api.updated_on user.updated_on
       api.last_login_on     user.last_login_on
       api.passwd_changed_on user.passwd_changed_on
+      api.avatar_url gravatar_url(user.mail, {rating: nil, size: nil})
       api.twofa_scheme user.twofa_scheme

       render_api_custom_values user.visible_custom_field_values, api
diff --git a/app/views/users/show.api.rsb b/app/views/users/show.api.rsb
index a19a8c637a..c30947512e 100644
--- a/app/views/users/show.api.rsb
+++ b/app/views/users/show.api.rsb
@@ -9,6 +9,7 @@ api.user do
   api.updated_on @user.updated_on
   api.last_login_on     @user.last_login_on
   api.passwd_changed_on @user.passwd_changed_on
+  api.avatar_url gravatar_url(@user.mail, {rating: nil, size: nil})
   api.twofa_scheme      @user.twofa_scheme if User.current.admin? || (User.current == @user)
   api.api_key    @user.api_key if User.current.admin? || (User.current == @user)
   api.status     @user.status if User.current.admin?

#2 Updated by Go MAEDA 6 months ago

  • File 36303-v2.patchMagnifier added
  • Target version set to Candidate for next major release

Updated the patch to check if the setting "Use Gravatar user icons" is enabled.

#3 Updated by Go MAEDA 6 months ago

  • Target version changed from Candidate for next major release to 5.0.0

Setting the target version to 5.0.0.

#4 Updated by Go MAEDA 6 months ago

The patch should respect Setting.Setting.gravatar_default. Otherwise, the icon you see in Redmine and the icon you get by accessing the avatar_url returned by the API will be different.

#5 Updated by Yuichi HARADA 6 months ago

Go MAEDA wrote:

The patch should respect Setting.Setting.gravatar_default. Otherwise, the icon you see in Redmine and the icon you get by accessing the avatar_url returned by the API will be different.

You're right. Setting.Setting.gravatar_default should be respected.

#6 Updated by Go MAEDA 5 months ago

Updated the patch to respect Setting.Setting.gravatar_default.

#7 Updated by Go MAEDA 5 months ago

  • Subject changed from Include avatar URL in user API to Include avatar URL in Users API
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch.

#8 Updated by Alex Moroz about 1 month ago

Crashes here, if user is Anonimous (user.mail = nil)

api.avatar_url gravatar_url(@user.mail, {rating: nil, size: nil})

#9 Updated by Go MAEDA about 1 month ago

  • Related to Defect #37157: Internal server error when trying to retrieve AnonymousUser's information via Users API added

Also available in: Atom PDF