Defect #37157

Internal server error when trying to retrieve AnonymousUser's information via Users API

Added by Go MAEDA 3 months ago. Updated 3 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Marius BALTEANU% Done:

0%

Category:REST API
Target version:5.0.2
Resolution:Fixed Affected version:5.0.0

Description

Users API raises an exception when it attempts to generate an avatar URL for AnonymousUser. This was originally reported in #36303#note-8 by Alex Moroz.

Started GET "/users/6.json" for 127.0.0.1 at 2022-05-25 09:41:36 +0900
Processing by UsersController#show as JSON
  Parameters: {"id"=>"6"}
 .
(snip)
 .
  Rendering users/show.api.rsb
  Rendered users/show.api.rsb (Duration: 0.5ms | Allocations: 200)
Completed 500 Internal Server Error in 15ms (ActiveRecord: 1.9ms | Allocations: 7193)

ActionView::Template::Error (no implicit conversion of nil into String):
     9:   api.updated_on @user.updated_on
    10:   api.last_login_on     @user.last_login_on
    11:   api.passwd_changed_on @user.passwd_changed_on
    12:   api.avatar_url gravatar_url(@user.mail, {rating: nil, size: nil, default: Setting.gravatar_default}) if Setting.gravatar_enabled?
    13:   api.twofa_scheme      @user.twofa_scheme if User.current.admin? || (User.current == @user)
    14:   api.api_key    @user.api_key if User.current.admin? || (User.current == @user)
    15:   api.status     @user.status if User.current.admin?

lib/plugins/gravatar/lib/gravatar.rb:68:in `digest'
lib/plugins/gravatar/lib/gravatar.rb:68:in `hexdigest'
lib/plugins/gravatar/lib/gravatar.rb:68:in `gravatar_url'
app/views/users/show.api.rsb:12
lib/redmine/views/builders/structure.rb:73:in `method_missing'
app/views/users/show.api.rsb:1
lib/redmine/views/builders.rb:38:in `for'
app/views/users/show.api.rsb:1
lib/redmine/sudo_mode.rb:61:in `sudo_mode'

37157.patch Magnifier (1.91 KB) Yuichi HARADA, 2022-05-26 06:48


Related issues

Related to Redmine - Feature #36303: Include avatar URL in Users API Closed

Associated revisions

Revision 21606
Added by Marius BALTEANU 3 months ago

Fix internal server error when trying to retrieve AnonymousUser's information via Users API (#37157).

Patch by Yuichi HARADA.

Revision 21615
Added by Marius BALTEANU 3 months ago

Merged r21606 to 5.0-stable (#37157).

History

#1 Updated by Go MAEDA 3 months ago

#2 Updated by Yuichi HARADA 3 months ago

Users API was raised with an exception because AnonymousUser has no email address set.
The following patch will solve the problem.

diff --git a/app/views/users/show.api.rsb b/app/views/users/show.api.rsb
index f6a323265a..d84be914ec 100644
--- a/app/views/users/show.api.rsb
+++ b/app/views/users/show.api.rsb
@@ -9,7 +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, default: Setting.gravatar_default}) if Setting.gravatar_enabled?
+  api.avatar_url gravatar_url(@user.mail, {rating: nil, size: nil, default: Setting.gravatar_default}) if @user.mail && Setting.gravatar_enabled?
   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?

#3 Updated by Marius BALTEANU 3 months ago

  • Target version set to 5.0.2

#4 Updated by Marius BALTEANU 3 months ago

  • Status changed from New to Closed
  • Assignee set to Marius BALTEANU
  • Resolution set to Fixed

Fixed committed, thanks!

Also available in: Atom PDF