]> git.openstreetmap.org Git - rails.git/commitdiff
Use correct extension and type for avatar images attached to mails
authorTom Hughes <tom@compton.nu>
Wed, 9 Aug 2023 10:41:55 +0000 (11:41 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 9 Aug 2023 10:41:55 +0000 (11:41 +0100)
Fixes #4147

app/mailers/user_mailer.rb
app/views/user_mailer/_message_body.html.erb

index c5c0118e6f8b395da0569c7f12b040bd341f5ffc..a9c6b70f91eeb29d8538aa1c18859e199a38b8ad 100644 (file)
@@ -187,7 +187,25 @@ class UserMailer < ApplicationMailer
   end
 
   def attach_user_avatar(user)
-    attachments.inline["avatar.png"] = user_avatar_file(user)
+    @avatar = user_avatar_filename(user)
+    attachments.inline[@avatar] = user_avatar_file(user)
+  end
+
+  def user_avatar_filename(user)
+    avatar = user&.avatar
+    if avatar&.attached?
+      case avatar.content_type
+      when "image/png" then "avatar.png"
+      when "image/jpeg" then "avatar.jpg"
+      when "image/gif" then "avatar.gif"
+      when "image/bmp" then "avatar.bmp"
+      when "image/tiff" then "avatar.tif"
+      when "image/svg+xml" then "avatar.svg"
+      else "avatar"
+      end
+    else
+      "avatar.png"
+    end
   end
 
   def user_avatar_file(user)
index d572fb9d0a79e92e7486b56218d63792295b0116..851f153a2a9a2a1938d0130b97098d5b42a687b6 100644 (file)
@@ -3,7 +3,7 @@
     <td style="width: 50px; min-width: 50px; vertical-align: top; padding: 15px">
       <%= link_to(
             image_tag(
-              attachments["avatar.png"].url,
+              attachments[@avatar].url,
               :alt => @author,
               :title => @author,
               :width => 50,