Rename Pleroma.Backup to Pleroma.User.Backup

This commit is contained in:
Egor Kislitsyn 2020-10-20 17:16:58 +04:00
parent c1976d5b19
commit ad605e3e16
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
11 changed files with 22 additions and 21 deletions

View file

@ -831,7 +831,7 @@
config :pleroma, Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator config :pleroma, Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator
config :pleroma, Pleroma.Backup, config :pleroma, Pleroma.User.Backup,
purge_after_days: 30, purge_after_days: 30,
limit_days: 7, limit_days: 7,
dir: nil dir: nil

View file

@ -3731,7 +3731,7 @@
}, },
%{ %{
group: :pleroma, group: :pleroma,
key: Pleroma.Backup, key: Pleroma.User.Backup,
type: :group, type: :group,
description: "Account Backup", description: "Account Backup",
children: [ children: [

View file

@ -1077,7 +1077,7 @@ Control favicons for instances.
* `enabled`: Allow/disallow displaying and getting instances favicons * `enabled`: Allow/disallow displaying and getting instances favicons
## Account Backup ## Pleroma.User.Backup
!!! note !!! note
Requires enabled email Requires enabled email

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Backup do defmodule Pleroma.User.Backup do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset 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 defp validate_limit(user, nil) do
case get_last(user.id) do case get_last(user.id) do
%__MODULE__{inserted_at: inserted_at} -> %__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) diff = Timex.diff(NaiveDateTime.utc_now(), inserted_at, :days)
if diff > days do if diff > days do

View file

@ -685,7 +685,7 @@ def stats(conn, params) do
def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do def create_backup(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
with %User{} = user <- User.get_by_nickname(nickname), 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"}) ModerationLog.insert_log(%{actor: admin, subject: user, action: "create_backup"})
json(conn, "") json(conn, "")

View file

@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupController do
use Pleroma.Web, :controller use Pleroma.Web, :controller
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.User.Backup
action_fallback(Pleroma.Web.MastodonAPI.FallbackController) action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
plug(OAuthScopesPlug, %{scopes: ["read:accounts"]} when action in [:index, :create]) 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 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaBackupOperation
def index(%{assigns: %{user: user}} = conn, _params) do def index(%{assigns: %{user: user}} = conn, _params) do
backups = Pleroma.Backup.list(user) backups = Backup.list(user)
render(conn, "index.json", backups: backups) render(conn, "index.json", backups: backups)
end end
def create(%{assigns: %{user: user}} = conn, _params) do def create(%{assigns: %{user: user}} = conn, _params) do
with {:ok, _} <- Pleroma.Backup.create(user) do with {:ok, _} <- Backup.create(user) do
backups = Pleroma.Backup.list(user) backups = Backup.list(user)
render(conn, "index.json", backups: backups) render(conn, "index.json", backups: backups)
end end
end end

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Web.PleromaAPI.BackupView do defmodule Pleroma.Web.PleromaAPI.BackupView do
use Pleroma.Web, :view use Pleroma.Web, :view
alias Pleroma.Backup alias Pleroma.User.Backup
alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.CommonAPI.Utils
def render("show.json", %{backup: %Backup{} = backup}) do def render("show.json", %{backup: %Backup{} = backup}) do

View file

@ -6,7 +6,7 @@ defmodule Pleroma.Workers.BackupWorker do
use Oban.Worker, queue: :backup, max_attempts: 1 use Oban.Worker, queue: :backup, max_attempts: 1
alias Oban.Job alias Oban.Job
alias Pleroma.Backup alias Pleroma.User.Backup
def process(backup, admin_user_id \\ nil) do def process(backup, admin_user_id \\ nil) do
%{"op" => "process", "backup_id" => backup.id, "admin_user_id" => admin_user_id} %{"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 end
def schedule_deletion(backup) do 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 time = 60 * 60 * 24 * days
scheduled_at = Calendar.NaiveDateTime.add!(backup.inserted_at, time) scheduled_at = Calendar.NaiveDateTime.add!(backup.inserted_at, time)

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.BackupTest do defmodule Pleroma.User.BackupTest do
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase use Pleroma.DataCase
@ -10,7 +10,7 @@ defmodule Pleroma.BackupTest do
import Pleroma.Factory import Pleroma.Factory
import Swoosh.TestAssertions import Swoosh.TestAssertions
alias Pleroma.Backup alias Pleroma.User.Backup
alias Pleroma.Bookmark alias Pleroma.Bookmark
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
@ -18,7 +18,7 @@ defmodule Pleroma.BackupTest do
setup do setup do
clear_config([Pleroma.Upload, :uploader]) clear_config([Pleroma.Upload, :uploader])
clear_config([Pleroma.Backup, :limit_days]) clear_config([Backup, :limit_days])
clear_config([Pleroma.Emails.Mailer, :enabled], true) clear_config([Pleroma.Emails.Mailer, :enabled], true)
end 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 test "it return an error if the export limit is over" do
%{id: user_id} = user = insert(:user) %{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) assert {:ok, %Oban.Job{args: args}} = Backup.create(user)
backup = Backup.get(args["backup_id"]) backup = Backup.get(args["backup_id"])
assert %Backup{user_id: ^user_id, processed: false, file_size: 0} = backup assert %Backup{user_id: ^user_id, processed: false, file_size: 0} = backup
@ -76,7 +76,7 @@ test "it process a backup record" do
end end
test "it removes outdated backups after creating a fresh one" do 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) Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
user = insert(:user) user = insert(:user)

View file

@ -2038,7 +2038,7 @@ test "it creates a backup", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname}) |> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200) |> json_response(200)
assert [backup] = Repo.all(Pleroma.Backup) assert [backup] = Repo.all(Pleroma.User.Backup)
ObanHelpers.perform_all() ObanHelpers.perform_all()
@ -2079,7 +2079,7 @@ test "it doesn't limit admins", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname}) |> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200) |> json_response(200)
assert [_backup] = Repo.all(Pleroma.Backup) assert [_backup] = Repo.all(Pleroma.User.Backup)
assert "" == assert "" ==
conn conn
@ -2088,7 +2088,7 @@ test "it doesn't limit admins", %{conn: conn} do
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname}) |> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|> json_response(200) |> json_response(200)
assert Repo.aggregate(Pleroma.Backup, :count) == 2 assert Repo.aggregate(Pleroma.User.Backup, :count) == 2
end end
end end
end end

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.Backup alias Pleroma.User.Backup
alias Pleroma.Web.PleromaAPI.BackupView alias Pleroma.Web.PleromaAPI.BackupView
setup do setup do