forked from mirrors/akkoma
remove validate_expires_at from enqueue method
This commit is contained in:
parent
a098e10fd6
commit
15aece7238
4 changed files with 30 additions and 31 deletions
|
@ -155,8 +155,7 @@ defmodule Mix.Tasks.Pleroma.Database do
|
||||||
|
|
||||||
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
||||||
activity_id: activity.id,
|
activity_id: activity.id,
|
||||||
expires_at: expires_at,
|
expires_at: expires_at
|
||||||
validate: false
|
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -18,8 +18,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
||||||
| {:error, :expired_activities_disabled}
|
| {:error, :expired_activities_disabled}
|
||||||
| {:error, :expiration_too_close}
|
| {:error, :expiration_too_close}
|
||||||
def enqueue(args) do
|
def enqueue(args) do
|
||||||
with true <- enabled?(),
|
with true <- enabled?() do
|
||||||
args when is_map(args) <- validate_expires_at(args) do
|
|
||||||
{scheduled_at, args} = Map.pop(args, :expires_at)
|
{scheduled_at, args} = Map.pop(args, :expires_at)
|
||||||
|
|
||||||
args
|
args
|
||||||
|
@ -42,16 +41,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
||||||
end
|
end
|
||||||
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
|
defp find_activity(id) do
|
||||||
with nil <- Activity.get_by_id_with_object(id) do
|
with nil <- Activity.get_by_id_with_object(id) do
|
||||||
{:error, :activity_not_found}
|
{: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
|
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
|
||||||
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
||||||
activity_id: FlakeId.to_string(expiration.activity_id),
|
activity_id: FlakeId.to_string(expiration.activity_id),
|
||||||
expires_at: expires_at,
|
expires_at: expires_at
|
||||||
validate: false
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -10,21 +10,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivityTest do
|
||||||
|
|
||||||
alias Pleroma.Workers.PurgeExpiredActivity
|
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
|
test "enqueue job" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
|
|
||||||
|
@ -44,4 +29,31 @@ defmodule Pleroma.Workers.PurgeExpiredActivityTest do
|
||||||
|
|
||||||
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue