diff --git a/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex new file mode 100644 index 00000000..b3ccf771 --- /dev/null +++ b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex @@ -0,0 +1,27 @@ +defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do + use PhilomenaWeb, :controller + + alias Philomena.SourceChanges.SourceChange + alias Philomena.Repo + import Ecto.Query + + plug :verify_authorized + + def index(conn, %{"fingerprint_profile_id" => fingerprint}) do + source_changes = + SourceChange + |> where(fingerprint: ^fingerprint) + |> order_by(desc: :created_at) + |> preload([:user, image: [:user, :tags]]) + |> Repo.paginate(conn.assigns.scrivener) + + render(conn, "index.html", title: "Source Changes for Fingerprint `#{fingerprint}'", fingerprint: fingerprint, source_changes: source_changes) + end + + defp verify_authorized(conn, _opts) do + case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do + true -> conn + _false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) + end + end +end diff --git a/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex new file mode 100644 index 00000000..38f36fd6 --- /dev/null +++ b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex @@ -0,0 +1,35 @@ +defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do + use PhilomenaWeb, :controller + + alias Philomena.TagChanges.TagChange + alias Philomena.Repo + import Ecto.Query + + plug :verify_authorized + + def index(conn, %{"fingerprint_profile_id" => fingerprint} = params) do + tag_changes = + TagChange + |> where(fingerprint: ^fingerprint) + |> added_filter(params) + |> preload([:tag, :user, image: [:user, :tags]]) + |> order_by(desc: :created_at) + |> Repo.paginate(conn.assigns.scrivener) + + render(conn, "index.html", title: "Tag Changes for Fingerprint `#{fingerprint}'", fingerprint: fingerprint, tag_changes: tag_changes) + end + + defp added_filter(query, %{"added" => "1"}), + do: where(query, added: true) + defp added_filter(query, %{"added" => "0"}), + do: where(query, added: false) + defp added_filter(query, _params), + do: query + + defp verify_authorized(conn, _opts) do + case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do + true -> conn + _false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) + end + end +end diff --git a/lib/philomena_web/controllers/ip_profile/source_change_controller.ex b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex new file mode 100644 index 00000000..bfbcb90b --- /dev/null +++ b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex @@ -0,0 +1,29 @@ +defmodule PhilomenaWeb.IpProfile.SourceChangeController do + use PhilomenaWeb, :controller + + alias Philomena.SourceChanges.SourceChange + alias Philomena.Repo + import Ecto.Query + + plug :verify_authorized + + def index(conn, %{"ip_profile_id" => ip}) do + {:ok, ip} = EctoNetwork.INET.cast(ip) + + source_changes = + SourceChange + |> where(ip: ^ip) + |> order_by(desc: :created_at) + |> preload([:user, image: [:user, :tags]]) + |> Repo.paginate(conn.assigns.scrivener) + + render(conn, "index.html", title: "Source Changes for IP `#{ip}'", ip: ip, source_changes: source_changes) + end + + defp verify_authorized(conn, _opts) do + case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do + true -> conn + _false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) + end + end +end diff --git a/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex new file mode 100644 index 00000000..7dd912c6 --- /dev/null +++ b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex @@ -0,0 +1,37 @@ +defmodule PhilomenaWeb.IpProfile.TagChangeController do + use PhilomenaWeb, :controller + + alias Philomena.TagChanges.TagChange + alias Philomena.Repo + import Ecto.Query + + plug :verify_authorized + + def index(conn, %{"ip_profile_id" => ip} = params) do + {:ok, ip} = EctoNetwork.INET.cast(ip) + + tag_changes = + TagChange + |> where(ip: ^ip) + |> added_filter(params) + |> preload([:tag, :user, image: [:user, :tags]]) + |> order_by(desc: :created_at) + |> Repo.paginate(conn.assigns.scrivener) + + render(conn, "index.html", title: "Tag Changes for IP `#{ip}'", ip: ip, tag_changes: tag_changes) + end + + defp added_filter(query, %{"added" => "1"}), + do: where(query, added: true) + defp added_filter(query, %{"added" => "0"}), + do: where(query, added: false) + defp added_filter(query, _params), + do: query + + defp verify_authorized(conn, _opts) do + case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do + true -> conn + _false -> PhilomenaWeb.NotAuthorizedPlug.call(conn) + end + end +end diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 7adc356d..50e5b264 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -193,8 +193,14 @@ defmodule PhilomenaWeb.Router do resources "/dnp", DnpEntryController, only: [:new, :create, :edit, :update] - resources "/ip_profiles", IpProfileController, only: [:show] - resources "/fingerprint_profiles", FingerprintProfileController, only: [:show] + resources "/ip_profiles", IpProfileController, only: [:show] do + resources "/tag_changes", IpProfile.TagChangeController, only: [:index] + resources "/source_changes", IpProfile.SourceChangeController, only: [:index] + end + resources "/fingerprint_profiles", FingerprintProfileController, only: [:show] do + resources "/tag_changes", FingerprintProfile.TagChangeController, only: [:index] + resources "/source_changes", FingerprintProfile.SourceChangeController, only: [:index] + end scope "/admin", Admin, as: :admin do resources "/reports", ReportController, only: [:index, :show] do diff --git a/lib/philomena_web/templates/fingerprint_profile/show.html.slime b/lib/philomena_web/templates/fingerprint_profile/show.html.slime index 9c31d7a9..e6f73f91 100644 --- a/lib/philomena_web/templates/fingerprint_profile/show.html.slime +++ b/lib/philomena_web/templates/fingerprint_profile/show.html.slime @@ -10,9 +10,9 @@ ul = render PhilomenaWeb.BanView, "_bans.html", bans: @fingerprint_bans, conn: @conn h2 Administration Options -/ul - /li = link "View tag changes", "/fingerprint_profiles/#{@fingerprint}/tag_changes" - /li = link "View source URL history", "/fingerprint_profiles/#{@fingerprint}/source_changes" +ul + li = link "View tag changes", to: Routes.fingerprint_profile_tag_change_path(@conn, :index, @fingerprint) + li = link "View source URL history", to: Routes.fingerprint_profile_source_change_path(@conn, :index, @fingerprint) li = link "View reports this fingerprint has made", to: Routes.admin_report_path(@conn, :index, rq: "fingerprint:#{@fingerprint}") li = link "View fingerprint ban history", to: Routes.admin_fingerprint_ban_path(@conn, :index, fingerprint: @fingerprint) li = link "Ban this sucker", to: Routes.admin_fingerprint_ban_path(@conn, :new, fingerprint: @fingerprint) diff --git a/lib/philomena_web/templates/fingerprint_profile/source_change/index.html.slime b/lib/philomena_web/templates/fingerprint_profile/source_change/index.html.slime new file mode 100644 index 00000000..d1dd1440 --- /dev/null +++ b/lib/philomena_web/templates/fingerprint_profile/source_change/index.html.slime @@ -0,0 +1,8 @@ +h1 + ' Source changes by + = @fingerprint + +- route = fn p -> Routes.fingerprint_profile_source_change_path(@conn, :index, @fingerprint, p) end +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn + += render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination diff --git a/lib/philomena_web/templates/fingerprint_profile/tag_change/index.html.slime b/lib/philomena_web/templates/fingerprint_profile/tag_change/index.html.slime new file mode 100644 index 00000000..6bd0ca55 --- /dev/null +++ b/lib/philomena_web/templates/fingerprint_profile/tag_change/index.html.slime @@ -0,0 +1,17 @@ +h1 + ' Tag changes by + = @fingerprint + +- route = fn p -> Routes.fingerprint_profile_tag_change_path(@conn, :index, @fingerprint, p) end +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn + +.block + .block__header + span.block__header_title + | Display only: + + = link "Removed", to: Routes.fingerprint_profile_tag_change_path(@conn, :index, @fingerprint, added: 0) + = link "Added", to: Routes.fingerprint_profile_tag_change_path(@conn, :index, @fingerprint, added: 1) + = link "All", to: Routes.fingerprint_profile_tag_change_path(@conn, :index, @fingerprint) + + = render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination diff --git a/lib/philomena_web/templates/ip_profile/show.html.slime b/lib/philomena_web/templates/ip_profile/show.html.slime index 02f41a55..0a886778 100644 --- a/lib/philomena_web/templates/ip_profile/show.html.slime +++ b/lib/philomena_web/templates/ip_profile/show.html.slime @@ -11,8 +11,8 @@ ul h2 Administration Options ul - /li = link "View tag changes", "/ip_profiles/#{@ip}/tag_changes" - /li = link "View source URL history", "/ip_profiles/#{@ip}/source_changes" + li = link "View tag changes", to: Routes.ip_profile_tag_change_path(@conn, :index, to_string(@ip)) + li = link "View source URL history", to: Routes.ip_profile_source_change_path(@conn, :index, to_string(@ip)) li = link "View reports this IP has made", to: Routes.admin_report_path(@conn, :index, rq: "ip:#{@ip}") li = link "View IP ban history", to: Routes.admin_subnet_ban_path(@conn, :index, ip: to_string(@ip)) li = link "Ban this sucker", to: Routes.admin_subnet_ban_path(@conn, :new, specification: to_string(@ip)) diff --git a/lib/philomena_web/templates/ip_profile/source_change/index.html.slime b/lib/philomena_web/templates/ip_profile/source_change/index.html.slime new file mode 100644 index 00000000..5bf1bea1 --- /dev/null +++ b/lib/philomena_web/templates/ip_profile/source_change/index.html.slime @@ -0,0 +1,8 @@ +h1 + ' Source changes by + = @ip + +- route = fn p -> Routes.ip_profile_source_change_path(@conn, :index, to_string(@ip), p) end +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn + += render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination diff --git a/lib/philomena_web/templates/ip_profile/tag_change/index.html.slime b/lib/philomena_web/templates/ip_profile/tag_change/index.html.slime new file mode 100644 index 00000000..b66c28ff --- /dev/null +++ b/lib/philomena_web/templates/ip_profile/tag_change/index.html.slime @@ -0,0 +1,17 @@ +h1 + ' Tag changes by + = @ip + +- route = fn p -> Routes.ip_profile_tag_change_path(@conn, :index, to_string(@ip), p) end +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn + +.block + .block__header + span.block__header_title + | Display only: + + = link "Removed", to: Routes.ip_profile_tag_change_path(@conn, :index, to_string(@ip), added: 0) + = link "Added", to: Routes.ip_profile_tag_change_path(@conn, :index, to_string(@ip), added: 1) + = link "All", to: Routes.ip_profile_tag_change_path(@conn, :index, to_string(@ip)) + + = render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination diff --git a/lib/philomena_web/templates/source_change/index.html.slime b/lib/philomena_web/templates/source_change/index.html.slime index 6fd42897..77663b20 100644 --- a/lib/philomena_web/templates/source_change/index.html.slime +++ b/lib/philomena_web/templates/source_change/index.html.slime @@ -27,7 +27,11 @@ = pretty_time(source_change.created_at) td class=user_column_class(source_change) - = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: source_change, conn: @conn + => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: source_change, conn: @conn + + = if can?(@conn, :show, :ip_address) do + => link_to_ip @conn, source_change.ip + => link_to_fingerprint @conn,source_change.fingerprint = if staff?(source_change) do br diff --git a/lib/philomena_web/templates/tag_change/index.html.slime b/lib/philomena_web/templates/tag_change/index.html.slime index e20c06c5..39326c54 100644 --- a/lib/philomena_web/templates/tag_change/index.html.slime +++ b/lib/philomena_web/templates/tag_change/index.html.slime @@ -34,7 +34,11 @@ = pretty_time(tag_change.created_at) td class=user_column_class(tag_change) - = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: tag_change, conn: @conn + => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: tag_change, conn: @conn + + = if can?(@conn, :show, :ip_address) do + => link_to_ip @conn, tag_change.ip + => link_to_fingerprint @conn, tag_change.fingerprint = if staff?(tag_change) do br diff --git a/lib/philomena_web/views/fingerprint_profile/source_change_view.ex b/lib/philomena_web/views/fingerprint_profile/source_change_view.ex new file mode 100644 index 00000000..8b403fc3 --- /dev/null +++ b/lib/philomena_web/views/fingerprint_profile/source_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.FingerprintProfile.SourceChangeView do + use PhilomenaWeb, :view +end diff --git a/lib/philomena_web/views/fingerprint_profile/tag_change_view.ex b/lib/philomena_web/views/fingerprint_profile/tag_change_view.ex new file mode 100644 index 00000000..da6e5a5e --- /dev/null +++ b/lib/philomena_web/views/fingerprint_profile/tag_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.FingerprintProfile.TagChangeView do + use PhilomenaWeb, :view +end diff --git a/lib/philomena_web/views/ip_profile/source_change_view.ex b/lib/philomena_web/views/ip_profile/source_change_view.ex new file mode 100644 index 00000000..00ee5e86 --- /dev/null +++ b/lib/philomena_web/views/ip_profile/source_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.IpProfile.SourceChangeView do + use PhilomenaWeb, :view +end diff --git a/lib/philomena_web/views/ip_profile/tag_change_view.ex b/lib/philomena_web/views/ip_profile/tag_change_view.ex new file mode 100644 index 00000000..36eddeef --- /dev/null +++ b/lib/philomena_web/views/ip_profile/tag_change_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.IpProfile.TagChangeView do + use PhilomenaWeb, :view +end