reject associated duplicate reports when deleting

This commit is contained in:
byte[] 2019-12-30 18:37:41 -05:00
parent 31b1704847
commit b18a1370a5

View file

@ -9,6 +9,7 @@ defmodule Philomena.Images do
alias Philomena.Repo alias Philomena.Repo
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.DuplicateReports.DuplicateReport
alias Philomena.Images.Image alias Philomena.Images.Image
alias Philomena.Images.Hider alias Philomena.Images.Hider
alias Philomena.Images.Uploader alias Philomena.Images.Uploader
@ -323,6 +324,11 @@ defmodule Philomena.Images do
end end
def hide_image(%Image{} = image, user, attrs) do def hide_image(%Image{} = image, user, attrs) do
DuplicateReport
|> where(state: "open")
|> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id)
|> Repo.update_all(set: [state: "rejected"])
Image.hide_changeset(image, attrs, user) Image.hide_changeset(image, attrs, user)
|> internal_hide_image(image) |> internal_hide_image(image)
end end