mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
fix artist dnp validation
This commit is contained in:
parent
abd441fb4d
commit
fd9ea4a991
1 changed files with 12 additions and 5 deletions
|
@ -3,6 +3,7 @@ defmodule Philomena.Images.DnpValidator do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
alias Philomena.Tags.Tag
|
alias Philomena.Tags.Tag
|
||||||
|
alias Philomena.UserLinks.UserLink
|
||||||
|
|
||||||
def validate_dnp(changeset, uploader) do
|
def validate_dnp(changeset, uploader) do
|
||||||
tags =
|
tags =
|
||||||
|
@ -28,8 +29,7 @@ defmodule Philomena.Images.DnpValidator do
|
||||||
Enum.reduce(tags_with_dnp, changeset, fn tag, changeset ->
|
Enum.reduce(tags_with_dnp, changeset, fn tag, changeset ->
|
||||||
case Enum.any?(
|
case Enum.any?(
|
||||||
tag.dnp_entries,
|
tag.dnp_entries,
|
||||||
&(&1.dnp_type == "Artist Upload Only" and
|
&(&1.dnp_type == "Artist Upload Only" and not valid_user?(&1, uploader))
|
||||||
not same_user?(&1.requesting_user, uploader))
|
|
||||||
) do
|
) do
|
||||||
true ->
|
true ->
|
||||||
add_error(changeset, :image, "DNP (Artist upload only)")
|
add_error(changeset, :image, "DNP (Artist upload only)")
|
||||||
|
@ -46,7 +46,7 @@ defmodule Philomena.Images.DnpValidator do
|
||||||
Enum.reduce(tags_with_dnp, changeset, fn tag, changeset ->
|
Enum.reduce(tags_with_dnp, changeset, fn tag, changeset ->
|
||||||
case Enum.any?(
|
case Enum.any?(
|
||||||
tag.dnp_entries,
|
tag.dnp_entries,
|
||||||
&(&1.dnp_type == "No Edits" and not same_user?(&1.requesting_user, uploader))
|
&(&1.dnp_type == "No Edits" and not valid_user?(&1, uploader))
|
||||||
) do
|
) do
|
||||||
true ->
|
true ->
|
||||||
add_error(changeset, :image, "DNP (No edits)")
|
add_error(changeset, :image, "DNP (No edits)")
|
||||||
|
@ -57,8 +57,15 @@ defmodule Philomena.Images.DnpValidator do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp same_user?(%{id: id}, %{id: id}), do: true
|
defp valid_user?(_dnp_entry, nil), do: false
|
||||||
defp same_user?(_user1, _user2), do: false
|
|
||||||
|
defp valid_user?(dnp_entry, user) do
|
||||||
|
UserLink
|
||||||
|
|> where(tag_id: ^dnp_entry.tag_id)
|
||||||
|
|> where(aasm_state: "verified")
|
||||||
|
|> where(user_id: ^user.id)
|
||||||
|
|> Repo.exists?()
|
||||||
|
end
|
||||||
|
|
||||||
defp extract_tags(tags) do
|
defp extract_tags(tags) do
|
||||||
tags
|
tags
|
||||||
|
|
Loading…
Reference in a new issue