mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 02:05:12 +00:00
remove validate_expires_at from enqueue method
This commit is contained in:
parent
a098e10fd6
commit
15aece7238
|
@ -155,8 +155,7 @@ defmodule Mix.Tasks.Pleroma.Database do
|
|||
|
||||
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
||||
activity_id: activity.id,
|
||||
expires_at: expires_at,
|
||||
validate: false
|
||||
expires_at: expires_at
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -18,8 +18,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
|||
| {:error, :expired_activities_disabled}
|
||||
| {:error, :expiration_too_close}
|
||||
def enqueue(args) do
|
||||
with true <- enabled?(),
|
||||
args when is_map(args) <- validate_expires_at(args) do
|
||||
with true <- enabled?() do
|
||||
{scheduled_at, args} = Map.pop(args, :expires_at)
|
||||
|
||||
args
|
||||
|
@ -42,16 +41,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
|||
end
|
||||
end
|
||||
|
||||
defp validate_expires_at(%{validate: false} = args), do: Map.delete(args, :validate)
|
||||
|
||||
defp validate_expires_at(args) do
|
||||
if expires_late_enough?(args[:expires_at]) do
|
||||
args
|
||||
else
|
||||
{:error, :expiration_too_close}
|
||||
end
|
||||
end
|
||||
|
||||
defp find_activity(id) do
|
||||
with nil <- Activity.get_by_id_with_object(id) do
|
||||
{:error, :activity_not_found}
|
||||
|
|
|
@ -17,8 +17,7 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
|
|||
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
|
||||
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
||||
activity_id: FlakeId.to_string(expiration.activity_id),
|
||||
expires_at: expires_at,
|
||||
validate: false
|
||||
expires_at: expires_at
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -10,21 +10,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivityTest do
|
|||
|
||||
alias Pleroma.Workers.PurgeExpiredActivity
|
||||
|
||||
test "denies expirations that don't live long enough" do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
assert {:error, :expiration_too_close} =
|
||||
PurgeExpiredActivity.enqueue(%{
|
||||
activity_id: activity.id,
|
||||
expires_at: DateTime.utc_now()
|
||||
})
|
||||
|
||||
refute_enqueued(
|
||||
worker: Pleroma.Workers.PurgeExpiredActivity,
|
||||
args: %{activity_id: activity.id}
|
||||
)
|
||||
end
|
||||
|
||||
test "enqueue job" do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
|
@ -44,4 +29,31 @@ defmodule Pleroma.Workers.PurgeExpiredActivityTest do
|
|||
|
||||
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
end
|
||||
|
||||
test "error if user was not found" do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
assert {:ok, _} =
|
||||
PurgeExpiredActivity.enqueue(%{
|
||||
activity_id: activity.id,
|
||||
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
||||
})
|
||||
|
||||
user = Pleroma.User.get_by_ap_id(activity.actor)
|
||||
Pleroma.Repo.delete(user)
|
||||
|
||||
assert {:error, :user_not_found} =
|
||||
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
|
||||
end
|
||||
|
||||
test "error if actiivity was not found" do
|
||||
assert {:ok, _} =
|
||||
PurgeExpiredActivity.enqueue(%{
|
||||
activity_id: "some_id",
|
||||
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
||||
})
|
||||
|
||||
assert {:error, :activity_not_found} =
|
||||
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: "some_if"})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue