Add config for Pleroma.Backup

This commit is contained in:
Egor Kislitsyn 2020-09-04 18:30:39 +04:00
parent a0ad9bd734
commit 3ad7492f9d
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
5 changed files with 31 additions and 2 deletions

View file

@ -818,6 +818,10 @@ config :floki, :html_parser, Floki.HTMLParser.FastHtml
config :pleroma, Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator config :pleroma, Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator
config :pleroma, Pleroma.Backup,
purge_after_days: 30,
limit_days: 7
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs" import_config "#{Mix.env()}.exs"

View file

@ -3712,5 +3712,25 @@ config :pleroma, :config_description, [
] ]
} }
] ]
},
%{
group: :pleroma,
key: Pleroma.Backup,
type: :group,
description: "Account Backup",
children: [
%{
key: :purge_after_days,
type: :integer,
description: "Remove backup achives after N days",
suggestions: [30]
},
%{
key: :limit_days,
type: :integer,
description: "Limit user to export not more often than once per N days",
suggestions: [7]
}
]
} }
] ]

View file

@ -1083,6 +1083,11 @@ Control favicons for instances.
* `enabled`: Allow/disallow displaying and getting instances favicons * `enabled`: Allow/disallow displaying and getting instances favicons
## Account Backup
* `:purge_after_days` an integer, remove backup achives after N days.
* `:limit_days` an integer, limit user to export not more often than once per N days.
## Frontend management ## Frontend management
Frontends in Pleroma are swappable - you can specify which one to use here. Frontends in Pleroma are swappable - you can specify which one to use here.

View file

@ -49,7 +49,7 @@ defmodule Pleroma.Backup do
defp validate_limit(user) do defp validate_limit(user) do
case get_last(user.id) do case get_last(user.id) do
%__MODULE__{inserted_at: inserted_at} -> %__MODULE__{inserted_at: inserted_at} ->
days = 7 days = Pleroma.Config.get([Pleroma.Backup, :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

@ -27,7 +27,7 @@ defmodule Pleroma.BackupTest 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 = 7 limit_days = Pleroma.Config.get([Pleroma.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