mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-17 22:47:59 +01:00
38 lines
931 B
Elixir
38 lines
931 B
Elixir
defmodule PhilomenaWeb.FingerprintProfileController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.UserFingerprints.UserFingerprint
|
|
alias Philomena.Bans.Fingerprint
|
|
alias Philomena.Repo
|
|
import Ecto.Query
|
|
|
|
plug :authorize_ip
|
|
|
|
def show(conn, %{"id" => fingerprint}) do
|
|
user_fps =
|
|
UserFingerprint
|
|
|> where(fingerprint: ^fingerprint)
|
|
|> order_by(desc: :updated_at)
|
|
|> preload(:user)
|
|
|> Repo.all()
|
|
|
|
fp_bans =
|
|
Fingerprint
|
|
|> where(fingerprint: ^fingerprint)
|
|
|> Repo.all()
|
|
|
|
render(conn, "show.html",
|
|
title: "#{fingerprint}'s fingerprint profile",
|
|
fingerprint: fingerprint,
|
|
user_fps: user_fps,
|
|
fingerprint_bans: fp_bans
|
|
)
|
|
end
|
|
|
|
defp authorize_ip(conn, _opts) do
|
|
case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do
|
|
false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
|
true -> conn
|
|
end
|
|
end
|
|
end
|