Add "Your backup is ready" email

This commit is contained in:
Egor Kislitsyn 2020-09-17 18:42:24 +04:00
parent e52dd62e14
commit 7fdd81d000
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
3 changed files with 25 additions and 2 deletions

View File

@ -189,4 +189,20 @@ def unsubscribe_url(user, notifications_type) do
Router.Helpers.subscription_url(Endpoint, :unsubscribe, token) Router.Helpers.subscription_url(Endpoint, :unsubscribe, token)
end end
def backup_is_ready_email(backup) do
%{user: user} = Pleroma.Repo.preload(backup, :user)
download_url = Pleroma.Web.PleromaAPI.BackupView.download_url(backup)
html_body = """
<p>You requested a full backup of your Pleroma account. It's ready for download:</p>
<p><a href="#{download_url}"></a></p>
"""
new()
|> to(recipient(user))
|> from(sender())
|> subject("Your account archive is ready")
|> html_body(html_body)
end
end end

View File

@ -34,7 +34,11 @@ def perform(%Job{args: %{"op" => "process", "backup_id" => backup_id}}) do
with {:ok, %Backup{} = backup} <- with {:ok, %Backup{} = backup} <-
backup_id |> Backup.get() |> Backup.process(), backup_id |> Backup.get() |> Backup.process(),
{:ok, _job} <- schedule_deletion(backup), {:ok, _job} <- schedule_deletion(backup),
:ok <- Backup.remove_outdated(backup) do :ok <- Backup.remove_outdated(backup),
{:ok, _} <-
backup
|> Pleroma.Emails.UserEmail.backup_is_ready_email()
|> Pleroma.Emails.Mailer.deliver() do
{:ok, backup} {:ok, backup}
end end
end end

View File

@ -6,8 +6,9 @@ defmodule Pleroma.BackupTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory
import Mock import Mock
import Pleroma.Factory
import Swoosh.TestAssertions
alias Pleroma.Backup alias Pleroma.Backup
alias Pleroma.Bookmark alias Pleroma.Bookmark
@ -65,6 +66,8 @@ test "it process a backup record" do
assert_enqueued(worker: BackupWorker, args: delete_job_args) assert_enqueued(worker: BackupWorker, args: delete_job_args)
assert {:ok, backup} = perform_job(BackupWorker, delete_job_args) assert {:ok, backup} = perform_job(BackupWorker, delete_job_args)
refute Backup.get(backup_id) refute Backup.get(backup_id)
assert_email_sent(Pleroma.Emails.UserEmail.backup_is_ready_email(backup))
end end
test "it removes outdated backups after creating a fresh one" do test "it removes outdated backups after creating a fresh one" do