mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
break compile time dependencies in schema helpers
This commit is contained in:
parent
f278362fda
commit
907e030b3a
9 changed files with 39 additions and 38 deletions
|
@ -2,7 +2,7 @@ defmodule Philomena.Adverts.Advert do
|
|||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
import Philomena.Schema.Time
|
||||
alias Philomena.Schema.Time
|
||||
|
||||
schema "adverts" do
|
||||
field :image, :string
|
||||
|
@ -34,15 +34,15 @@ defmodule Philomena.Adverts.Advert do
|
|||
def changeset(advert, attrs) do
|
||||
advert
|
||||
|> cast(attrs, [])
|
||||
|> propagate_time(:start_date, :start_time)
|
||||
|> propagate_time(:finish_date, :finish_time)
|
||||
|> Time.propagate_time(:start_date, :start_time)
|
||||
|> Time.propagate_time(:finish_date, :finish_time)
|
||||
end
|
||||
|
||||
def save_changeset(advert, attrs) do
|
||||
advert
|
||||
|> cast(attrs, [:title, :link, :start_time, :finish_time, :live, :restrictions, :notes])
|
||||
|> assign_time(:start_time, :start_date)
|
||||
|> assign_time(:finish_time, :finish_date)
|
||||
|> Time.assign_time(:start_time, :start_date)
|
||||
|> Time.assign_time(:finish_time, :finish_date)
|
||||
|> validate_required([:title, :link, :start_date, :finish_date])
|
||||
|> validate_inclusion(:restrictions, ["none", "nsfw", "sfw"])
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ defmodule Philomena.Bans.Fingerprint do
|
|||
import Ecto.Changeset
|
||||
|
||||
alias Philomena.Users.User
|
||||
import Philomena.Schema.Time
|
||||
import Philomena.Schema.BanId
|
||||
alias Philomena.Schema.Time
|
||||
alias Philomena.Schema.BanId
|
||||
|
||||
schema "fingerprint_bans" do
|
||||
belongs_to :banning_user, User
|
||||
|
@ -25,14 +25,14 @@ defmodule Philomena.Bans.Fingerprint do
|
|||
def changeset(fingerprint_ban, attrs) do
|
||||
fingerprint_ban
|
||||
|> cast(attrs, [])
|
||||
|> propagate_time(:valid_until, :until)
|
||||
|> Time.propagate_time(:valid_until, :until)
|
||||
end
|
||||
|
||||
def save_changeset(fingerprint_ban, attrs) do
|
||||
fingerprint_ban
|
||||
|> cast(attrs, [:reason, :note, :enabled, :fingerprint, :until])
|
||||
|> assign_time(:until, :valid_until)
|
||||
|> put_ban_id("F")
|
||||
|> Time.assign_time(:until, :valid_until)
|
||||
|> BanId.put_ban_id("F")
|
||||
|> validate_required([:reason, :enabled, :fingerprint, :valid_until])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ defmodule Philomena.Bans.Subnet do
|
|||
import Ecto.Changeset
|
||||
|
||||
alias Philomena.Users.User
|
||||
import Philomena.Schema.Time
|
||||
import Philomena.Schema.BanId
|
||||
alias Philomena.Schema.Time
|
||||
alias Philomena.Schema.BanId
|
||||
|
||||
schema "subnet_bans" do
|
||||
belongs_to :banning_user, User
|
||||
|
@ -25,14 +25,14 @@ defmodule Philomena.Bans.Subnet do
|
|||
def changeset(subnet_ban, attrs) do
|
||||
subnet_ban
|
||||
|> cast(attrs, [])
|
||||
|> propagate_time(:valid_until, :until)
|
||||
|> Time.propagate_time(:valid_until, :until)
|
||||
end
|
||||
|
||||
def save_changeset(subnet_ban, attrs) do
|
||||
subnet_ban
|
||||
|> cast(attrs, [:reason, :note, :enabled, :specification, :until])
|
||||
|> assign_time(:until, :valid_until)
|
||||
|> put_ban_id("S")
|
||||
|> Time.assign_time(:until, :valid_until)
|
||||
|> BanId.put_ban_id("S")
|
||||
|> validate_required([:reason, :enabled, :specification, :valid_until])
|
||||
|> mask_specification()
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@ defmodule Philomena.Bans.User do
|
|||
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Repo
|
||||
import Philomena.Schema.Time
|
||||
import Philomena.Schema.BanId
|
||||
alias Philomena.Schema.Time
|
||||
alias Philomena.Schema.BanId
|
||||
|
||||
schema "user_bans" do
|
||||
belongs_to :user, User
|
||||
|
@ -28,16 +28,16 @@ defmodule Philomena.Bans.User do
|
|||
def changeset(user_ban, attrs) do
|
||||
user_ban
|
||||
|> cast(attrs, [])
|
||||
|> propagate_time(:valid_until, :until)
|
||||
|> Time.propagate_time(:valid_until, :until)
|
||||
|> populate_username()
|
||||
end
|
||||
|
||||
def save_changeset(user_ban, attrs) do
|
||||
user_ban
|
||||
|> cast(attrs, [:reason, :note, :enabled, :override_ip_ban, :username, :until])
|
||||
|> assign_time(:until, :valid_until)
|
||||
|> Time.assign_time(:until, :valid_until)
|
||||
|> populate_user_id()
|
||||
|> put_ban_id("U")
|
||||
|> BanId.put_ban_id("U")
|
||||
|> validate_required([:reason, :enabled, :user_id, :valid_until])
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
defmodule Philomena.Filters.Filter do
|
||||
use Ecto.Schema
|
||||
import Philomena.Schema.TagList
|
||||
import Philomena.Schema.Search
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Philomena.Schema.TagList
|
||||
alias Philomena.Schema.Search
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Repo
|
||||
|
||||
|
@ -35,13 +35,13 @@ defmodule Philomena.Filters.Filter do
|
|||
|
||||
filter
|
||||
|> cast(attrs, [:spoilered_tag_list, :hidden_tag_list, :description, :name, :spoilered_complex_str, :hidden_complex_str])
|
||||
|> propagate_tag_list(:spoilered_tag_list, :spoilered_tag_ids)
|
||||
|> propagate_tag_list(:hidden_tag_list, :hidden_tag_ids)
|
||||
|> TagList.propagate_tag_list(:spoilered_tag_list, :spoilered_tag_ids)
|
||||
|> TagList.propagate_tag_list(:hidden_tag_list, :hidden_tag_ids)
|
||||
|> validate_required([:name, :description])
|
||||
|> validate_my_downvotes(:spoilered_complex_str)
|
||||
|> validate_my_downvotes(:hidden_complex_str)
|
||||
|> validate_search(:spoilered_complex_str, user)
|
||||
|> validate_search(:hidden_complex_str, user)
|
||||
|> Search.validate_search(:spoilered_complex_str, user)
|
||||
|> Search.validate_search(:hidden_complex_str, user)
|
||||
|> unsafe_validate_unique([:user_id, :name], Repo)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ defmodule Philomena.SiteNotices.SiteNotice do
|
|||
import Ecto.Changeset
|
||||
|
||||
alias Philomena.Users.User
|
||||
import Philomena.Schema.Time
|
||||
alias Philomena.Schema.Time
|
||||
|
||||
schema "site_notices" do
|
||||
belongs_to :user, User
|
||||
|
@ -26,15 +26,15 @@ defmodule Philomena.SiteNotices.SiteNotice do
|
|||
def changeset(site_notice, attrs) do
|
||||
site_notice
|
||||
|> cast(attrs, [])
|
||||
|> propagate_time(:start_date, :start_time)
|
||||
|> propagate_time(:finish_date, :finish_time)
|
||||
|> Time.propagate_time(:start_date, :start_time)
|
||||
|> Time.propagate_time(:finish_date, :finish_time)
|
||||
|> validate_required([])
|
||||
end
|
||||
|
||||
def save_changeset(site_notice, attrs) do
|
||||
site_notice
|
||||
|> cast(attrs, [:title, :text, :link, :link_text, :live, :start_time, :finish_time])
|
||||
|> assign_time(:start_time, :start_date)
|
||||
|> assign_time(:finish_time, :finish_date)
|
||||
|> Time.assign_time(:start_time, :start_date)
|
||||
|> Time.assign_time(:finish_time, :finish_date)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,9 @@ defmodule Philomena.Users.User do
|
|||
extensions: [PowResetPassword, PowLockout]
|
||||
|
||||
import Ecto.Changeset
|
||||
import Philomena.Schema.TagList
|
||||
import Philomena.Schema.Search
|
||||
|
||||
alias Philomena.Schema.TagList
|
||||
alias Philomena.Schema.Search
|
||||
|
||||
alias Philomena.Filters.Filter
|
||||
alias Philomena.UserLinks.UserLink
|
||||
|
@ -206,12 +207,12 @@ defmodule Philomena.Users.User do
|
|||
:anonymous_by_default, :scale_large_images, :comments_per_page, :theme,
|
||||
:no_spoilered_in_watched, :use_centered_layout, :hide_vote_counts
|
||||
])
|
||||
|> propagate_tag_list(:watched_tag_list, :watched_tag_ids)
|
||||
|> TagList.propagate_tag_list(:watched_tag_list, :watched_tag_ids)
|
||||
|> validate_inclusion(:theme, ~W(default dark red))
|
||||
|> validate_inclusion(:images_per_page, 15..50)
|
||||
|> validate_inclusion(:comments_per_page, 15..100)
|
||||
|> validate_search(:watched_images_query_str, user, true)
|
||||
|> validate_search(:watched_images_exclude_str, user, true)
|
||||
|> Search.validate_search(:watched_images_query_str, user, true)
|
||||
|> Search.validate_search(:watched_images_exclude_str, user, true)
|
||||
end
|
||||
|
||||
def description_changeset(user, attrs) do
|
||||
|
|
Loading…
Reference in a new issue