diff --git a/config/config.exs b/config/config.exs
index 63e386250..c758c818c 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -831,7 +831,7 @@
config :pleroma, Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator
-config :pleroma, Pleroma.Backup,
+config :pleroma, Pleroma.User.Backup,
purge_after_days: 30,
limit_days: 7,
dir: nil
diff --git a/config/description.exs b/config/description.exs
index 88f2a6133..9f23b6d3d 100644
--- a/config/description.exs
+++ b/config/description.exs
@@ -3731,7 +3731,7 @@
},
%{
group: :pleroma,
- key: Pleroma.Backup,
+ key: Pleroma.User.Backup,
type: :group,
description: "Account Backup",
children: [
diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md
index aafc43f3d..b40a2aebf 100644
--- a/docs/configuration/cheatsheet.md
+++ b/docs/configuration/cheatsheet.md
@@ -1077,7 +1077,7 @@ Control favicons for instances.
* `enabled`: Allow/disallow displaying and getting instances favicons
-## Account Backup
+## Pleroma.User.Backup
!!! note
Requires enabled email
diff --git a/lib/pleroma/backup.ex b/lib/pleroma/user/backup.ex
similarity index 98%
rename from lib/pleroma/backup.ex
rename to lib/pleroma/user/backup.ex
index 629e879a7..a9041fd94 100644
--- a/lib/pleroma/backup.ex
+++ b/lib/pleroma/user/backup.ex
@@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Backup do
+defmodule Pleroma.User.Backup do
use Ecto.Schema
import Ecto.Changeset
@@ -65,7 +65,7 @@ defp validate_limit(_user, admin_id) when is_binary(admin_id), do: :ok
defp validate_limit(user, nil) do
case get_last(user.id) do
%__MODULE__{inserted_at: inserted_at} ->
- days = Pleroma.Config.get([Pleroma.Backup, :limit_days])
+ days = Pleroma.Config.get([__MODULE__, :limit_days])
diff = Timex.diff(NaiveDateTime.utc_now(), inserted_at, :days)
if diff > days do
diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
index a4f0d7d34..0a27c5861 100644
--- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
@@ -685,7 +685,7 @@ def stats(conn, params) do
def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
with %User{} = user <- User.get_by_nickname(nickname),
- {:ok, _} <- Pleroma.Backup.create(user, admin.id) do
+ {:ok, _} <- Pleroma.User.Backup.create(user, admin.id) do
ModerationLog.insert_log(%{actor: admin, subject: user, action: "create_backup"})
json(conn, "")
diff --git a/lib/pleroma/web/pleroma_api/controllers/backup_controller.ex b/lib/pleroma/web/pleroma_api/controllers/backup_controller.ex
index 8e3d081f3..bd7b36880 100644
--- a/lib/pleroma/web/pleroma_api/controllers/backup_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/backup_controller.ex
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupController do
use Pleroma.Web, :controller
alias Pleroma.Web.Plugs.OAuthScopesPlug
+ alias Pleroma.User.Backup
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
plug(OAuthScopesPlug, %{scopes: ["read:accounts"]} when action in [:index, :create])
@@ -14,13 +15,13 @@ defmodule Pleroma.Web.PleromaAPI.BackupController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaBackupOperation
def index(%{assigns: %{user: user}} = conn, _params) do
- backups = Pleroma.Backup.list(user)
+ backups = Backup.list(user)
render(conn, "index.json", backups: backups)
end
def create(%{assigns: %{user: user}} = conn, _params) do
- with {:ok, _} <- Pleroma.Backup.create(user) do
- backups = Pleroma.Backup.list(user)
+ with {:ok, _} <- Backup.create(user) do
+ backups = Backup.list(user)
render(conn, "index.json", backups: backups)
end
end
diff --git a/lib/pleroma/web/pleroma_api/views/backup_view.ex b/lib/pleroma/web/pleroma_api/views/backup_view.ex
index bf40a001e..af75876aa 100644
--- a/lib/pleroma/web/pleroma_api/views/backup_view.ex
+++ b/lib/pleroma/web/pleroma_api/views/backup_view.ex
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.PleromaAPI.BackupView do
use Pleroma.Web, :view
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
alias Pleroma.Web.CommonAPI.Utils
def render("show.json", %{backup: %Backup{} = backup}) do
diff --git a/lib/pleroma/workers/backup_worker.ex b/lib/pleroma/workers/backup_worker.ex
index 65754b6a2..5b4985983 100644
--- a/lib/pleroma/workers/backup_worker.ex
+++ b/lib/pleroma/workers/backup_worker.ex
@@ -6,7 +6,7 @@ defmodule Pleroma.Workers.BackupWorker do
use Oban.Worker, queue: :backup, max_attempts: 1
alias Oban.Job
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
def process(backup, admin_user_id \\ nil) do
%{"op" => "process", "backup_id" => backup.id, "admin_user_id" => admin_user_id}
@@ -15,7 +15,7 @@ def process(backup, admin_user_id \\ nil) do
end
def schedule_deletion(backup) do
- days = Pleroma.Config.get([Pleroma.Backup, :purge_after_days])
+ days = Pleroma.Config.get([Backup, :purge_after_days])
time = 60 * 60 * 24 * days
scheduled_at = Calendar.NaiveDateTime.add!(backup.inserted_at, time)
diff --git a/test/pleroma/backup_test.exs b/test/pleroma/user/backup_test.exs
similarity index 97%
rename from test/pleroma/backup_test.exs
rename to test/pleroma/user/backup_test.exs
index 078e03621..5ad587833 100644
--- a/test/pleroma/backup_test.exs
+++ b/test/pleroma/user/backup_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.BackupTest do
+defmodule Pleroma.User.BackupTest do
use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase
@@ -10,7 +10,7 @@ defmodule Pleroma.BackupTest do
import Pleroma.Factory
import Swoosh.TestAssertions
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
alias Pleroma.Bookmark
alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
@@ -18,7 +18,7 @@ defmodule Pleroma.BackupTest do
setup do
clear_config([Pleroma.Upload, :uploader])
- clear_config([Pleroma.Backup, :limit_days])
+ clear_config([Backup, :limit_days])
clear_config([Pleroma.Emails.Mailer, :enabled], true)
end
@@ -44,7 +44,7 @@ test "it creates a backup record and an Oban job" do
test "it return an error if the export limit is over" do
%{id: user_id} = user = insert(:user)
- limit_days = Pleroma.Config.get([Pleroma.Backup, :limit_days])
+ limit_days = Pleroma.Config.get([Backup, :limit_days])
assert {:ok, %Oban.Job{args: args}} = Backup.create(user)
backup = Backup.get(args["backup_id"])
assert %Backup{user_id: ^user_id, processed: false, file_size: 0} = backup
@@ -76,7 +76,7 @@ test "it process a backup record" do
end
test "it removes outdated backups after creating a fresh one" do
- Pleroma.Config.put([Pleroma.Backup, :limit_days], -1)
+ Pleroma.Config.put([Backup, :limit_days], -1)
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
user = insert(:user)
diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
index 34d48c2c1..5efe8ef71 100644
--- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
@@ -2038,7 +2038,7 @@ test "it creates a backup", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200)
- assert [backup] = Repo.all(Pleroma.Backup)
+ assert [backup] = Repo.all(Pleroma.User.Backup)
ObanHelpers.perform_all()
@@ -2079,7 +2079,7 @@ test "it doesn't limit admins", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200)
- assert [_backup] = Repo.all(Pleroma.Backup)
+ assert [_backup] = Repo.all(Pleroma.User.Backup)
assert "" ==
conn
@@ -2088,7 +2088,7 @@ test "it doesn't limit admins", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200)
- assert Repo.aggregate(Pleroma.Backup, :count) == 2
+ assert Repo.aggregate(Pleroma.User.Backup, :count) == 2
end
end
end
diff --git a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
index b2ac74c7d..f1941f6dd 100644
--- a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
alias Pleroma.Web.PleromaAPI.BackupView
setup do