2019-12-04 23:56:13 +01:00
|
|
|
defmodule PhilomenaWeb.Profile.SourceChangeController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users.User
|
|
|
|
alias Philomena.Images.Image
|
|
|
|
alias Philomena.SourceChanges.SourceChange
|
2020-08-16 07:35:42 +02:00
|
|
|
alias Philomena.SpoilerExecutor
|
2019-12-04 23:56:13 +01:00
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
2020-01-11 05:20:19 +01:00
|
|
|
|
|
|
|
plug :load_and_authorize_resource,
|
|
|
|
model: User,
|
|
|
|
id_name: "profile_id",
|
|
|
|
id_field: "slug",
|
|
|
|
persisted: true
|
2019-12-04 23:56:13 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
user = conn.assigns.user
|
|
|
|
|
|
|
|
source_changes =
|
|
|
|
SourceChange
|
|
|
|
|> join(:inner, [sc], i in Image, on: sc.image_id == i.id)
|
2020-01-11 05:20:19 +01:00
|
|
|
|> where(
|
|
|
|
[sc, i],
|
|
|
|
sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
|
|
|
|
)
|
2020-08-16 12:03:33 +02:00
|
|
|
|> preload([:user, image: [:user]])
|
2019-12-04 23:56:13 +01:00
|
|
|
|> order_by(desc: :created_at)
|
|
|
|
|> Repo.paginate(conn.assigns.scrivener)
|
2020-01-11 05:20:19 +01:00
|
|
|
|
2020-08-16 07:35:42 +02:00
|
|
|
spoilers =
|
|
|
|
SpoilerExecutor.execute_spoiler(
|
|
|
|
conn.assigns.compiled_spoiler,
|
|
|
|
Enum.map(source_changes, & &1.image)
|
|
|
|
)
|
|
|
|
|
2020-01-11 05:20:19 +01:00
|
|
|
render(conn, "index.html",
|
|
|
|
title: "Source Changes for User `#{user.name}'",
|
|
|
|
user: user,
|
2020-08-16 07:35:42 +02:00
|
|
|
source_changes: source_changes,
|
|
|
|
spoilers: spoilers
|
2020-01-11 05:20:19 +01:00
|
|
|
)
|
2019-12-04 23:56:13 +01:00
|
|
|
end
|
2019-12-16 20:24:38 +01:00
|
|
|
end
|