Make it possible to bulk send confirmation emails to all unconfirmed users
authorMark Felder <feld@FreeBSD.org>
Tue, 8 Sep 2020 21:39:08 +0000 (16:39 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 8 Sep 2020 21:39:08 +0000 (16:39 -0500)
docs/administration/CLI_tasks/email.md
lib/mix/tasks/pleroma/email.ex
lib/pleroma/user/query.ex

index 00d2e74f83d9374b242cf406e8f0b0ea3110eff8..439ea877a3ef020ef6b66430a5e266f1bb8a44f1 100644 (file)
@@ -1,4 +1,4 @@
-# Managing emails
+# E-Mail administration tasks
 
 {! backend/administration/CLI_tasks/general_cli_task_info.include !}
 
@@ -30,3 +30,17 @@ Example:
     ```sh
     mix pleroma.email test --to root@example.org
     ```
+
+## Send confirmation emails to all unconfirmed user accounts
+
+=== "OTP"
+
+    ```sh
+     ./bin/pleroma_ctl email send_confirmation_mails
+    ```
+
+=== "From Source"
+
+    ```sh
+    mix pleroma.email send_confirmation_mails
+    ```
index d3fac6ec8f3420da3ec0b765932b49ba432f42e6..61d4319719b4f8b93fee5a0b4fb67e5a109f06fb 100644 (file)
@@ -2,7 +2,7 @@ defmodule Mix.Tasks.Pleroma.Email do
   use Mix.Task
   import Mix.Pleroma
 
-  @shortdoc "Simple Email test"
+  @shortdoc "Email administrative tasks"
   @moduledoc File.read!("docs/administration/CLI_tasks/email.md")
 
   def run(["test" | args]) do
@@ -21,4 +21,21 @@ defmodule Mix.Tasks.Pleroma.Email do
 
     shell_info("Test email has been sent to #{inspect(email.to)} from #{inspect(email.from)}")
   end
+
+  def run(["resend_confirmation_emails"]) do
+    start_pleroma()
+
+    Pleroma.User.Query.build(%{
+      local: true,
+      deactivated: false,
+      confirmation_pending: true,
+      invisible: false
+    })
+    |> Pleroma.RepoStreamer.chunk_stream(500)
+    |> Stream.each(fn users ->
+      users
+      |> Enum.each(fn user -> Pleroma.User.send_confirmation_email(user) end)
+    end)
+    |> Stream.run()
+  end
 end
index d618432fffcc70e8bb86ceb44baec07f26adb8dd..f59ca6f9cc7598873e6dffcbb999a648f2ce248c 100644 (file)
@@ -148,6 +148,10 @@ defmodule Pleroma.User.Query do
     |> where([u], not is_nil(u.nickname))
   end
 
+  defp compose_query({:confirmation_pending, bool}, query) do
+    where(query, [u], u.confirmation_pending == ^bool)
+  end
+
   defp compose_query({:need_approval, _}, query) do
     where(query, [u], u.approval_pending)
   end