philomena/lib/philomena_web/controllers/fingerprint_profile_controller.ex

39 lines
931 B
Elixir
Raw Permalink 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()
2020-01-11 05:20:19 +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)
2020-01-11 05:20:19 +01:00
true -> conn
2019-12-08 02:49:28 +01:00
end
end
2019-12-14 23:07:43 +01:00
end