Skip to content

Commit

Permalink
Merge pull request #239 from philomena-dev/verified-routes2
Browse files Browse the repository at this point in the history
Verified routes
  • Loading branch information
liamwhite committed Jun 2, 2024
2 parents e6c7651 + 9e79648 commit 6bde65a
Show file tree
Hide file tree
Showing 343 changed files with 1,167 additions and 1,181 deletions.
18 changes: 9 additions & 9 deletions lib/philomena/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ defmodule Philomena.Users do
|> Ecto.Multi.delete_all(:tokens, UserToken.user_and_contexts_query(user, [context]))
end

@doc """
@doc ~S"""
Delivers the update email instructions to the given user.
## Examples
iex> deliver_update_email_instructions(user, current_email, &Routes.user_update_email_url(conn, :edit, &1))
iex> deliver_update_email_instructions(user, current_email, &url(~p"/registrations/email/#{&1})")
{:ok, %{to: ..., body: ...}}
"""
Expand Down Expand Up @@ -263,12 +263,12 @@ defmodule Philomena.Users do
|> Repo.update()
end

@doc """
@doc ~S"""
Delivers the unlock instructions to the given user.
## Examples
iex> deliver_user_unlock_instructions(user, &Routes.unlock_url(conn, :show, &1))
iex> deliver_user_unlock_instructions(user, &url(~p"/unlocks/#{&1}"))
{:ok, %{to: ..., body: ...}}
"""
Expand Down Expand Up @@ -379,15 +379,15 @@ defmodule Philomena.Users do

## Confirmation

@doc """
@doc ~S"""
Delivers the confirmation email instructions to the given user.
## Examples
iex> deliver_user_confirmation_instructions(user, &Routes.user_confirmation_url(conn, :confirm, &1))
iex> deliver_user_confirmation_instructions(user, &url(~p"/confirmations/#{&1}"))
{:ok, %{to: ..., body: ...}}
iex> deliver_user_confirmation_instructions(confirmed_user, &Routes.user_confirmation_url(conn, :confirm, &1))
iex> deliver_user_confirmation_instructions(confirmed_user, &url(~p"/confirmations/#{&1}"))
{:error, :already_confirmed}
"""
Expand Down Expand Up @@ -426,12 +426,12 @@ defmodule Philomena.Users do

## Reset password

@doc """
@doc ~S"""
Delivers the reset password email to the given user.
## Examples
iex> deliver_user_reset_password_instructions(user, &Routes.user_reset_password_url(conn, :edit, &1))
iex> deliver_user_reset_password_instructions(user, &url(~p"/passwords/#{&1}/edit"))
{:ok, %{to: ..., body: ...}}
"""
Expand Down
17 changes: 15 additions & 2 deletions lib/philomena_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule PhilomenaWeb do
and import those modules here.
"""

def static_paths, do: ~w(assets favicon.ico favicon.svg robots.txt)

def controller do
quote do
use Phoenix.Controller, namespace: PhilomenaWeb
Expand All @@ -25,7 +27,8 @@ defmodule PhilomenaWeb do
import PhilomenaWeb.Gettext
import Canary.Plugs
import PhilomenaWeb.ModerationLogPlug, only: [moderation_log: 2]
alias PhilomenaWeb.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

Expand All @@ -43,10 +46,11 @@ defmodule PhilomenaWeb do

import PhilomenaWeb.ErrorHelpers
import PhilomenaWeb.Gettext
alias PhilomenaWeb.Router.Helpers, as: Routes

# Wrong way around for convenience
import PhilomenaWeb.AppView

unquote(verified_routes())
end
end

Expand All @@ -65,6 +69,15 @@ defmodule PhilomenaWeb do
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: PhilomenaWeb.Endpoint,
router: PhilomenaWeb.Router,
statics: PhilomenaWeb.static_paths()
end
end

@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule PhilomenaWeb.Admin.Advert.ImageController do
{:ok, _advert} ->
conn
|> put_flash(:info, "Advert was successfully updated.")
|> redirect(to: Routes.admin_advert_path(conn, :index))
|> redirect(to: ~p"/admin/adverts")

{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
Expand Down
6 changes: 3 additions & 3 deletions lib/philomena_web/controllers/admin/advert_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule PhilomenaWeb.Admin.AdvertController do
{:ok, _advert} ->
conn
|> put_flash(:info, "Advert was successfully created.")
|> redirect(to: Routes.admin_advert_path(conn, :index))
|> redirect(to: ~p"/admin/adverts")

{:error, :advert, changeset, _changes} ->
render(conn, "new.html", changeset: changeset)
Expand All @@ -49,7 +49,7 @@ defmodule PhilomenaWeb.Admin.AdvertController do
{:ok, _advert} ->
conn
|> put_flash(:info, "Advert was successfully updated.")
|> redirect(to: Routes.admin_advert_path(conn, :index))
|> redirect(to: ~p"/admin/adverts")

{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
Expand All @@ -61,7 +61,7 @@ defmodule PhilomenaWeb.Admin.AdvertController do

conn
|> put_flash(:info, "Advert was successfully deleted.")
|> redirect(to: Routes.admin_advert_path(conn, :index))
|> redirect(to: ~p"/admin/adverts")
end

defp verify_authorized(conn, _opts) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ defmodule PhilomenaWeb.Admin.ArtistLink.ContactController do
conn
|> put_flash(:info, "Artist successfully marked as contacted.")
|> moderation_log(details: &log_details/3, data: artist_link)
|> redirect(to: Routes.admin_artist_link_path(conn, :index))
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(conn, _action, artist_link) do
defp log_details(_conn, _action, artist_link) do
%{
body: "Contacted artist #{artist_link.user.name} at #{artist_link.uri}",
subject_path: Routes.profile_artist_link_path(conn, :show, artist_link.user, artist_link)
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ defmodule PhilomenaWeb.Admin.ArtistLink.RejectController do
conn
|> put_flash(:info, "Artist link successfully marked as rejected.")
|> moderation_log(details: &log_details/3, data: artist_link)
|> redirect(to: Routes.admin_artist_link_path(conn, :index))
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(conn, _action, artist_link) do
defp log_details(_conn, _action, artist_link) do
%{
body: "Rejected artist link #{artist_link.uri} created by #{artist_link.user.name}",
subject_path: Routes.profile_artist_link_path(conn, :show, artist_link.user, artist_link)
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ defmodule PhilomenaWeb.Admin.ArtistLink.VerificationController do
conn
|> put_flash(:info, "Artist link successfully verified.")
|> moderation_log(details: &log_details/3, data: result.artist_link)
|> redirect(to: Routes.admin_artist_link_path(conn, :index))
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(conn, _action, artist_link) do
defp log_details(_conn, _action, artist_link) do
%{
body: "Verified artist link #{artist_link.uri} created by #{artist_link.user.name}",
subject_path: Routes.profile_artist_link_path(conn, :show, artist_link.user, artist_link)
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Admin.Badge.ImageController do
{:ok, _badge} ->
conn
|> put_flash(:info, "Badge updated successfully.")
|> redirect(to: Routes.admin_badge_path(conn, :index))
|> redirect(to: ~p"/admin/badges")

{:error, :badge, changeset, _changes} ->
render(conn, "edit.html", changeset: changeset)
Expand Down
4 changes: 2 additions & 2 deletions lib/philomena_web/controllers/admin/badge_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule PhilomenaWeb.Admin.BadgeController do
{:ok, _badge} ->
conn
|> put_flash(:info, "Badge created successfully.")
|> redirect(to: Routes.admin_badge_path(conn, :index))
|> redirect(to: ~p"/admin/badges")

{:error, :badge, changeset, _changes} ->
render(conn, "new.html", changeset: changeset)
Expand All @@ -45,7 +45,7 @@ defmodule PhilomenaWeb.Admin.BadgeController do
{:ok, _badge} ->
conn
|> put_flash(:info, "Badge updated successfully.")
|> redirect(to: Routes.admin_badge_path(conn, :index))
|> redirect(to: ~p"/admin/badges")

{:error, :badge, changeset, _changes} ->
render(conn, "edit.html", changeset: changeset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule PhilomenaWeb.Admin.Batch.TagController do
defp log_details(conn, _action, data) do
%{
body: "Batch tagged '#{data.tag_list}' on #{data.image_count} images",
subject_path: Routes.profile_path(conn, :show, conn.assigns.current_user)
subject_path: ~p"/profiles/#{conn.assigns.current_user}"
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ defmodule PhilomenaWeb.Admin.DnpEntry.TransitionController do
{:ok, dnp_entry} ->
conn
|> put_flash(:info, "Successfully updated DNP entry.")
|> redirect(to: Routes.dnp_entry_path(conn, :show, dnp_entry))
|> redirect(to: ~p"/dnp/#{dnp_entry}")

{:error, _changeset} ->
conn
|> put_flash(:error, "Failed to update DNP entry!")
|> redirect(to: Routes.dnp_entry_path(conn, :show, conn.assigns.dnp_entry))
|> redirect(to: ~p"/dnp/#{conn.assigns.dnp_entry}")
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/philomena_web/controllers/admin/donation_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ defmodule PhilomenaWeb.Admin.DonationController do
{:ok, _donation} ->
conn
|> put_flash(:info, "Donation successfully created.")
|> redirect(to: Routes.admin_donation_path(conn, :index))
|> redirect(to: ~p"/admin/donations")

_error ->
conn
|> put_flash(:error, "Error creating donation!")
|> redirect(to: Routes.admin_donation_path(conn, :index))
|> redirect(to: ~p"/admin/donations")
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
conn
|> put_flash(:info, "Fingerprint was successfully banned.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> redirect(to: Routes.admin_fingerprint_ban_path(conn, :index))
|> redirect(to: ~p"/admin/fingerprint_bans")

{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
Expand All @@ -66,7 +66,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
conn
|> put_flash(:info, "Fingerprint ban successfully updated.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> redirect(to: Routes.admin_fingerprint_ban_path(conn, :index))
|> redirect(to: ~p"/admin/fingerprint_bans")

{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
Expand All @@ -79,7 +79,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
conn
|> put_flash(:info, "Fingerprint ban successfully deleted.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> redirect(to: Routes.admin_fingerprint_ban_path(conn, :index))
|> redirect(to: ~p"/admin/fingerprint_bans")
end

defp load_bans(queryable, conn) do
Expand Down Expand Up @@ -110,14 +110,14 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
end
end

defp log_details(conn, action, ban) do
defp log_details(_conn, action, ban) do
body =
case action do
:create -> "Created a fingerprint ban #{ban.generated_ban_id}"
:update -> "Updated a fingerprint ban #{ban.generated_ban_id}"
:delete -> "Deleted a fingerprint ban #{ban.generated_ban_id}"
end

%{body: body, subject_path: Routes.admin_fingerprint_ban_path(conn, :index)}
%{body: body, subject_path: ~p"/admin/fingerprint_bans"}
end
end
4 changes: 2 additions & 2 deletions lib/philomena_web/controllers/admin/forum_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Admin.ForumController do
{:ok, _forum} ->
conn
|> put_flash(:info, "Forum created successfully.")
|> redirect(to: Routes.admin_forum_path(conn, :index))
|> redirect(to: ~p"/admin/forums")

{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
Expand All @@ -38,7 +38,7 @@ defmodule PhilomenaWeb.Admin.ForumController do
{:ok, _forum} ->
conn
|> put_flash(:info, "Forum updated successfully.")
|> redirect(to: Routes.admin_forum_path(conn, :index))
|> redirect(to: ~p"/admin/forums")

{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
Expand Down
6 changes: 3 additions & 3 deletions lib/philomena_web/controllers/admin/mod_note_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do
{:ok, _mod_note} ->
conn
|> put_flash(:info, "Successfully created mod note.")
|> redirect(to: Routes.admin_mod_note_path(conn, :index))
|> redirect(to: ~p"/admin/mod_notes")

{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
Expand All @@ -63,7 +63,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do
{:ok, _mod_note} ->
conn
|> put_flash(:info, "Successfully updated mod note.")
|> redirect(to: Routes.admin_mod_note_path(conn, :index))
|> redirect(to: ~p"/admin/mod_notes")

{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
Expand All @@ -75,7 +75,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do

conn
|> put_flash(:info, "Successfully deleted mod note.")
|> redirect(to: Routes.admin_mod_note_path(conn, :index))
|> redirect(to: ~p"/admin/mod_notes")
end

defp verify_authorized(conn, _opts) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ defmodule PhilomenaWeb.Admin.Report.ClaimController do
{:ok, _report} ->
conn
|> put_flash(:info, "Successfully marked report as in progress")
|> redirect(to: Routes.admin_report_path(conn, :index))
|> redirect(to: ~p"/admin/reports")

{:error, _changeset} ->
conn
|> put_flash(:error, "Couldn't claim that report!")
|> redirect(to: Routes.admin_report_path(conn, :show, conn.assigns.report))
|> redirect(to: ~p"/admin/reports/#{conn.assigns.report}")
end
end

Expand All @@ -26,6 +26,6 @@ defmodule PhilomenaWeb.Admin.Report.ClaimController do

conn
|> put_flash(:info, "Successfully released report.")
|> redirect(to: Routes.admin_report_path(conn, :show, report))
|> redirect(to: ~p"/admin/reports/#{report}")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ defmodule PhilomenaWeb.Admin.Report.CloseController do

conn
|> put_flash(:info, "Successfully closed report")
|> redirect(to: Routes.admin_report_path(conn, :index))
|> redirect(to: ~p"/admin/reports")
end
end
Loading

0 comments on commit 6bde65a

Please sign in to comment.