Do not limit admins
authorEgor Kislitsyn <egor@kislitsyn.com>
Sun, 20 Sep 2020 17:06:16 +0000 (21:06 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 7 Oct 2020 14:35:27 +0000 (18:35 +0400)
lib/pleroma/backup.ex
test/web/admin_api/controllers/admin_api_controller_test.exs

index f5f39431df265bc6e165a7a05acf68a82b4cb5ae..e2673db804741e2d90094fc7c253d41be8916a9d 100644 (file)
@@ -30,12 +30,12 @@ defmodule Pleroma.Backup do
     timestamps()
   end
 
-  def create(user, admin_user_id \\ nil) do
+  def create(user, admin_id \\ nil) do
     with :ok <- validate_email_enabled(),
          :ok <- validate_user_email(user),
-         :ok <- validate_limit(user),
+         :ok <- validate_limit(user, admin_id),
          {:ok, backup} <- user |> new() |> Repo.insert() do
-      BackupWorker.process(backup, admin_user_id)
+      BackupWorker.process(backup, admin_id)
     end
   end
 
@@ -59,7 +59,9 @@ defmodule Pleroma.Backup do
     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
       %__MODULE__{inserted_at: inserted_at} ->
         days = Pleroma.Config.get([Pleroma.Backup, :limit_days])
index 4d331779e4b15591fcfc5c0310faac0ce616f6db..4b3abce0dfd46af0a4eb11f9f520e4acb628ac0e 100644 (file)
@@ -2044,6 +2044,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
 
       assert_email_sent(Pleroma.Emails.UserEmail.backup_is_ready_email(backup, admin.id))
     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