2019-12-17 03:26:43 +01:00
|
|
|
defmodule PhilomenaWeb.Profile.DetailController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.UserNameChanges.UserNameChange
|
|
|
|
alias Philomena.ModNotes.ModNote
|
2020-05-08 04:19:08 +02:00
|
|
|
alias PhilomenaWeb.TextileRenderer
|
2019-12-17 03:26:43 +01:00
|
|
|
alias Philomena.Polymorphic
|
|
|
|
alias Philomena.Users.User
|
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, index: :show_details
|
2020-01-11 05:20:19 +01:00
|
|
|
|
|
|
|
plug :load_and_authorize_resource,
|
|
|
|
model: User,
|
|
|
|
id_field: "slug",
|
|
|
|
id_name: "profile_id",
|
|
|
|
persisted: true
|
2019-12-17 03:26:43 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
user = conn.assigns.user
|
|
|
|
|
|
|
|
mod_notes =
|
|
|
|
ModNote
|
|
|
|
|> where(notable_type: "User", notable_id: ^user.id)
|
|
|
|
|> order_by(desc: :id)
|
|
|
|
|> preload(:moderator)
|
|
|
|
|> Repo.all()
|
|
|
|
|> Polymorphic.load_polymorphic(notable: [notable_id: :notable_type])
|
|
|
|
|
|
|
|
mod_notes =
|
|
|
|
mod_notes
|
2020-05-08 04:19:08 +02:00
|
|
|
|> TextileRenderer.render_collection(conn)
|
2019-12-17 03:26:43 +01:00
|
|
|
|> Enum.zip(mod_notes)
|
|
|
|
|
|
|
|
name_changes =
|
|
|
|
UserNameChange
|
|
|
|
|> where(user_id: ^user.id)
|
|
|
|
|> order_by(desc: :id)
|
|
|
|
|> Repo.all()
|
|
|
|
|
2020-01-11 05:20:19 +01:00
|
|
|
render(conn, "index.html",
|
|
|
|
title: "Profile Details for User `#{user.name}'",
|
|
|
|
mod_notes: mod_notes,
|
|
|
|
name_changes: name_changes
|
|
|
|
)
|
2019-12-17 03:26:43 +01:00
|
|
|
end
|
|
|
|
end
|