mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
mod profiles tag/source changes
This commit is contained in:
parent
8a37696915
commit
e2496cd43b
17 changed files with 213 additions and 9 deletions
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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))
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.FingerprintProfile.SourceChangeView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.FingerprintProfile.TagChangeView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
3
lib/philomena_web/views/ip_profile/source_change_view.ex
Normal file
3
lib/philomena_web/views/ip_profile/source_change_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.IpProfile.SourceChangeView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
3
lib/philomena_web/views/ip_profile/tag_change_view.ex
Normal file
3
lib/philomena_web/views/ip_profile/tag_change_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
|||
defmodule PhilomenaWeb.IpProfile.TagChangeView do
|
||||
use PhilomenaWeb, :view
|
||||
end
|
Loading…
Reference in a new issue