forked from AkkomaGang/akkoma
Do not limit admins
This commit is contained in:
parent
17562bf414
commit
e4792ce76a
2 changed files with 30 additions and 4 deletions
|
@ -30,12 +30,12 @@ defmodule Pleroma.Backup do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(user, admin_user_id \\ nil) do
|
def create(user, admin_id \\ nil) do
|
||||||
with :ok <- validate_email_enabled(),
|
with :ok <- validate_email_enabled(),
|
||||||
:ok <- validate_user_email(user),
|
:ok <- validate_user_email(user),
|
||||||
:ok <- validate_limit(user),
|
:ok <- validate_limit(user, admin_id),
|
||||||
{:ok, backup} <- user |> new() |> Repo.insert() do
|
{:ok, backup} <- user |> new() |> Repo.insert() do
|
||||||
BackupWorker.process(backup, admin_user_id)
|
BackupWorker.process(backup, admin_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ def delete(backup) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_limit(user) do
|
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
|
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([Pleroma.Backup, :limit_days])
|
||||||
|
|
|
@ -2044,6 +2044,30 @@ test "it creates a backup", %{conn: conn} do
|
||||||
|
|
||||||
assert_email_sent(Pleroma.Emails.UserEmail.backup_is_ready_email(backup, admin.id))
|
assert_email_sent(Pleroma.Emails.UserEmail.backup_is_ready_email(backup, admin.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it doesn't limit admins", %{conn: conn} do
|
||||||
|
admin = insert(:user, is_admin: true)
|
||||||
|
token = insert(:oauth_admin_token, user: admin)
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
assert "" ==
|
||||||
|
conn
|
||||||
|
|> assign(:user, admin)
|
||||||
|
|> assign(:token, token)
|
||||||
|
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert [_backup] = Repo.all(Pleroma.Backup)
|
||||||
|
|
||||||
|
assert "" ==
|
||||||
|
conn
|
||||||
|
|> assign(:user, admin)
|
||||||
|
|> assign(:token, token)
|
||||||
|
|> post("/api/pleroma/admin/backups", %{nickname: user.nickname})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert Repo.aggregate(Pleroma.Backup, :count) == 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue