Disable NewUsersDigestEmail by default
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 22 Jan 2020 16:53:06 +0000 (20:53 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 22 Jan 2020 16:53:06 +0000 (20:53 +0400)
config/config.exs
config/test.exs
lib/pleroma/workers/new_users_digest_worker.ex

index 53ea76dd36ef1e9e1f99f0559c28709d7f6acea3..3f0222f0ee8ad86b9262a419e576de7d091c41bd 100644 (file)
@@ -581,6 +581,8 @@ config :pleroma, Pleroma.Emails.UserEmail,
     text_muted_color: "#b9b9ba"
   }
 
+config :pleroma, Pleroma.Emails.NewUsersDigestEmail, enabled: false
+
 config :prometheus, Pleroma.Web.Endpoint.MetricsExporter, path: "/api/pleroma/app_metrics"
 
 config :pleroma, Pleroma.ScheduledActivity,
index 5c66a36f1d1ebfb11137ff1b516741e6d684f243..9da0ae484fbcabceb0a1440c0cbf6920867b6814 100644 (file)
@@ -97,6 +97,8 @@ config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock
 
 config :pleroma, :modules, runtime_dir: "test/fixtures/modules"
 
+config :pleroma, Pleroma.Emails.NewUsersDigestEmail, enabled: true
+
 if File.exists?("./config/test.secret.exs") do
   import_config "test.secret.exs"
 else
index 24cc6bdf303120bbb82b5c3b5ee7c1a9897640a4..b776b2c793441984179b27b21df255058aa02ece 100644 (file)
@@ -13,44 +13,46 @@ defmodule Pleroma.Workers.NewUsersDigestWorker do
 
   @impl Oban.Worker
   def perform(_args, _job) do
-    today = NaiveDateTime.utc_now() |> Timex.beginning_of_day()
-
-    a_day_ago =
-      today
-      |> Timex.shift(days: -1)
-      |> Timex.beginning_of_day()
-
-    users_and_statuses =
-      %{
-        local: true,
-        order_by: :inserted_at
-      }
+    if Pleroma.Config.get([Pleroma.Emails.NewUsersDigestEmail, :enabled]) do
+      today = NaiveDateTime.utc_now() |> Timex.beginning_of_day()
+
+      a_day_ago =
+        today
+        |> Timex.shift(days: -1)
+        |> Timex.beginning_of_day()
+
+      users_and_statuses =
+        %{
+          local: true,
+          order_by: :inserted_at
+        }
+        |> User.Query.build()
+        |> where([u], u.inserted_at >= ^a_day_ago and u.inserted_at < ^today)
+        |> Repo.all()
+        |> Enum.map(fn user ->
+          latest_status =
+            Activity
+            |> Activity.Queries.by_actor(user.ap_id)
+            |> Activity.Queries.by_type("Create")
+            |> Activity.with_preloaded_object()
+            |> order_by(desc: :inserted_at)
+            |> limit(1)
+            |> Repo.one()
+
+          total_statuses =
+            Activity
+            |> Activity.Queries.by_actor(user.ap_id)
+            |> Activity.Queries.by_type("Create")
+            |> Repo.aggregate(:count, :id)
+
+          {user, total_statuses, latest_status}
+        end)
+
+      %{is_admin: true}
       |> User.Query.build()
-      |> where([u], u.inserted_at >= ^a_day_ago and u.inserted_at < ^today)
       |> Repo.all()
-      |> Enum.map(fn user ->
-        latest_status =
-          Activity
-          |> Activity.Queries.by_actor(user.ap_id)
-          |> Activity.Queries.by_type("Create")
-          |> Activity.with_preloaded_object()
-          |> order_by(desc: :inserted_at)
-          |> limit(1)
-          |> Repo.one()
-
-        total_statuses =
-          Activity
-          |> Activity.Queries.by_actor(user.ap_id)
-          |> Activity.Queries.by_type("Create")
-          |> Repo.aggregate(:count, :id)
-
-        {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)
+      |> Enum.map(&Pleroma.Emails.NewUsersDigestEmail.new_users(&1, users_and_statuses))
+      |> Enum.each(&Pleroma.Emails.Mailer.deliver/1)
+    end
   end
 end