Rename `Pleroma.Backup` to `Pleroma.User.Backup`
This commit is contained in:
parent
c1976d5b19
commit
ad605e3e16
|
@ -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
|
||||
|
|
|
@ -3731,7 +3731,7 @@
|
|||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: Pleroma.Backup,
|
||||
key: Pleroma.User.Backup,
|
||||
type: :group,
|
||||
description: "Account Backup",
|
||||
children: [
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# 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
|
||||
|
@ -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
|
|
@ -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, "")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# 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
|
||||
|
||||
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue