fixes #96: add tag blacklist

This commit is contained in:
byte[] 2020-04-30 16:34:35 -04:00
parent f5e249aa39
commit 7b49f8d978
2 changed files with 35 additions and 0 deletions

20
config/tag.json Normal file
View 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"
]
}

View file

@ -1,4 +1,5 @@
defmodule Philomena.Images.TagValidator do
alias Philomena.Servers.Config
import Ecto.Changeset
@safe_rating MapSet.new(["safe"])
@ -19,6 +20,7 @@ defmodule Philomena.Images.TagValidator do
changeset
|> validate_number_of_tags(tag_set, 3)
|> validate_bad_words(tag_set)
|> validate_has_rating(rating_set)
|> validate_safe(rating_set)
|> validate_sexual_exclusion(rating_set)
@ -50,6 +52,19 @@ defmodule Philomena.Images.TagValidator do
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})
when s == @empty and x == @empty and h == @empty and g == @empty do
changeset