From 4493dfcc1d43842283d36d0cc1f31877e6ff8c83 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 9 Jul 2024 19:48:24 -0400 Subject: [PATCH] Move ban ID generator to bans namespace --- lib/philomena/bans/fingerprint.ex | 4 ++-- lib/philomena/{schema/ban_id.ex => bans/id_generator.ex} | 4 +++- lib/philomena/bans/subnet.ex | 4 ++-- lib/philomena/bans/user.ex | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) rename lib/philomena/{schema/ban_id.ex => bans/id_generator.ex} (82%) diff --git a/lib/philomena/bans/fingerprint.ex b/lib/philomena/bans/fingerprint.ex index 5e61f8e7..5b499554 100644 --- a/lib/philomena/bans/fingerprint.ex +++ b/lib/philomena/bans/fingerprint.ex @@ -1,9 +1,9 @@ defmodule Philomena.Bans.Fingerprint do use Ecto.Schema import Ecto.Changeset + import Philomena.Bans.IdGenerator alias Philomena.Users.User - alias Philomena.Schema.BanId schema "fingerprint_bans" do belongs_to :banning_user, User @@ -22,7 +22,7 @@ defmodule Philomena.Bans.Fingerprint do def changeset(fingerprint_ban, attrs) do fingerprint_ban |> cast(attrs, [:reason, :note, :enabled, :fingerprint, :valid_until]) - |> BanId.put_ban_id("F") + |> put_ban_id("F") |> validate_required([:reason, :enabled, :fingerprint, :valid_until]) |> check_constraint(:valid_until, name: :fingerprint_ban_duration_must_be_valid) end diff --git a/lib/philomena/schema/ban_id.ex b/lib/philomena/bans/id_generator.ex similarity index 82% rename from lib/philomena/schema/ban_id.ex rename to lib/philomena/bans/id_generator.ex index c1c8ee02..e2b7cf03 100644 --- a/lib/philomena/schema/ban_id.ex +++ b/lib/philomena/bans/id_generator.ex @@ -1,4 +1,6 @@ -defmodule Philomena.Schema.BanId do +defmodule Philomena.Bans.IdGenerator do + @moduledoc false + import Ecto.Changeset def put_ban_id(%{data: %{generated_ban_id: nil}} = changeset, prefix) do diff --git a/lib/philomena/bans/subnet.ex b/lib/philomena/bans/subnet.ex index e9b5bb95..2eeb424a 100644 --- a/lib/philomena/bans/subnet.ex +++ b/lib/philomena/bans/subnet.ex @@ -1,9 +1,9 @@ defmodule Philomena.Bans.Subnet do use Ecto.Schema import Ecto.Changeset + import Philomena.Bans.IdGenerator alias Philomena.Users.User - alias Philomena.Schema.BanId schema "subnet_bans" do belongs_to :banning_user, User @@ -22,7 +22,7 @@ defmodule Philomena.Bans.Subnet do def changeset(subnet_ban, attrs) do subnet_ban |> cast(attrs, [:reason, :note, :enabled, :specification, :valid_until]) - |> BanId.put_ban_id("S") + |> put_ban_id("S") |> validate_required([:reason, :enabled, :specification, :valid_until]) |> check_constraint(:valid_until, name: :subnet_ban_duration_must_be_valid) |> mask_specification() diff --git a/lib/philomena/bans/user.ex b/lib/philomena/bans/user.ex index 1f142ea8..efae6214 100644 --- a/lib/philomena/bans/user.ex +++ b/lib/philomena/bans/user.ex @@ -1,9 +1,9 @@ defmodule Philomena.Bans.User do use Ecto.Schema import Ecto.Changeset + import Philomena.Bans.IdGenerator alias Philomena.Users.User - alias Philomena.Schema.BanId schema "user_bans" do belongs_to :user, User @@ -23,7 +23,7 @@ defmodule Philomena.Bans.User do def changeset(user_ban, attrs) do user_ban |> cast(attrs, [:reason, :note, :enabled, :override_ip_ban, :user_id, :valid_until]) - |> BanId.put_ban_id("U") + |> put_ban_id("U") |> validate_required([:reason, :enabled, :user_id, :valid_until]) |> check_constraint(:valid_until, name: :user_ban_duration_must_be_valid) end