Actions
Defect #37157
closedInternal server error when trying to retrieve AnonymousUser's information via Users API
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
Related issues
Updated by Go MAEDA over 2 years ago
- Related to Feature #36303: Include avatar URL in Users API added
Updated by Yuichi HARADA over 2 years ago
- File 37157.patch 37157.patch added
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?
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