Hotlink logo instead of attachment
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 11 Feb 2020 19:33:05 +0000 (23:33 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 11 Feb 2020 19:33:05 +0000 (23:33 +0400)
config/config.exs
lib/pleroma/emails/new_users_digest_email.ex
lib/pleroma/web/templates/layout/email_styled.html.eex
lib/pleroma/workers/cron/new_users_digest_worker.ex [moved from lib/pleroma/workers/new_users_digest_worker.ex with 77% similarity]
test/workers/cron/new_users_digest_worker_test.exs

index 06ae2f2629ba5e04d6e4c5ed747b193802ae1251..e974430285e10e9fcea7d30d2d1425f3c64646e7 100644 (file)
@@ -488,7 +488,7 @@ config :pleroma, Oban,
     {"0 * * * *", Pleroma.Workers.Cron.StatsWorker},
     {"* * * * *", Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker},
     {"0 0 * * 0", Pleroma.Workers.Cron.DigestEmailsWorker},
-    {"0 0 * * *", Pleroma.Workers.NewUsersDigestWorker}
+    {"0 0 * * *", Pleroma.Workers.Cron.NewUsersDigestWorker}
   ]
 
 config :pleroma, :workers,
index 21096a7446b4cd01168d5069269c2b5daec3320e..7d16b807f60849d9ff33fa07b67c83d31d9cd91c 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Emails.NewUsersDigestEmail do
@@ -12,14 +12,10 @@ defmodule Pleroma.Emails.NewUsersDigestEmail do
   def new_users(to, users_and_statuses) do
     instance_name = Pleroma.Config.get([:instance, :name])
     styling = Pleroma.Config.get([Pleroma.Emails.UserEmail, :styling])
-    logo = Pleroma.Config.get([Pleroma.Emails.UserEmail, :logo])
 
-    logo_path =
-      if is_nil(logo) do
-        Path.join(:code.priv_dir(:pleroma), "static/static/logo.png")
-      else
-        Path.join(Pleroma.Config.get([:instance, :static_dir]), logo)
-      end
+    logo_url =
+      Pleroma.Web.Endpoint.url() <>
+        Pleroma.Config.get([:frontend_configurations, :pleroma_fe, :logo])
 
     new()
     |> to({to.name, to.email})
@@ -29,8 +25,8 @@ defmodule Pleroma.Emails.NewUsersDigestEmail do
       title: "New Users",
       users_and_statuses: users_and_statuses,
       instance: instance_name,
-      styling: styling
+      styling: styling,
+      logo_url: logo_url
     })
-    |> attachment(Swoosh.Attachment.new(logo_path, filename: "logo.png", type: :inline))
   end
 end
index eb5f592446afb99d2e09d7dbf83256d26fa035d0..ca2caaf4dece1bcdd8b93abed7362cb6718e7998 100644 (file)
                                                                                        <div align="center" class="img-container center"
                                                                                                style="padding-right: 0px;padding-left: 0px;">
                                                                                                <!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr style="line-height:0px"><td style="padding-right: 0px;padding-left: 0px;" align="center"><![endif]--><img
-                                                                                                       align="center" alt="Image" border="0" class="center" src="cid:logo.png"
+                                                                                                       align="center" alt="Image" border="0" class="center" src="<%= @logo_url %>"
                                                                                                        style="text-decoration: none; -ms-interpolation-mode: bicubic; border: 0; height: 80px; width: auto; max-height: 80px; display: block;"
                                                                                                        title="Image" height="80" />
                                                                                                <!--[if mso]></td></tr></table><![endif]-->
similarity index 77%
rename from lib/pleroma/workers/new_users_digest_worker.ex
rename to lib/pleroma/workers/cron/new_users_digest_worker.ex
index 845eb4bf713b1616b29e53b5f0da3427d5a6fbbd..951c2c0540a516cce9718b8e40475a2c9cbef4d8 100644 (file)
@@ -1,8 +1,8 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.Workers.NewUsersDigestWorker do
+defmodule Pleroma.Workers.Cron.NewUsersDigestWorker do
   alias Pleroma.Activity
   alias Pleroma.Repo
   alias Pleroma.User
@@ -48,11 +48,13 @@ defmodule Pleroma.Workers.NewUsersDigestWorker do
           {user, total_statuses, latest_status}
         end)
 
-      %{is_admin: true}
-      |> User.Query.build()
-      |> Repo.all()
-      |> Enum.map(&Pleroma.Emails.NewUsersDigestEmail.new_users(&1, users_and_statuses))
-      |> Enum.each(&Pleroma.Emails.Mailer.deliver/1)
+      if users_and_statuses != [] do
+        %{is_admin: true}
+        |> User.Query.build()
+        |> Repo.all()
+        |> Enum.map(&Pleroma.Emails.NewUsersDigestEmail.new_users(&1, users_and_statuses))
+        |> Enum.each(&Pleroma.Emails.Mailer.deliver/1)
+      end
     end
   end
 end
index f735cb152c3598b9608fe368a4fb52210c280646..2f439c1fedb59abb236b4892a2d39c2d7175bffb 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
@@ -8,7 +8,7 @@ defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
 
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.Web.CommonAPI
-  alias Pleroma.Workers.NewUsersDigestWorker
+  alias Pleroma.Workers.Cron.NewUsersDigestWorker
 
   test "it sends new users digest emails" do
     yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)