mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
Removes discourage bans (#65)
Co-authored-by: Parasprite <foalspeedahead@gmail.com>
This commit is contained in:
parent
5822635408
commit
e058a212e7
3 changed files with 1 additions and 25 deletions
|
@ -344,7 +344,6 @@ defmodule Philomena.Bans do
|
||||||
Fingerprint
|
Fingerprint
|
||||||
|> select([f], %{
|
|> select([f], %{
|
||||||
reason: f.reason,
|
reason: f.reason,
|
||||||
note: f.note,
|
|
||||||
valid_until: f.valid_until,
|
valid_until: f.valid_until,
|
||||||
generated_ban_id: f.generated_ban_id,
|
generated_ban_id: f.generated_ban_id,
|
||||||
type: ^"FingerprintBan"
|
type: ^"FingerprintBan"
|
||||||
|
@ -363,7 +362,6 @@ defmodule Philomena.Bans do
|
||||||
Subnet
|
Subnet
|
||||||
|> select([s], %{
|
|> select([s], %{
|
||||||
reason: s.reason,
|
reason: s.reason,
|
||||||
note: s.note,
|
|
||||||
valid_until: s.valid_until,
|
valid_until: s.valid_until,
|
||||||
generated_ban_id: s.generated_ban_id,
|
generated_ban_id: s.generated_ban_id,
|
||||||
type: ^"SubnetBan"
|
type: ^"SubnetBan"
|
||||||
|
@ -380,7 +378,6 @@ defmodule Philomena.Bans do
|
||||||
User
|
User
|
||||||
|> select([u], %{
|
|> select([u], %{
|
||||||
reason: u.reason,
|
reason: u.reason,
|
||||||
note: u.note,
|
|
||||||
valid_until: u.valid_until,
|
valid_until: u.valid_until,
|
||||||
generated_ban_id: u.generated_ban_id,
|
generated_ban_id: u.generated_ban_id,
|
||||||
type: ^"UserBan"
|
type: ^"UserBan"
|
||||||
|
|
|
@ -158,7 +158,6 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
Bans.User
|
Bans.User
|
||||||
|> where(user_id: ^user.id)
|
|> where(user_id: ^user.id)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.reject(&String.contains?(&1.note || "", "discourage"))
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
conn,
|
conn,
|
||||||
|
|
|
@ -24,26 +24,6 @@ defmodule PhilomenaWeb.CurrentBanPlug do
|
||||||
|
|
||||||
ban = Bans.exists_for?(user, ip, fingerprint)
|
ban = Bans.exists_for?(user, ip, fingerprint)
|
||||||
|
|
||||||
cond do
|
|
||||||
discourage?(ban) ->
|
|
||||||
Conn.register_before_send(conn, fn conn ->
|
|
||||||
:timer.sleep(normal_time())
|
|
||||||
|
|
||||||
pass(error?(), conn)
|
|
||||||
end)
|
|
||||||
|> Conn.assign(:current_ban, nil)
|
|
||||||
|
|
||||||
true ->
|
|
||||||
Conn.assign(conn, :current_ban, ban)
|
Conn.assign(conn, :current_ban, ban)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp discourage?(%{note: note}) when is_binary(note), do: String.contains?(note, "discourage")
|
|
||||||
defp discourage?(_ban), do: false
|
|
||||||
|
|
||||||
defp normal_time, do: :rand.normal(5_000, 25_000_000) |> trunc() |> max(0)
|
|
||||||
defp error?, do: :rand.uniform() < 0.05
|
|
||||||
|
|
||||||
defp pass(false, conn), do: conn
|
|
||||||
defp pass(_true, _conn), do: nil
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in a new issue