mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Move ban ID generator to bans namespace
This commit is contained in:
parent
c89424d146
commit
4493dfcc1d
4 changed files with 9 additions and 7 deletions
|
@ -1,9 +1,9 @@
|
||||||
defmodule Philomena.Bans.Fingerprint do
|
defmodule Philomena.Bans.Fingerprint do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
import Philomena.Bans.IdGenerator
|
||||||
|
|
||||||
alias Philomena.Users.User
|
alias Philomena.Users.User
|
||||||
alias Philomena.Schema.BanId
|
|
||||||
|
|
||||||
schema "fingerprint_bans" do
|
schema "fingerprint_bans" do
|
||||||
belongs_to :banning_user, User
|
belongs_to :banning_user, User
|
||||||
|
@ -22,7 +22,7 @@ defmodule Philomena.Bans.Fingerprint do
|
||||||
def changeset(fingerprint_ban, attrs) do
|
def changeset(fingerprint_ban, attrs) do
|
||||||
fingerprint_ban
|
fingerprint_ban
|
||||||
|> cast(attrs, [:reason, :note, :enabled, :fingerprint, :valid_until])
|
|> cast(attrs, [:reason, :note, :enabled, :fingerprint, :valid_until])
|
||||||
|> BanId.put_ban_id("F")
|
|> put_ban_id("F")
|
||||||
|> validate_required([:reason, :enabled, :fingerprint, :valid_until])
|
|> validate_required([:reason, :enabled, :fingerprint, :valid_until])
|
||||||
|> check_constraint(:valid_until, name: :fingerprint_ban_duration_must_be_valid)
|
|> check_constraint(:valid_until, name: :fingerprint_ban_duration_must_be_valid)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
defmodule Philomena.Schema.BanId do
|
defmodule Philomena.Bans.IdGenerator do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
def put_ban_id(%{data: %{generated_ban_id: nil}} = changeset, prefix) do
|
def put_ban_id(%{data: %{generated_ban_id: nil}} = changeset, prefix) do
|
|
@ -1,9 +1,9 @@
|
||||||
defmodule Philomena.Bans.Subnet do
|
defmodule Philomena.Bans.Subnet do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
import Philomena.Bans.IdGenerator
|
||||||
|
|
||||||
alias Philomena.Users.User
|
alias Philomena.Users.User
|
||||||
alias Philomena.Schema.BanId
|
|
||||||
|
|
||||||
schema "subnet_bans" do
|
schema "subnet_bans" do
|
||||||
belongs_to :banning_user, User
|
belongs_to :banning_user, User
|
||||||
|
@ -22,7 +22,7 @@ defmodule Philomena.Bans.Subnet do
|
||||||
def changeset(subnet_ban, attrs) do
|
def changeset(subnet_ban, attrs) do
|
||||||
subnet_ban
|
subnet_ban
|
||||||
|> cast(attrs, [:reason, :note, :enabled, :specification, :valid_until])
|
|> cast(attrs, [:reason, :note, :enabled, :specification, :valid_until])
|
||||||
|> BanId.put_ban_id("S")
|
|> put_ban_id("S")
|
||||||
|> validate_required([:reason, :enabled, :specification, :valid_until])
|
|> validate_required([:reason, :enabled, :specification, :valid_until])
|
||||||
|> check_constraint(:valid_until, name: :subnet_ban_duration_must_be_valid)
|
|> check_constraint(:valid_until, name: :subnet_ban_duration_must_be_valid)
|
||||||
|> mask_specification()
|
|> mask_specification()
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
defmodule Philomena.Bans.User do
|
defmodule Philomena.Bans.User do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
import Philomena.Bans.IdGenerator
|
||||||
|
|
||||||
alias Philomena.Users.User
|
alias Philomena.Users.User
|
||||||
alias Philomena.Schema.BanId
|
|
||||||
|
|
||||||
schema "user_bans" do
|
schema "user_bans" do
|
||||||
belongs_to :user, User
|
belongs_to :user, User
|
||||||
|
@ -23,7 +23,7 @@ defmodule Philomena.Bans.User do
|
||||||
def changeset(user_ban, attrs) do
|
def changeset(user_ban, attrs) do
|
||||||
user_ban
|
user_ban
|
||||||
|> cast(attrs, [:reason, :note, :enabled, :override_ip_ban, :user_id, :valid_until])
|
|> 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])
|
|> validate_required([:reason, :enabled, :user_id, :valid_until])
|
||||||
|> check_constraint(:valid_until, name: :user_ban_duration_must_be_valid)
|
|> check_constraint(:valid_until, name: :user_ban_duration_must_be_valid)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue