philomena/lib/philomena_web/controllers/image/source_controller.ex

35 lines
1.1 KiB
Elixir
Raw Normal View History

2019-11-24 19:36:21 +01:00
defmodule PhilomenaWeb.Image.SourceController do
use PhilomenaWeb, :controller
alias Philomena.UserStatistics
2019-11-24 19:36:21 +01:00
alias Philomena.Images.Image
alias Philomena.Images
2019-11-24 19:36:21 +01:00
plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.CaptchaPlug
plug PhilomenaWeb.UserAttributionPlug
plug PhilomenaWeb.CanaryMapPlug, update: :edit_metadata
2019-11-24 19:36:21 +01:00
plug :load_and_authorize_resource, model: Image, id_name: "image_id"
def update(conn, %{"image" => image_params}) do
attributes = conn.assigns.attributes
image = conn.assigns.image
case Images.update_source(image, attributes, image_params) do
{:ok, %{image: image}} ->
changeset =
Images.change_image(image)
UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates)
2019-11-24 19:36:21 +01:00
conn
|> put_view(PhilomenaWeb.ImageView)
|> render("_source.html", layout: false, image: image, changeset: changeset)
2019-11-24 19:36:21 +01:00
{:error, :image, changeset, _} ->
conn
|> put_view(PhilomenaWeb.ImageView)
|> render("_source.html", layout: false, image: image, changeset: changeset)
2019-11-24 19:36:21 +01:00
end
end
end