philomena/lib/philomena_web/controllers/fingerprint_profile_controller.ex

34 lines
903 B
Elixir
Raw Normal View History

2019-12-08 02:49:28 +01:00
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()
2019-12-16 20:24:38 +01:00
render(conn, "show.html", title: "#{fingerprint}'s fingerprint profile", fingerprint: fingerprint, user_fps: user_fps, fingerprint_bans: fp_bans)
2019-12-08 02:49:28 +01:00
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
2019-12-14 23:07:43 +01:00
end