2022-02-26 06:11:42 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2022-02-26 06:11:42 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-07 10:44:42 +00:00
|
|
|
defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2]
|
|
|
|
|
|
|
|
def change do
|
2020-09-13 07:04:50 +00:00
|
|
|
Pleroma.Config.Oban.warn()
|
|
|
|
|
2021-01-17 06:58:41 +00:00
|
|
|
Application.ensure_all_started(:oban)
|
|
|
|
|
2020-09-07 10:44:42 +00:00
|
|
|
Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
|
|
|
|
strategy: :one_for_one,
|
|
|
|
name: Pleroma.Supervisor
|
|
|
|
)
|
|
|
|
|
|
|
|
if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do
|
|
|
|
from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|
|
|
|
|> Pleroma.Repo.stream()
|
|
|
|
|> Stream.each(fn token ->
|
|
|
|
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
|
|
|
|
token_id: token.id,
|
|
|
|
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
|
|
|
mod: Pleroma.Web.OAuth.Token
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
|
|
|
from(t in Pleroma.MFA.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|
|
|
|
|> Pleroma.Repo.stream()
|
|
|
|
|> Stream.each(fn token ->
|
|
|
|
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
|
|
|
|
token_id: token.id,
|
|
|
|
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
|
|
|
mod: Pleroma.MFA.Token
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
end
|