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
},
%{
group: :pleroma,
- key: Pleroma.Backup,
+ key: Pleroma.User.Backup,
type: :group,
description: "Account Backup",
children: [
* `enabled`: Allow/disallow displaying and getting instances favicons
-## Account Backup
+## Pleroma.User.Backup
!!! note
Requires enabled email
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Backup do
+defmodule Pleroma.User.Backup do
use Ecto.Schema
import Ecto.Changeset
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
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, "")
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])
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
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
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}
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)
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# 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
import Pleroma.Factory
import Swoosh.TestAssertions
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
alias Pleroma.Bookmark
alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
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
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
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)
|> 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()
|> 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
|> 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
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Backup
+ alias Pleroma.User.Backup
alias Pleroma.Web.PleromaAPI.BackupView
setup do