diff --git a/lib/philomena/bans.ex b/lib/philomena/bans.ex index ee463130..767658e3 100644 --- a/lib/philomena/bans.ex +++ b/lib/philomena/bans.ex @@ -356,6 +356,7 @@ defmodule Philomena.Bans do Fingerprint |> select([f], %{ reason: f.reason, + note: f.note, valid_until: f.valid_until, generated_ban_id: f.generated_ban_id, type: ^"FingerprintBan" @@ -374,6 +375,7 @@ defmodule Philomena.Bans do Subnet |> select([s], %{ reason: s.reason, + note: s.note, valid_until: s.valid_until, generated_ban_id: s.generated_ban_id, type: ^"SubnetBan" @@ -390,6 +392,7 @@ defmodule Philomena.Bans do User |> select([u], %{ reason: u.reason, + note: u.note, valid_until: u.valid_until, generated_ban_id: u.generated_ban_id, type: ^"UserBan" diff --git a/lib/philomena_web/plugs/current_ban_plug.ex b/lib/philomena_web/plugs/current_ban_plug.ex index db7837c0..39f8d556 100644 --- a/lib/philomena_web/plugs/current_ban_plug.ex +++ b/lib/philomena_web/plugs/current_ban_plug.ex @@ -27,6 +27,25 @@ defmodule PhilomenaWeb.CurrentBanPlug do ban = Bans.exists_for?(user, ip, fingerprint) - Conn.assign(conn, :current_ban, ban) + cond do + discourage?(ban) -> + Conn.register_before_send(conn, fn conn -> + :timer.sleep(normal_time()) + + pass(error?(), conn) + end) + + true -> + Conn.assign(conn, :current_ban, ban) + end end + + defp discourage?(%{note: note}) when is_binary(note), do: String.contains?(note, "discourage") + defp discourage?(_ban), do: false + + defp normal_time, do: trunc(:rand.normal(10_000, 5_000)) + defp error?, do: :rand.uniform() < 0.05 + + defp pass(false, conn), do: conn + defp pass(_true, _conn), do: nil end