Patch #31391

Small refactorization of avatar methods

Added by Marius BALTEANU 3 months ago. Updated 3 months ago.

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

0%

Category:Code cleanup/refactoring
Target version:4.1.0

Description

Small refactorization of avatar methods:
  • move existing methods from ApplicationHelper to a new helper file (AvatarsHelper)
  • change default avatar size from 50 to 24 because most of the avatars are using the size 24
  • class 'gravatar' is always added and all custom classes are appended
  • added user name as default title for avatar images
  • added two new methods: assignee_avatar and author_avatar
This patch will change 2 existing behaviours:
  • in issue#show page, the titles for assignee and author will have the format: Assignee: <user name> and Author: <user name>
  • the default title of all avatar is now <user name>

The implementation could be improved more, but it is enough for now.

Any feedback is welcome!

0001-Small-refactorization-of-avatar-methods.patch Magnifier (19.9 KB) Marius BALTEANU, 2019-05-18 13:28


Related issues

Blocks Redmine - Patch #5899: Display user's gravatar when editing profile Closed 2010-07-18

Associated revisions

Revision 18175
Added by Go MAEDA 3 months ago

Small refactorization of avatar methods (#31391).

  • move existing methods from ApplicationHelper to a new helper file (AvatarsHelper)
  • change default avatar size from 50 to 24 because most of the avatars are using the size 24
  • class 'gravatar' is always added and all custom classes are appended
  • added user name as default title for avatar images
  • added two new methods: assignee_avatar and author_avatar

Patch by Marius BALTEANU.

Revision 18176
Added by Go MAEDA 3 months ago

Reverts undesired changes in r18175 (#31391).

Revision 18188
Added by Go MAEDA 3 months ago

assignee_avatar method causes NoMethodError if the given object is a group (#31391).

Patch by Go MAEDA.

History

#1 Updated by Go MAEDA 3 months ago

  • Target version set to 4.1.0

LGTM. Setting the target version to 4.1.0.

#2 Updated by Go MAEDA 3 months ago

  • Blocks Patch #5899: Display user's gravatar when editing profile added

#3 Updated by Go MAEDA 3 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch. Thanks.

#4 Updated by Go MAEDA 3 months ago

  • Status changed from Closed to Reopened

IssuesController#show raises "undefined method `html_safe' for nil:NilClass" error if the issue is assigned to a group. We can fix the error by applying the following fix.

Index: app/helpers/avatars_helper.rb
===================================================================
--- app/helpers/avatars_helper.rb    (リビジョン 18186)
+++ app/helpers/avatars_helper.rb    (作業コピー)
@@ -24,7 +24,7 @@
     return '' unless user

     options.merge!(:title => l(:field_assigned_to) + ": " + user.name)
-    avatar(user, options).html_safe
+    avatar(user, options).to_s.html_safe
   end

   def author_avatar(user, options={})
@@ -31,7 +31,7 @@
     return '' unless user

     options.merge!(:title => l(:field_author) + ": " + user.name)
-    avatar(user, options).html_safe
+    avatar(user, options).to_s.html_safe
   end

   # Returns the avatar image tag for the given +user+ if avatars are enabled

#5 Updated by Go MAEDA 3 months ago

  • Status changed from Reopened to Closed

Go MAEDA wrote:

IssuesController#show raises "undefined method `html_safe' for nil:NilClass" error if the issue is assigned to a group. We can fix the error by applying the following fix.

[...]

Committed the fix.

#6 Updated by Marius BALTEANU 3 months ago

Go MAEDA wrote:

Committed the fix.

Thanks! Anyway, I'll take again a look over the changes proposed by just to be sure that I didn't break anything else.

Also available in: Atom PDF