Project

General

Profile

Actions

Defect #37157

closed

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

Added by Go MAEDA over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
REST API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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'

Files

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

Related issues

Related to Redmine - Feature #36303: Include avatar URL in Users APIClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA over 2 years ago

Actions #2

Updated by Yuichi HARADA over 2 years 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?
Actions #3

Updated by Marius BĂLTEANU over 2 years ago

  • Target version set to 5.0.2
Actions #4

Updated by Marius BĂLTEANU over 2 years ago

  • Status changed from New to Closed
  • Assignee set to Marius BĂLTEANU
  • Resolution set to Fixed

Fixed committed, thanks!

Actions

Also available in: Atom PDF