philomena/lib/philomena_web/controllers/profile/detail_controller.ex

49 lines
1.2 KiB
Elixir
Raw Permalink Normal View History

2019-12-17 03:26:43 +01:00
defmodule PhilomenaWeb.Profile.DetailController do
use PhilomenaWeb, :controller
alias Philomena.UserNameChanges.UserNameChange
alias Philomena.ModNotes.ModNote
alias PhilomenaWeb.MarkdownRenderer
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
|> MarkdownRenderer.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