mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
fix mandatory descriptions for filters, missing public option
This commit is contained in:
parent
f8e5feb24c
commit
39d53ee763
3 changed files with 32 additions and 6 deletions
|
@ -66,7 +66,7 @@ defmodule Philomena.Filters do
|
|||
"""
|
||||
def create_filter(user, attrs \\ %{}) do
|
||||
%Filter{user_id: user.id}
|
||||
|> Filter.changeset(attrs)
|
||||
|> Filter.creation_changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
|
@ -84,7 +84,7 @@ defmodule Philomena.Filters do
|
|||
"""
|
||||
def update_filter(%Filter{} = filter, attrs) do
|
||||
filter
|
||||
|> Filter.changeset(attrs)
|
||||
|> Filter.update_changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Philomena.Filters.Filter do
|
|||
belongs_to :user, User
|
||||
|
||||
field :name, :string
|
||||
field :description, :string
|
||||
field :description, :string, default: ""
|
||||
field :system, :boolean
|
||||
field :public, :boolean
|
||||
field :hidden_complex_str, :string
|
||||
|
@ -29,7 +29,7 @@ defmodule Philomena.Filters.Filter do
|
|||
@doc false
|
||||
def changeset(filter, attrs) do
|
||||
user =
|
||||
filter
|
||||
change(filter).data
|
||||
|> Repo.preload(:user)
|
||||
|> Map.get(:user)
|
||||
|
||||
|
@ -44,7 +44,7 @@ defmodule Philomena.Filters.Filter do
|
|||
])
|
||||
|> 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_required([:name])
|
||||
|> validate_my_downvotes(:spoilered_complex_str)
|
||||
|> validate_my_downvotes(:hidden_complex_str)
|
||||
|> Search.validate_search(:spoilered_complex_str, user)
|
||||
|
@ -52,6 +52,16 @@ defmodule Philomena.Filters.Filter do
|
|||
|> unsafe_validate_unique([:user_id, :name], Repo)
|
||||
end
|
||||
|
||||
def creation_changeset(filter, attrs) do
|
||||
filter
|
||||
|> cast(attrs, [:public])
|
||||
|> changeset(attrs)
|
||||
end
|
||||
|
||||
def update_changeset(filter, attrs) do
|
||||
changeset(filter, attrs)
|
||||
end
|
||||
|
||||
def deletion_changeset(filter) do
|
||||
filter
|
||||
|> change()
|
||||
|
|
|
@ -65,4 +65,20 @@
|
|||
strong> WARNING:
|
||||
' This filter is applied along with your tag filters. Tag filters may hide images that you mean to filter more precisely here. Double-check to make sure they don't interfere.
|
||||
|
||||
= submit "Save Filter", class: "button"
|
||||
= cond do
|
||||
- is_nil(input_value(f, :id)) ->
|
||||
.field
|
||||
= checkbox f, :public, class: "checkbox"
|
||||
= label f, :public
|
||||
|
||||
.fieldlabel
|
||||
strong You probably do not want to check this unless you know what you are doing - it cannot be changed later
|
||||
| . Pulic filters can be shared with other users and used by them; if you make changes to a filter, it will update all users of that filter.
|
||||
|
||||
- input_value(f, :public) == true ->
|
||||
.fieldlabel
|
||||
strong Changes made to this filter will affect anyone else using this filter! Check your changes, and make sure your changes don't change the filter's intent.
|
||||
|
||||
- true ->
|
||||
|
||||
= submit "Save Filter", class: "button"
|
||||
|
|
Loading…
Reference in a new issue