From 50d9fcbe29acae63ad2aec4eadedf7b9ba614428 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 11 Feb 2020 23:33:05 +0400 Subject: [PATCH] Hotlink logo instead of attachment --- config/config.exs | 2 +- lib/pleroma/emails/new_users_digest_email.ex | 16 ++++++---------- .../web/templates/layout/email_styled.html.eex | 2 +- .../{ => cron}/new_users_digest_worker.ex | 16 +++++++++------- .../cron/new_users_digest_worker_test.exs | 4 ++-- 5 files changed, 19 insertions(+), 21 deletions(-) rename lib/pleroma/workers/{ => cron}/new_users_digest_worker.ex (77%) diff --git a/config/config.exs b/config/config.exs index 06ae2f262..e97443028 100644 --- a/config/config.exs +++ b/config/config.exs @@ -488,7 +488,7 @@ {"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, diff --git a/lib/pleroma/emails/new_users_digest_email.ex b/lib/pleroma/emails/new_users_digest_email.ex index 21096a744..7d16b807f 100644 --- a/lib/pleroma/emails/new_users_digest_email.ex +++ b/lib/pleroma/emails/new_users_digest_email.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emails.NewUsersDigestEmail do @@ -12,14 +12,10 @@ defp instance_notify_email 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 @@ def new_users(to, users_and_statuses) 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 diff --git a/lib/pleroma/web/templates/layout/email_styled.html.eex b/lib/pleroma/web/templates/layout/email_styled.html.eex index eb5f59244..ca2caaf4d 100644 --- a/lib/pleroma/web/templates/layout/email_styled.html.eex +++ b/lib/pleroma/web/templates/layout/email_styled.html.eex @@ -128,7 +128,7 @@
Image diff --git a/lib/pleroma/workers/new_users_digest_worker.ex b/lib/pleroma/workers/cron/new_users_digest_worker.ex 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 845eb4bf7..951c2c054 100644 --- a/lib/pleroma/workers/new_users_digest_worker.ex +++ b/lib/pleroma/workers/cron/new_users_digest_worker.ex @@ -1,8 +1,8 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # 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 @@ def perform(_args, _job) 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 diff --git a/test/workers/cron/new_users_digest_worker_test.exs b/test/workers/cron/new_users_digest_worker_test.exs index f735cb152..2f439c1fe 100644 --- a/test/workers/cron/new_users_digest_worker_test.exs +++ b/test/workers/cron/new_users_digest_worker_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # 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)