mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
fixes #96: add tag blacklist
This commit is contained in:
parent
f5e249aa39
commit
7b49f8d978
2 changed files with 35 additions and 0 deletions
20
config/tag.json
Normal file
20
config/tag.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"blacklist": [
|
||||||
|
"tagme",
|
||||||
|
"tag me",
|
||||||
|
"not tagged",
|
||||||
|
"no tag",
|
||||||
|
"notag",
|
||||||
|
"notags",
|
||||||
|
"upvotes galore",
|
||||||
|
"downvotes galore",
|
||||||
|
"wall of faves",
|
||||||
|
"drama in the comments",
|
||||||
|
"drama in comments",
|
||||||
|
"tag needed",
|
||||||
|
"paywall",
|
||||||
|
"cringeworthy",
|
||||||
|
"solo oc",
|
||||||
|
"tag your shit"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
defmodule Philomena.Images.TagValidator do
|
defmodule Philomena.Images.TagValidator do
|
||||||
|
alias Philomena.Servers.Config
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
@safe_rating MapSet.new(["safe"])
|
@safe_rating MapSet.new(["safe"])
|
||||||
|
@ -19,6 +20,7 @@ defmodule Philomena.Images.TagValidator do
|
||||||
|
|
||||||
changeset
|
changeset
|
||||||
|> validate_number_of_tags(tag_set, 3)
|
|> validate_number_of_tags(tag_set, 3)
|
||||||
|
|> validate_bad_words(tag_set)
|
||||||
|> validate_has_rating(rating_set)
|
|> validate_has_rating(rating_set)
|
||||||
|> validate_safe(rating_set)
|
|> validate_safe(rating_set)
|
||||||
|> validate_sexual_exclusion(rating_set)
|
|> validate_sexual_exclusion(rating_set)
|
||||||
|
@ -50,6 +52,19 @@ defmodule Philomena.Images.TagValidator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_bad_words(changeset, tag_set) do
|
||||||
|
bad_words = MapSet.new(Config.get(:tag)["blacklist"])
|
||||||
|
intersection = MapSet.intersection(tag_set, bad_words)
|
||||||
|
|
||||||
|
cond do
|
||||||
|
MapSet.size(intersection) > 0 ->
|
||||||
|
Enum.reduce(intersection, changeset, &add_error(&2, :tag_input, "contains forbidden tag `#{&1}'"))
|
||||||
|
|
||||||
|
true ->
|
||||||
|
changeset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp validate_has_rating(changeset, %{safe: s, sexual: x, horror: h, gross: g})
|
defp validate_has_rating(changeset, %{safe: s, sexual: x, horror: h, gross: g})
|
||||||
when s == @empty and x == @empty and h == @empty and g == @empty do
|
when s == @empty and x == @empty and h == @empty and g == @empty do
|
||||||
changeset
|
changeset
|
||||||
|
|
Loading…
Reference in a new issue