From 58e9b23d26c0dd35e709fb2e5c96ee4247f64e64 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 23 Sep 2024 18:52:52 +0100 Subject: [PATCH 1/2] chore: upgrade to verified routes --- lib/atomic/accounts.ex | 23 ++---- lib/atomic_web.ex | 24 ++++-- lib/atomic_web/components/activity.ex | 2 +- lib/atomic_web/components/announcement.ex | 2 +- lib/atomic_web/components/organizations.ex | 4 +- lib/atomic_web/components/sidebar.ex | 16 ++-- lib/atomic_web/config.ex | 41 +++++----- lib/atomic_web/controllers/user_auth.ex | 7 +- .../user_change_password_controller.ex | 2 +- .../user_confirmation_controller.ex | 2 +- .../user_registration_controller.ex | 2 +- .../user_reset_password_controller.ex | 6 +- lib/atomic_web/endpoint.ex | 2 +- .../live/activity_live/edit.html.heex | 2 +- .../live/activity_live/index.html.heex | 6 +- .../live/activity_live/new.html.heex | 2 +- lib/atomic_web/live/activity_live/show.ex | 2 +- .../live/activity_live/show.html.heex | 2 +- lib/atomic_web/live/announcement_live/edit.ex | 2 +- .../live/announcement_live/edit.html.heex | 2 +- .../live/announcement_live/index.html.heex | 6 +- .../live/announcement_live/new.html.heex | 2 +- .../live/announcement_live/show.html.heex | 2 +- .../live/calendar_live/components/month.ex | 4 +- .../live/calendar_live/components/week.ex | 2 +- lib/atomic_web/live/calendar_live/show.ex | 14 ++-- .../live/collaborator_live/form_component.ex | 2 +- lib/atomic_web/live/department_live/edit.ex | 12 +-- .../live/department_live/edit.html.heex | 4 +- .../live/department_live/index.html.heex | 6 +- lib/atomic_web/live/department_live/show.ex | 17 +---- .../live/department_live/show.html.heex | 74 ++++--------------- .../follow_suggestions/follow_suggestions.ex | 2 +- .../follow_suggestions/suggestion.ex | 2 +- .../live/home_live/components/schedule.ex | 4 +- lib/atomic_web/live/home_live/index.html.heex | 4 +- .../live/organization_live/edit.html.heex | 2 +- .../live/organization_live/index.html.heex | 6 +- .../live/organization_live/new.html.heex | 2 +- lib/atomic_web/live/organization_live/show.ex | 10 +-- .../live/organization_live/show.html.heex | 2 +- lib/atomic_web/live/partner_live/edit.ex | 8 +- .../live/partner_live/edit.html.heex | 2 +- .../live/partner_live/index.html.heex | 6 +- .../live/partner_live/show.html.heex | 4 +- lib/atomic_web/live/profile_live/edit.ex | 6 +- .../live/profile_live/form_component.ex | 4 +- .../live/profile_live/show.html.heex | 2 +- lib/atomic_web/live/scanner_live/index.ex | 4 +- lib/atomic_web/live/user_live/edit.html.heex | 2 +- lib/atomic_web/templates/error/404.html.heex | 8 +- lib/atomic_web/templates/error/500.html.heex | 6 +- .../templates/layout/_user_menu.html.heex | 6 +- .../templates/layout/root.html.heex | 4 +- .../user_change_password/edit.html.heex | 2 +- .../templates/user_confirmation/new.html.heex | 4 +- .../templates/user_registration/new.html.heex | 4 +- .../user_reset_password/edit.html.heex | 2 +- .../user_reset_password/new.html.heex | 4 +- .../templates/user_session/new.html.heex | 6 +- .../templates/user_settings/edit.html.heex | 4 +- .../templates/user_setup/edit.html.heex | 2 +- .../atomic_web/controllers/user_auth_test.exs | 2 +- .../user_change_password_controller_test.exs | 12 +-- .../user_confirmation_controller_test.exs | 16 ++-- .../user_registration_controller_test.exs | 6 +- .../user_reset_password_controller_test.exs | 18 ++--- .../user_session_controller_test.exs | 16 ++-- test/support/conn_case.ex | 10 +-- 69 files changed, 217 insertions(+), 283 deletions(-) diff --git a/lib/atomic/accounts.ex b/lib/atomic/accounts.ex index 97b67564c..676aa304d 100644 --- a/lib/atomic/accounts.ex +++ b/lib/atomic/accounts.ex @@ -252,7 +252,7 @@ defmodule Atomic.Accounts 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 @@ -260,7 +260,7 @@ defmodule Atomic.Accounts do iex> deliver_update_email_instructions( ...> user, ...> current_email, - ...> &Routes.user_update_email_url(conn, :edit, &1) + ...> &url(~p"/users/settings/confirm_email/#{&1}") ...> ) {:ok, %{to: ..., body: ...}} @@ -348,21 +348,15 @@ defmodule Atomic.Accounts 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, :edit, &1) - ...> ) + iex> deliver_user_confirmation_instructions(user, &url(~p"/users/confirm/#{&1}")) {:ok, %{to: ..., body: ...}} - iex> deliver_user_confirmation_instructions( - ...> confirmed_user, - ...> &Routes.user_confirmation_url(conn, :edit, &1) - ...> ) + iex> deliver_user_confirmation_instructions(confirmed_user, &url(~p"/users/confirm/#{&1}")) {:error, :already_confirmed} """ @@ -401,15 +395,12 @@ defmodule Atomic.Accounts 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"/users/reset_password/#{&1}")) {:ok, %{to: ..., body: ...}} """ diff --git a/lib/atomic_web.ex b/lib/atomic_web.ex index 58d46de71..7581894af 100644 --- a/lib/atomic_web.ex +++ b/lib/atomic_web.ex @@ -17,6 +17,8 @@ defmodule AtomicWeb do and import those modules here. """ + def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) + def controller do quote do use Phoenix.Controller, namespace: AtomicWeb @@ -24,7 +26,7 @@ defmodule AtomicWeb do import Plug.Conn - alias AtomicWeb.Router.Helpers, as: Routes + unquote(verified_routes()) end end @@ -85,29 +87,37 @@ defmodule AtomicWeb do end end + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: AtomicWeb.Endpoint, + router: AtomicWeb.Router, + statics: AtomicWeb.static_paths() + end + end + defp view_helpers do quote do # Use all HTML functionality (forms, tags, etc) use Phoenix.HTML - # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) + # Import LiveView and .heex helpers (<.link>, <.form>, etc) import Phoenix.LiveView.Helpers import Phoenix.Component - # Import commonly used components - unquote(components()) - # Import basic rendering functionality (render, render_layout, etc) import Phoenix.View - # Custom imports + # Custom uses, imports and aliases + unquote(components()) + + use AtomicWeb, :verified_routes use Gettext, backend: AtomicWeb.Gettext import AtomicWeb.ErrorHelpers import AtomicWeb.Helpers alias Atomic.Uploaders - alias AtomicWeb.Router.Helpers, as: Routes end end diff --git a/lib/atomic_web/components/activity.ex b/lib/atomic_web/components/activity.ex index cc0e88fc1..6f98b8e62 100644 --- a/lib/atomic_web/components/activity.ex +++ b/lib/atomic_web/components/activity.ex @@ -19,7 +19,7 @@ defmodule AtomicWeb.Components.Activity do
- <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @activity.organization.id)}> + <.link navigate={~p"/organizations/#{@activity.organization.id}"}> <%= @activity.organization.name %> diff --git a/lib/atomic_web/components/announcement.ex b/lib/atomic_web/components/announcement.ex index 78569fe90..f96ba8a2b 100644 --- a/lib/atomic_web/components/announcement.ex +++ b/lib/atomic_web/components/announcement.ex @@ -17,7 +17,7 @@ defmodule AtomicWeb.Components.Announcement do
- <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @announcement.organization.id)} class="hover:underline focus:outline-none"> + <.link navigate={~p"/organizations/#{@announcement.organization.id}"} class="hover:underline focus:outline-none">

<%= @announcement.organization.name %>

diff --git a/lib/atomic_web/components/organizations.ex b/lib/atomic_web/components/organizations.ex index cc414a082..35866601a 100644 --- a/lib/atomic_web/components/organizations.ex +++ b/lib/atomic_web/components/organizations.ex @@ -52,7 +52,7 @@ defmodule AtomicWeb.Components.Organizations do socket |> assign(current_organization: nil) |> put_flash(:info, gettext("Now viewing as yourself")) - |> push_navigate(to: Routes.home_index_path(socket, :index))} + |> push_navigate(to: ~p"/")} else organization = Organizations.get_organization!(organization_id) @@ -64,7 +64,7 @@ defmodule AtomicWeb.Components.Organizations do socket |> assign(current_organization: organization) |> put_flash(:info, "#{gettext("Now editing as")} #{organization.name}") - |> push_navigate(to: Routes.organization_show_path(socket, :show, organization))} + |> push_navigate(to: ~p"/organizations/#{organization}")} end end end diff --git a/lib/atomic_web/components/sidebar.ex b/lib/atomic_web/components/sidebar.ex index 23277ee1b..4062d54b5 100644 --- a/lib/atomic_web/components/sidebar.ex +++ b/lib/atomic_web/components/sidebar.ex @@ -98,7 +98,7 @@ defmodule AtomicWeb.Components.Sidebar do defp sidebar_list(assigns) do ~H"""
    - <%= for page <- AtomicWeb.Config.pages(AtomicWeb.Endpoint, @current_user, @current_organization) do %> + <%= for page <- AtomicWeb.Config.pages(@current_user, @current_organization) do %>
  • <.link navigate={page.url} class={"#{if @current_page == page.key do "bg-zinc-50 text-orange-500" else "text-zinc-700 hover:text-orange-500 hover:bg-zinc-50" end} group flex gap-x-3 rounded-md p-2 text-sm font-semibold leading-6"}> <.icon name={page.icon} class={ @@ -123,14 +123,14 @@ defmodule AtomicWeb.Components.Sidebar do <:wrapper> <% else %> - <.link navigate={Routes.user_session_path(AtomicWeb.Endpoint, :new)} class="flex select-none items-center space-x-2 px-4 py-3 text-sm font-semibold leading-6 text-zinc-700 lg:px-0"> - + <.link navigate={~p"/users/log_in"} class="flex select-none items-center space-x-2 px-4 py-3 text-sm font-semibold leading-6 text-zinc-700 lg:px-0"> + Log in <.icon name="hero-arrow-right-end-on-rectangle-solid" class="size-5" /> <% end %> @@ -139,8 +139,8 @@ defmodule AtomicWeb.Components.Sidebar do defp sidebar_header(assigns) do ~H""" - <.link navigate={Routes.home_index_path(AtomicWeb.Endpoint, :index)} class="flex h-16 shrink-0 select-none items-center gap-x-4 pt-4"> - + <.link navigate={~p"/"} class="flex h-16 shrink-0 select-none items-center gap-x-4 pt-4"> +

    Atomic

    """ @@ -153,11 +153,11 @@ defmodule AtomicWeb.Components.Sidebar do [ %{ name: gettext("Your profile"), - navigate: Routes.profile_show_path(AtomicWeb.Endpoint, :show, current_user) + navigate: ~p"/profile/#{current_user}" }, %{ name: gettext("Sign out"), - href: Routes.user_session_path(AtomicWeb.Endpoint, :delete), + href: ~p"/users/log_out", method: "delete" } ] diff --git a/lib/atomic_web/config.ex b/lib/atomic_web/config.ex index 949f8b9c0..fa7af886a 100644 --- a/lib/atomic_web/config.ex +++ b/lib/atomic_web/config.ex @@ -2,98 +2,99 @@ defmodule AtomicWeb.Config do @moduledoc """ Web configuration for our pages. """ + use AtomicWeb, :verified_routes + alias Atomic.Accounts - alias AtomicWeb.Router.Helpers, as: Routes # User is not logged in - def pages(conn, nil, _current_organization) do - default_pages(conn) + def pages(nil, _current_organization) do + default_pages() end # User is logged in - def pages(conn, current_user, current_organization) do + def pages(current_user, current_organization) do if has_permissions?(current_user, current_organization) do - admin_pages(conn, current_organization) + admin_pages(current_organization) else - user_pages(conn) + user_pages() end end - def user_pages(conn) do - default_pages(conn) ++ + def user_pages() do + default_pages() ++ [ %{ key: :scanner, title: "Scanner", icon: "hero-qr-code", - url: Routes.scanner_index_path(conn, :index), + url: ~p"/scanner", tabs: [] } ] end - def admin_pages(conn, current_organization) do - default_pages(conn) ++ + def admin_pages(current_organization) do + default_pages() ++ [ %{ key: :departments, title: "Departments", icon: "hero-cube", - url: Routes.department_index_path(conn, :index, current_organization.id), + url: ~p"/organizations/#{current_organization}/departments", tabs: [] }, %{ key: :partners, title: "Partners", icon: "hero-user-group", - url: Routes.partner_index_path(conn, :index, current_organization.id), + url: ~p"/organizations/#{current_organization}/partners", tabs: [] }, %{ key: :scanner, title: "Scanner", icon: "hero-qr-code", - url: Routes.scanner_index_path(conn, :index), + url: ~p"/scanner", tabs: [] } ] end - def default_pages(conn) do + def default_pages() do [ %{ key: :home, title: "Home", icon: "hero-home", - url: Routes.home_index_path(conn, :index), + url: ~p"/", tabs: [] }, %{ key: :calendar, title: "Calendar", icon: "hero-calendar", - url: Routes.calendar_show_path(conn, :show), + url: ~p"/calendar", tabs: [] }, %{ key: :activities, title: "Activities", icon: "hero-academic-cap", - url: Routes.activity_index_path(conn, :index), + url: ~p"/activities", tabs: [] }, %{ key: :announcements, title: "Announcements", icon: "hero-newspaper", - url: Routes.announcement_index_path(conn, :index), + url: ~p"/announcements", tabs: [] }, %{ key: :organizations, title: "Organizations", icon: "tabler-affiliate", - url: Routes.organization_index_path(conn, :index), + url: ~p"/organizations", tabs: [] } ] diff --git a/lib/atomic_web/controllers/user_auth.ex b/lib/atomic_web/controllers/user_auth.ex index 927eafc3e..9b75ec1f3 100644 --- a/lib/atomic_web/controllers/user_auth.ex +++ b/lib/atomic_web/controllers/user_auth.ex @@ -2,11 +2,12 @@ defmodule AtomicWeb.UserAuth do @moduledoc """ This module contains functions to log users in and out. """ + use AtomicWeb, :verified_routes + import Plug.Conn import Phoenix.Controller alias Atomic.Accounts - alias AtomicWeb.Router.Helpers, as: Routes # Make the remember me cookie valid for 60 days. # If you want bump or reduce this value, also change @@ -95,7 +96,7 @@ defmodule AtomicWeb.UserAuth do conn |> renew_session() |> delete_resp_cookie(@remember_me_cookie) - |> redirect(to: Routes.user_session_path(conn, :new)) + |> redirect(to: ~p"/users/log_in") end @doc """ @@ -163,7 +164,7 @@ defmodule AtomicWeb.UserAuth do conn |> put_flash(:error, "You must log in to access this page.") |> maybe_store_return_to() - |> redirect(to: Routes.user_session_path(conn, :new)) + |> redirect(to: ~p"/users/log_in") |> halt() end end diff --git a/lib/atomic_web/controllers/user_change_password_controller.ex b/lib/atomic_web/controllers/user_change_password_controller.ex index 6ccd6ee0f..c71c90478 100644 --- a/lib/atomic_web/controllers/user_change_password_controller.ex +++ b/lib/atomic_web/controllers/user_change_password_controller.ex @@ -17,7 +17,7 @@ defmodule AtomicWeb.UserChangePasswordController do {:ok, user} -> conn |> put_flash(:info, "Password updated successfully.") - |> put_session(:user_return_to, Routes.user_change_password_path(conn, :edit)) + |> put_session(:user_return_to, ~p"/users/change_password") |> UserAuth.log_in_user(user) {:error, changeset} -> diff --git a/lib/atomic_web/controllers/user_confirmation_controller.ex b/lib/atomic_web/controllers/user_confirmation_controller.ex index 2ec91167c..f8d06a01b 100644 --- a/lib/atomic_web/controllers/user_confirmation_controller.ex +++ b/lib/atomic_web/controllers/user_confirmation_controller.ex @@ -11,7 +11,7 @@ defmodule AtomicWeb.UserConfirmationController do if user = Accounts.get_user_by_email(email) do Accounts.deliver_user_confirmation_instructions( user, - &Routes.user_confirmation_url(conn, :edit, &1) + &url(~p"/users/confirm/#{&1}") ) end diff --git a/lib/atomic_web/controllers/user_registration_controller.ex b/lib/atomic_web/controllers/user_registration_controller.ex index b12615add..f4282686b 100644 --- a/lib/atomic_web/controllers/user_registration_controller.ex +++ b/lib/atomic_web/controllers/user_registration_controller.ex @@ -21,7 +21,7 @@ defmodule AtomicWeb.UserRegistrationController do {:ok, _} = Accounts.deliver_user_confirmation_instructions( user, - &Routes.user_confirmation_url(conn, :edit, &1) + &url(~p"/users/confirm/#{&1}") ) conn diff --git a/lib/atomic_web/controllers/user_reset_password_controller.ex b/lib/atomic_web/controllers/user_reset_password_controller.ex index 903e6a796..7dd17c259 100644 --- a/lib/atomic_web/controllers/user_reset_password_controller.ex +++ b/lib/atomic_web/controllers/user_reset_password_controller.ex @@ -15,7 +15,7 @@ defmodule AtomicWeb.UserResetPasswordController do if user do Accounts.deliver_user_reset_password_instructions( user, - &Routes.user_reset_password_url(conn, :edit, &1) + &url(~p"/users/reset_password/#{&1}") ) end @@ -24,7 +24,7 @@ defmodule AtomicWeb.UserResetPasswordController do :info, "If your email or username is in our system, you will receive instructions to reset your password shortly." ) - |> redirect(to: Routes.user_session_path(conn, :new)) + |> redirect(to: ~p"/users/log_in") end def edit(conn, _params) do @@ -41,7 +41,7 @@ defmodule AtomicWeb.UserResetPasswordController do {:ok, _} -> conn |> put_flash(:info, "Password changed successfully.") - |> redirect(to: Routes.user_session_path(conn, :new)) + |> redirect(to: ~p"/users/log_in") {:error, changeset} -> render(conn, "edit.html", changeset: changeset, error_message: nil) diff --git a/lib/atomic_web/endpoint.ex b/lib/atomic_web/endpoint.ex index 59f02fcf0..fe8556b92 100644 --- a/lib/atomic_web/endpoint.ex +++ b/lib/atomic_web/endpoint.ex @@ -20,7 +20,7 @@ defmodule AtomicWeb.Endpoint do at: "/", from: :atomic, gzip: false, - only: ~w(assets fonts images favicon.ico robots.txt) + only: AtomicWeb.static_paths() plug(Plug.Static, at: "/uploads", diff --git a/lib/atomic_web/live/activity_live/edit.html.heex b/lib/atomic_web/live/activity_live/edit.html.heex index e90ac2e2b..db054f563 100644 --- a/lib/atomic_web/live/activity_live/edit.html.heex +++ b/lib/atomic_web/live/activity_live/edit.html.heex @@ -1,3 +1,3 @@
    - <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} title={@page_title} action={@live_action} activity={@activity} current_organization={@current_organization} return_to={Routes.activity_show_path(@socket, :show, @activity)} /> + <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={@activity.id} title={@page_title} action={@live_action} activity={@activity} current_organization={@current_organization} return_to={~p"/activities/#{@activity}"} />
    diff --git a/lib/atomic_web/live/activity_live/index.html.heex b/lib/atomic_web/live/activity_live/index.html.heex index d99d7663e..ffb627c8e 100644 --- a/lib/atomic_web/live/activity_live/index.html.heex +++ b/lib/atomic_web/live/activity_live/index.html.heex @@ -1,6 +1,6 @@ <.page title="Activities"> <:actions> - <.button navigate={Routes.activity_new_path(@socket, :new, @current_organization)}> + <.button navigate={~p"/organizations/#{@organization}/activities/new"}> <%= gettext("New") %> @@ -33,14 +33,14 @@ <%= if @empty? and @has_permissions? do %>
    - <.empty_state url={Routes.activity_new_path(@socket, :new, @current_organization)} placeholder="activity" /> + <.empty_state url={~p"/organizations/#{@organization}/activities/new"} placeholder="activity" />
    <% else %>
      <%= for activity <- @activities do %>
    • - <.link navigate={Routes.activity_show_path(@socket, :show, activity)} class="block hover:bg-zinc-50"> + <.link navigate={~p"/activities/#{activity}"} class="block hover:bg-zinc-50">

      diff --git a/lib/atomic_web/live/activity_live/new.html.heex b/lib/atomic_web/live/activity_live/new.html.heex index bd9884938..962236f15 100644 --- a/lib/atomic_web/live/activity_live/new.html.heex +++ b/lib/atomic_web/live/activity_live/new.html.heex @@ -1,3 +1,3 @@

      - <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={:new} title={@page_title} action={@live_action} activity={@activity} current_organization={@current_organization} return_to={Routes.activity_index_path(@socket, :index)} /> + <.live_component module={AtomicWeb.ActivityLive.FormComponent} id={:new} title={@page_title} action={@live_action} activity={@activity} current_organization={@current_organization} return_to={~p"/activities"} />
      diff --git a/lib/atomic_web/live/activity_live/show.ex b/lib/atomic_web/live/activity_live/show.ex index 6deb235e8..16842123c 100644 --- a/lib/atomic_web/live/activity_live/show.ex +++ b/lib/atomic_web/live/activity_live/show.ex @@ -70,7 +70,7 @@ defmodule AtomicWeb.ActivityLive.Show do {:noreply, socket |> put_flash(:error, gettext("You must be logged in to enroll in an activity.")) - |> push_navigate(to: Routes.user_session_path(socket, :new))} + |> push_navigate(to: ~p"/users/log_in")} end @impl true diff --git a/lib/atomic_web/live/activity_live/show.html.heex b/lib/atomic_web/live/activity_live/show.html.heex index 7863c02c6..940507490 100644 --- a/lib/atomic_web/live/activity_live/show.html.heex +++ b/lib/atomic_web/live/activity_live/show.html.heex @@ -137,7 +137,7 @@
      <%= if @has_permissions? do %> - <.link patch={Routes.activity_edit_path(@socket, :edit, @activity.organization_id, @activity)} class="button"> + <.link patch={~p"/organizations/#{@activity.organization_id}/activities/#{@activity}/edit"} class="button"> diff --git a/lib/atomic_web/live/announcement_live/edit.ex b/lib/atomic_web/live/announcement_live/edit.ex index dacf20f45..aee94beda 100644 --- a/lib/atomic_web/live/announcement_live/edit.ex +++ b/lib/atomic_web/live/announcement_live/edit.ex @@ -16,7 +16,7 @@ defmodule AtomicWeb.AnnouncementLive.Edit do {:noreply, socket |> put_flash(:info, gettext("Announcement deleted successfully")) - |> push_navigate(to: Routes.announcement_index_path(socket, :index))} + |> push_navigate(to: ~p"/announcements")} end @impl true diff --git a/lib/atomic_web/live/announcement_live/edit.html.heex b/lib/atomic_web/live/announcement_live/edit.html.heex index 190892171..c3db0c4f7 100644 --- a/lib/atomic_web/live/announcement_live/edit.html.heex +++ b/lib/atomic_web/live/announcement_live/edit.html.heex @@ -5,6 +5,6 @@
      - <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={Routes.announcement_show_path(@socket, :show, @announcement)} /> + <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={@announcement.id} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements/#{@announcement}"} />
      diff --git a/lib/atomic_web/live/announcement_live/index.html.heex b/lib/atomic_web/live/announcement_live/index.html.heex index fe6cce42f..623e7d4b1 100644 --- a/lib/atomic_web/live/announcement_live/index.html.heex +++ b/lib/atomic_web/live/announcement_live/index.html.heex @@ -1,7 +1,7 @@ <.page title="Announcements"> <:actions> <%= if not @empty? and @has_permissions? do %> - <.button navigate={Routes.announcement_new_path(@socket, :new, @current_organization)}> + <.button navigate={~p"/announcements/new"}> <%= gettext("New") %> <% end %> @@ -23,14 +23,14 @@ <%= if @empty? and @has_permissions? do %>
      - <.empty_state url={Routes.announcement_new_path(@socket, :new, @current_organization)} placeholder="announcement" /> + <.empty_state url={~p"/announcements/new"} placeholder="announcement" />
      <% else %>
        <%= for announcement <- @announcements do %>
      • - <.link navigate={Routes.announcement_show_path(@socket, :show, announcement)} class="block hover:bg-zinc-50"> + <.link navigate={~p"/announcements/#{announcement}"} class="block hover:bg-zinc-50">

        diff --git a/lib/atomic_web/live/announcement_live/new.html.heex b/lib/atomic_web/live/announcement_live/new.html.heex index 961cf1a41..bda286c44 100644 --- a/lib/atomic_web/live/announcement_live/new.html.heex +++ b/lib/atomic_web/live/announcement_live/new.html.heex @@ -1,5 +1,5 @@ <.page title={gettext("New Announcement")}>

        - <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={Routes.announcement_index_path(@socket, :index)} /> + <.live_component module={AtomicWeb.AnnouncementLive.FormComponent} id={:new} organization={@current_organization} title={@page_title} action={@live_action} announcement={@announcement} return_to={~p"/announcements"} />
        diff --git a/lib/atomic_web/live/announcement_live/show.html.heex b/lib/atomic_web/live/announcement_live/show.html.heex index e48df2ecb..308ae58e5 100644 --- a/lib/atomic_web/live/announcement_live/show.html.heex +++ b/lib/atomic_web/live/announcement_live/show.html.heex @@ -14,7 +14,7 @@
        <%= if @has_permissions? do %> - <.link patch={Routes.announcement_edit_path(@socket, :edit, @announcement.organization, @announcement)} class="px-2 button"> + <.link patch={~p"/organizations/#{@announcement.organization}/announcements/#{@announcement}/edit"} class="px-2 button"> diff --git a/lib/atomic_web/live/calendar_live/components/month.ex b/lib/atomic_web/live/calendar_live/components/month.ex index 7ef4b728f..f0ddefd13 100644 --- a/lib/atomic_web/live/calendar_live/components/month.ex +++ b/lib/atomic_web/live/calendar_live/components/month.ex @@ -48,7 +48,7 @@ defmodule AtomicWeb.CalendarLive.Components.CalendarMonth do
        1. - <.link patch={Routes.activity_show_path(AtomicWeb.Endpoint, :show, activity)} class="group flex justify-between p-4 pr-6 focus-within:bg-gray-50 hover:bg-gray-50"> + <.link patch={~p"/activities/#{activity}"} class="group flex justify-between p-4 pr-6 focus-within:bg-gray-50 hover:bg-gray-50">

          <%= activity.title %> @@ -143,7 +143,7 @@ defmodule AtomicWeb.CalendarLive.Components.CalendarMonth do

          1. Enum.take(2)}> - <.link patch={Routes.activity_show_path(AtomicWeb.Endpoint, :show, activity)} class="group flex"> + <.link patch={~p"/activities/#{activity}"} class="group flex">

            <%= activity.title %>

            diff --git a/lib/atomic_web/live/calendar_live/components/week.ex b/lib/atomic_web/live/calendar_live/components/week.ex index 692c59fce..3d50fbd4c 100644 --- a/lib/atomic_web/live/calendar_live/components/week.ex +++ b/lib/atomic_web/live/calendar_live/components/week.ex @@ -117,7 +117,7 @@ defmodule AtomicWeb.CalendarLive.Components.CalendarWeek do grid-row: #{calc_row_start(activity.start)} / span #{calc_time(activity.start, activity.finish)}; width: #{width}%; left: #{left}%"}> - <.link patch={Routes.activity_show_path(AtomicWeb.Endpoint, :show, activity)}> + <.link patch={~p"/activities/#{activity}"}>
            assign(:page_title, "Calendar") + |> assign(:page_title, gettext("Calendar")) |> assign(:current_page, :calendar) |> assign(:params, params) |> assign(:mode, mode) @@ -31,10 +31,10 @@ defmodule AtomicWeb.CalendarLive.Show do :activities, list_activities(socket.assigns.timezone, mode, current_date, socket.assigns.current_user) ) - |> assign(:current_path, Routes.calendar_show_path(AtomicWeb.Endpoint, :show)) + |> assign(:current_path, ~p"/calendar") |> assign(:current_date, current_date) - |> assigns_month(Routes.calendar_show_path(AtomicWeb.Endpoint, :show)) - |> assigns_week(Routes.calendar_show_path(AtomicWeb.Endpoint, :show))} + |> assigns_month(~p"/calendar") + |> assigns_week(~p"/calendar")} end @impl true @@ -116,7 +116,7 @@ defmodule AtomicWeb.CalendarLive.Show do {:noreply, socket |> assign(:current_date, date) - |> push_patch(to: Routes.calendar_show_path(socket, :show, mode: "week"), replace: true)} + |> push_patch(to: ~p"/calendar?mode=week", replace: true)} {:error, _reason} -> {:noreply, socket} @@ -147,9 +147,9 @@ defmodule AtomicWeb.CalendarLive.Show do defp assigns_dates(socket) do if socket.assigns.mode == "week" do - assigns_week(socket, Routes.calendar_show_path(AtomicWeb.Endpoint, :show)) + assigns_week(socket, ~p"/calendar") else - assigns_month(socket, Routes.calendar_show_path(AtomicWeb.Endpoint, :show)) + assigns_month(socket, ~p"/calendar") end end diff --git a/lib/atomic_web/live/collaborator_live/form_component.ex b/lib/atomic_web/live/collaborator_live/form_component.ex index 2232c865f..c596e3fb5 100644 --- a/lib/atomic_web/live/collaborator_live/form_component.ex +++ b/lib/atomic_web/live/collaborator_live/form_component.ex @@ -19,7 +19,7 @@ defmodule AtomicWeb.CollaboratorLive.FormComponent do <% end %>
            - <.link navigate={Routes.profile_show_path(@socket, :show, @collaborator.user)} class="mt-4 flex outline-none"> + <.link navigate={~p"/profile/#{@collaborator.user}"} class="mt-4 flex outline-none"> <.avatar color={:light_gray} name={@collaborator.user.name} />

            <%= @collaborator.user.name %>

            diff --git a/lib/atomic_web/live/department_live/edit.ex b/lib/atomic_web/live/department_live/edit.ex index d3dc6634c..00e228558 100644 --- a/lib/atomic_web/live/department_live/edit.ex +++ b/lib/atomic_web/live/department_live/edit.ex @@ -59,9 +59,7 @@ defmodule AtomicWeb.DepartmentLive.Edit do {:noreply, socket - |> push_navigate( - to: Routes.department_index_path(socket, :index, socket.assigns.organization_id) - ) + |> push_navigate(to: ~p"/organizations/#{socket.assigns.organization_id}/departments") |> put_flash(:info, gettext("Department archived successfully"))} end @@ -71,9 +69,7 @@ defmodule AtomicWeb.DepartmentLive.Edit do {:noreply, socket - |> push_navigate( - to: Routes.department_index_path(socket, :index, socket.assigns.organization_id) - ) + |> push_navigate(to: ~p"/organizations/#{socket.assigns.organization_id}/departments") |> put_flash(:info, gettext("Department unarchived successfully"))} end @@ -83,9 +79,7 @@ defmodule AtomicWeb.DepartmentLive.Edit do {:noreply, socket - |> push_navigate( - to: Routes.department_index_path(socket, :index, socket.assigns.organization_id) - ) + |> push_navigate(to: ~p"/organizations/#{socket.assigns.organization_id}/departments") |> put_flash(:info, gettext("Department deleted successfully"))} end diff --git a/lib/atomic_web/live/department_live/edit.html.heex b/lib/atomic_web/live/department_live/edit.html.heex index 878fc3d73..2bcec0163 100644 --- a/lib/atomic_web/live/department_live/edit.html.heex +++ b/lib/atomic_web/live/department_live/edit.html.heex @@ -36,9 +36,9 @@ department={@department} return_to={ if @live_action in [:new] do - Routes.department_index_path(@socket, :index, @organization_id) + ~p"/organizations/#{@organization_id}/departments" else - Routes.department_show_path(@socket, :show, @organization_id, @department) + ~p"/organizations/#{@organization_id}/departments/#{@department}" end } /> diff --git a/lib/atomic_web/live/department_live/index.html.heex b/lib/atomic_web/live/department_live/index.html.heex index 7fec888bf..f6002c3cf 100644 --- a/lib/atomic_web/live/department_live/index.html.heex +++ b/lib/atomic_web/live/department_live/index.html.heex @@ -1,7 +1,7 @@ <.page title="Departments"> <:actions> <%= if not @empty? and @has_permissions? do %> - <.button patch={Routes.department_edit_path(@socket, :new, @current_organization)} icon="hero-plus"> + <.button patch={~p"/organizations/#{@current_organization}/departments/new"} icon="hero-plus"> <%= gettext("New") %> <% end %> @@ -9,12 +9,12 @@ <%= if @empty? and @has_permissions? do %>
            - <.empty_state url={Routes.department_edit_path(@socket, :new, @current_organization)} placeholder="department" /> + <.empty_state url={~p"/organizations/#{@current_organization}/departments/new"} placeholder="department" />
            <% else %>
            <%= for {department, collaborators} <- @departments do %> - <.link navigate={Routes.department_show_path(@socket, :show, @organization, department)}> + <.link navigate={~p"/organizations/#{@current_organization}/departments/#{department}"}> <.department_card department={department} collaborators={collaborators} /> <% end %> diff --git a/lib/atomic_web/live/department_live/show.ex b/lib/atomic_web/live/department_live/show.ex index 85f88883c..7020c23bd 100644 --- a/lib/atomic_web/live/department_live/show.ex +++ b/lib/atomic_web/live/department_live/show.ex @@ -113,13 +113,7 @@ defmodule AtomicWeb.DepartmentLive.Show do |> assign(:live_action, :show) |> push_patch( to: - Routes.department_show_path( - socket, - :show, - socket.assigns.organization, - socket.assigns.department, - Map.delete(socket.assigns.params, "collaborator_id") - ) + ~p"/organizations/#{socket.assigns.organization}/departments/#{socket.assigns.department}?#{Map.delete(socket.assigns.params, "collaborator_id")}" )} end @@ -135,8 +129,7 @@ defmodule AtomicWeb.DepartmentLive.Show do |> put_flash(:success, gettext("Applied to collaborate successfully.")) |> assign(:collaborator, collaborator) |> push_patch( - to: - Routes.department_show_path(socket, :show, department.organization_id, department.id) + to: ~p"/organizations/#{department.organization_id}/departments/#{department}" )} {:error, %Ecto.Changeset{} = changeset} -> @@ -147,9 +140,7 @@ defmodule AtomicWeb.DepartmentLive.Show do :error, "There was an error while trying to apply for this department. Please try again!" ) - |> push_navigate( - to: Routes.department_index_path(socket, :index, department.organization_id) - )} + |> push_navigate(to: ~p"/organizations/#{department.organization_id}/departments")} end end @@ -158,7 +149,7 @@ defmodule AtomicWeb.DepartmentLive.Show do {:noreply, socket |> put_flash(:error, gettext("You must be logged in to follow an organization.")) - |> push_navigate(to: Routes.user_session_path(socket, :new))} + |> push_navigate(to: ~p"/users/log_in")} end defp maybe_put_collaborator(socket, _department_id) when not socket.assigns.is_authenticated?, diff --git a/lib/atomic_web/live/department_live/show.html.heex b/lib/atomic_web/live/department_live/show.html.heex index 70e19ab49..2a70d5c88 100644 --- a/lib/atomic_web/live/department_live/show.html.heex +++ b/lib/atomic_web/live/department_live/show.html.heex @@ -2,7 +2,7 @@
            <%= if @department.banner do %> - + <% else %> <.gradient seed={@department.id} class="object-cover" /> <% end %> @@ -11,13 +11,13 @@
            -
            +
            -

            +

            <%= @department.name %>

            - <.link navigate={Routes.organization_show_path(@socket, :show, @organization)}> + <.link navigate={~p"/organizations/#{@organization}"}>

            @<%= @organization.name %>

            @@ -54,19 +54,12 @@ [ %{ name: gettext("Collaborators"), - navigate: - Routes.department_show_path( - @socket, - :show, - @organization.id, - @department.id, - tab: "collaborators" - ), + navigate: ~p"/organizations/#{@organization}/departments/#{@department}?tab=collaborators", icon: "hero-user-group" } ] ++ if @has_permissions? || (@current_collaborator && @current_collaborator.accepted) do - [%{name: gettext("Edit"), navigate: Routes.department_edit_path(@socket, :edit, @organization, @department, @params), icon: "hero-pencil"}] + [%{name: gettext("Edit"), navigate: ~p"/organizations/#{@organization}/departments/#{@department}/edit?#{@params}", icon: "hero-pencil"}] else [] end @@ -79,7 +72,7 @@ <% end %>
            - @@ -152,14 +122,14 @@

            <%= gettext("Recent Activity") %>

            - <.link class="flex flex-col items-center justify-center mt-4" navigate={Routes.organization_show_path(@socket, :show, @organization)}> + <.link class="mt-4 flex flex-col items-center justify-center" navigate={~p"/organizations/#{@organization}"}> <.avatar class="mb-4 p-1" type={:organization} color={:white} size={:lg} name={@organization.name} src={Uploaders.Logo.url({@organization.logo, @organization}, :original)} />

            <%= gettext("This department doesn't have any recent activity.") %>

            <%= gettext("In the meantime, check out %{organization_name}.", organization_name: @organization.name) %>

            -
            -<.modal :if={@live_action in [:edit_collaborator]} id="edit-collaborator" show on_cancel={JS.patch(Routes.department_show_path(@socket, :show, @organization, @department, Map.delete(@params, "collaborator_id")))}> +<.modal :if={@live_action in [:edit_collaborator]} id="edit-collaborator" show on_cancel={JS.patch(~p"/organizations/#{@organization}/departments/#{@department}?#{Map.delete(@params, "collaborator_id")}")}> <.live_component module={AtomicWeb.CollaboratorLive.FormComponent} id={@collaborator.id} title={@page_title} action={@live_action} collaborator={@collaborator} department={@department} /> diff --git a/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex b/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex index f1b3d5260..7e94c5938 100644 --- a/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex +++ b/lib/atomic_web/live/home_live/components/follow_suggestions/follow_suggestions.ex @@ -26,7 +26,7 @@ defmodule AtomicWeb.HomeLive.Components.FollowSuggestions do
      - <.button patch={Routes.organization_index_path(AtomicWeb.Endpoint, :index)} color={:white} size={:md} full_width> + <.button patch={~p"/organizations"} color={:white} size={:md} full_width> <%= gettext("View all") %>
      diff --git a/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex b/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex index 569489e22..28b03adbe 100644 --- a/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex +++ b/lib/atomic_web/live/home_live/components/follow_suggestions/suggestion.ex @@ -22,7 +22,7 @@ defmodule AtomicWeb.HomeLive.Components.FollowSuggestions.Suggestion do def render(assigns) do ~H"""
    • - <.link navigate={Routes.organization_show_path(AtomicWeb.Endpoint, :show, @organization)} class="flex min-w-0 flex-1 items-center space-x-3 py-4"> + <.link navigate={~p"/organizations/#{@organization}"} class="flex min-w-0 flex-1 items-center space-x-3 py-4">
      <.avatar name={@organization.name} class="!h-10 !w-10 !text-lg" color={:light_gray} size={:xs} type={:organization} src={Uploaders.Logo.url({@organization.logo, @organization}, :original)} />
      diff --git a/lib/atomic_web/live/home_live/components/schedule.ex b/lib/atomic_web/live/home_live/components/schedule.ex index 43e7a0bc5..9a776dd17 100644 --- a/lib/atomic_web/live/home_live/components/schedule.ex +++ b/lib/atomic_web/live/home_live/components/schedule.ex @@ -14,7 +14,7 @@ defmodule AtomicWeb.HomeLive.Components.Schedule do
        <%= for entry <- @schedule.daily do %> - <.link navigate={Routes.activity_show_path(AtomicWeb.Endpoint, :show, entry)}> + <.link navigate={~p"/activities/#{entry}"}>
      • <%= entry.title %> @@ -41,7 +41,7 @@ defmodule AtomicWeb.HomeLive.Components.Schedule do

          <%= for entry <- @schedule.weekly do %> - <.link navigate={Routes.activity_show_path(AtomicWeb.Endpoint, :show, entry)}> + <.link navigate={~p"/activities/#{entry}"}>
        • <%= entry.title %> diff --git a/lib/atomic_web/live/home_live/index.html.heex b/lib/atomic_web/live/home_live/index.html.heex index aba4aed0b..57d964964 100644 --- a/lib/atomic_web/live/home_live/index.html.heex +++ b/lib/atomic_web/live/home_live/index.html.heex @@ -42,11 +42,11 @@

          • <%= if post.type == :activity do %> - <.link navigate={Routes.activity_show_path(@socket, :show, post.activity)}> + <.link navigate={~p"/activities/#{post.activity}"}> <.activity activity={post.activity} /> <% else %> - <.link navigate={Routes.announcement_show_path(@socket, :show, post.announcement)}> + <.link navigate={~p"/announcements/#{post.announcement}"}> <.announcement announcement={post.announcement} /> <% end %> diff --git a/lib/atomic_web/live/organization_live/edit.html.heex b/lib/atomic_web/live/organization_live/edit.html.heex index 35ce9de8b..a2f554905 100644 --- a/lib/atomic_web/live/organization_live/edit.html.heex +++ b/lib/atomic_web/live/organization_live/edit.html.heex @@ -1 +1 @@ -<.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization} title={@page_title} action={@live_action} organization={@organization} return_to={Routes.organization_show_path(@socket, :show, @organization)} /> +<.live_component module={AtomicWeb.OrganizationLive.FormComponent} id={@organization} title={@page_title} action={@live_action} organization={@organization} return_to={~p"/organizations/#{@organization}"} /> diff --git a/lib/atomic_web/live/organization_live/index.html.heex b/lib/atomic_web/live/organization_live/index.html.heex index 1f46ca745..25f8ae65a 100644 --- a/lib/atomic_web/live/organization_live/index.html.heex +++ b/lib/atomic_web/live/organization_live/index.html.heex @@ -1,7 +1,7 @@ <.page title="Organizations"> <:actions> <%= if not @empty? and @has_permissions? do %> - <.button navigate={Routes.organization_new_path(@socket, :new)}> + <.button navigate={~p"/organizations/new"}> <%= gettext("New") %> <% end %> @@ -9,12 +9,12 @@ <%= if @empty? and @has_permissions? do %>
            - <.empty_state url={Routes.organization_index_path(@socket, :new)} placeholder="organization" /> + <.empty_state url={~p"/organizations/new"} placeholder="organization" />
            <% else %>
            <%= for organization <- @organizations do %> - <.link navigate={Routes.organization_show_path(@socket, :show, organization)}> + <.link navigate={~p"/organizations/#{organization.id}"}>
            <.avatar name={organization.name} src={Uploaders.Logo.url({organization.logo, organization}, :original)} type={:organization} size={:lg} color={:light_gray} />
            diff --git a/lib/atomic_web/live/organization_live/new.html.heex b/lib/atomic_web/live/organization_live/new.html.heex index 48a9c7a7a..6372c7552 100644 --- a/lib/atomic_web/live/organization_live/new.html.heex +++ b/lib/atomic_web/live/organization_live/new.html.heex @@ -1 +1 @@ -<.live_component module={AtomicWeb.OrganizationLive.FormComponent} current_user={@current_user} organization={@current_organization} id={:new} title={@page_title} action={@live_action} return_to={Routes.organization_index_path(@socket, :index)} /> +<.live_component module={AtomicWeb.OrganizationLive.FormComponent} current_user={@current_user} organization={@current_organization} id={:new} title={@page_title} action={@live_action} return_to={~p"/organizations"} /> diff --git a/lib/atomic_web/live/organization_live/show.ex b/lib/atomic_web/live/organization_live/show.ex index d24adbd91..d47b3f094 100644 --- a/lib/atomic_web/live/organization_live/show.ex +++ b/lib/atomic_web/live/organization_live/show.ex @@ -47,9 +47,7 @@ defmodule AtomicWeb.OrganizationLive.Show do socket |> put_flash(:success, "Started following " <> socket.assigns.organization.name) |> assign(:following?, true) - |> push_patch( - to: Routes.organization_show_path(socket, :show, socket.assigns.organization.id) - )} + |> push_patch(to: ~p"/organizations/#{socket.assigns.organization}")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :changeset, changeset)} @@ -70,9 +68,7 @@ defmodule AtomicWeb.OrganizationLive.Show do socket |> put_flash(:success, "Stopped following " <> socket.assigns.organization.name) |> assign(:following?, false) - |> push_patch( - to: Routes.organization_show_path(socket, :show, socket.assigns.organization.id) - )} + |> push_patch(to: ~p"/organizations/#{socket.assigns.organization}")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :changeset, changeset)} @@ -84,7 +80,7 @@ defmodule AtomicWeb.OrganizationLive.Show do {:noreply, socket |> put_flash(:error, gettext("You must be logged in to follow an organization.")) - |> push_navigate(to: Routes.user_session_path(socket, :new))} + |> push_navigate(to: ~p"/users/log_in")} end defp list_activities(organization_id) do diff --git a/lib/atomic_web/live/organization_live/show.html.heex b/lib/atomic_web/live/organization_live/show.html.heex index f56835293..a639572fd 100644 --- a/lib/atomic_web/live/organization_live/show.html.heex +++ b/lib/atomic_web/live/organization_live/show.html.heex @@ -71,7 +71,7 @@ <% end %> <% end %> <%= if @has_permissions? do %> - <.link patch={Routes.organization_edit_path(@socket, :edit, @organization)} class="button"> + <.link patch={~p"/organizations/#{@organization}/edit"} class="button"> diff --git a/lib/atomic_web/live/partner_live/edit.ex b/lib/atomic_web/live/partner_live/edit.ex index 9e78fd774..32344de1b 100644 --- a/lib/atomic_web/live/partner_live/edit.ex +++ b/lib/atomic_web/live/partner_live/edit.ex @@ -56,7 +56,7 @@ defmodule AtomicWeb.PartnerLive.Edit do {:noreply, socket |> put_flash(:success, "Partner deleted successfully") - |> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} + |> push_navigate(to: ~p"/organizations/#{organization_id}/partners")} {:error, _reason} -> {:noreply, put_flash(socket, :error, "Failed to delete partner")} @@ -73,7 +73,7 @@ defmodule AtomicWeb.PartnerLive.Edit do {:noreply, socket |> put_flash(:success, "Partner archived successfully") - |> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} + |> push_navigate(to: ~p"/organizations/#{organization_id}/partners")} {:error, _reason} -> {:noreply, put_flash(socket, :error, "Failed to delete partner")} @@ -88,8 +88,8 @@ defmodule AtomicWeb.PartnerLive.Edit do {:ok, _partner} -> {:noreply, socket - |> put_flash(:success, "Partner archived successfully") - |> push_redirect(to: Routes.partner_index_path(socket, :index, organization_id))} + |> put_flash(:success, "Partner unarchived successfully") + |> push_navigate(to: ~p"/organizations/#{organization_id}/partners")} {:error, _reason} -> {:noreply, put_flash(socket, :error, "Failed to delete partner")} diff --git a/lib/atomic_web/live/partner_live/edit.html.heex b/lib/atomic_web/live/partner_live/edit.html.heex index fc63e6ad5..c4a13f4b3 100644 --- a/lib/atomic_web/live/partner_live/edit.html.heex +++ b/lib/atomic_web/live/partner_live/edit.html.heex @@ -27,7 +27,7 @@ <% end %>
            - <.live_component module={AtomicWeb.PartnerLive.FormComponent} organization={@current_organization} id={@partner.id || :new} title={@page_title} action={@live_action} partner={@partner} return_to={Routes.partner_index_path(@socket, :index, @current_organization)} /> + <.live_component module={AtomicWeb.PartnerLive.FormComponent} organization={@current_organization} id={@partner.id || :new} title={@page_title} action={@live_action} partner={@partner} return_to={~p"/organizations/#{@current_organization}/partners"} />
            diff --git a/lib/atomic_web/live/partner_live/index.html.heex b/lib/atomic_web/live/partner_live/index.html.heex index 4e7b7e895..9001cb2bc 100644 --- a/lib/atomic_web/live/partner_live/index.html.heex +++ b/lib/atomic_web/live/partner_live/index.html.heex @@ -1,7 +1,7 @@ <.page title="Partners"> <:actions> <%= if not @empty? and @has_permissions? do %> - <.button navigate={Routes.partner_edit_path(@socket, :new, @current_organization)} icon="hero-plus"> + <.button navigate={~p"/organizations/#{@current_organization}/partners/new"} icon="hero-plus"> New Partner <% end %> @@ -30,12 +30,12 @@ <%= if @empty? and @has_permissions? do %>
            - <.empty_state url={Routes.partner_edit_path(@socket, :new, @organization)} placeholder="partnership" /> + <.empty_state url={~p"/organizations/#{@organization}/partners/new"} placeholder="partner" />
            <% else %>
              <%= for partner <- @partners do %> - <.link navigate={Routes.partner_show_path(@socket, :show, @organization, partner)} class="block hover:bg-zinc-50"> + <.link navigate={~p"/organizations/#{@organization}/partners/#{partner}"} class="block hover:bg-zinc-50">
            • diff --git a/lib/atomic_web/live/partner_live/show.html.heex b/lib/atomic_web/live/partner_live/show.html.heex index b585f556e..0756af2d2 100644 --- a/lib/atomic_web/live/partner_live/show.html.heex +++ b/lib/atomic_web/live/partner_live/show.html.heex @@ -2,7 +2,7 @@ <:actions> <%= if @has_permissions? do %>
              - <.button navigate={Routes.partner_edit_path(@socket, :edit, @organization, @partner)} icon="hero-pencil"> + <.button navigate={~p"/organizations/#{@organization}/partners/#{@partner}/edit"} icon="hero-pencil"> <%= gettext("Edit Partner") %>
              @@ -92,7 +92,7 @@
              <%= for partner <- @partners |> Enum.filter(fn partner -> partner.id != @partner.id end) do %>
              - <.link href={Routes.partner_show_path(@socket, :show, @organization, partner)}> + <.link href={~p"/organizations/#{@organization}/partners/#{@partner}"}>
              <.avatar color={:light_gray} name={partner.name} src={Uploaders.PartnerImage.url({partner.image, partner}, :original)} type={:company} size={:xs} />

              <%= partner.name %>

              diff --git a/lib/atomic_web/live/profile_live/edit.ex b/lib/atomic_web/live/profile_live/edit.ex index 354261c72..1e8b79783 100644 --- a/lib/atomic_web/live/profile_live/edit.ex +++ b/lib/atomic_web/live/profile_live/edit.ex @@ -19,7 +19,7 @@ defmodule AtomicWeb.ProfileLive.Edit do |> assign(:current_page, :profile) |> assign(:user, user)} else - {:noreply, socket |> redirect(to: Routes.profile_show_path(socket, :show, user_slug))} + {:noreply, socket |> redirect(to: ~p"/profile/#{user_slug}")} end end @@ -29,13 +29,13 @@ defmodule AtomicWeb.ProfileLive.Edit do {:noreply, socket |> put_flash(:info, "Email changed successfully.") - |> redirect(to: Routes.profile_show_path(socket, :show, socket.assigns.current_user))} + |> redirect(to: ~p"/profile/#{socket.assigns.current_user}")} :error -> {:noreply, socket |> put_flash(:error, "Email change link is invalid or it has expired.") - |> redirect(to: Routes.profile_show_path(socket, :show, socket.assigns.current_user))} + |> redirect(to: ~p"/profile/#{socket.assigns.current_user}")} end end end diff --git a/lib/atomic_web/live/profile_live/form_component.ex b/lib/atomic_web/live/profile_live/form_component.ex index 82fe062f4..b0e083345 100644 --- a/lib/atomic_web/live/profile_live/form_component.ex +++ b/lib/atomic_web/live/profile_live/form_component.ex @@ -42,7 +42,7 @@ defmodule AtomicWeb.ProfileLive.FormComponent do Accounts.deliver_update_email_instructions( applied_user, user.email, - &Routes.profile_edit_url(socket, :confirm_email, &1) + &url(~p"/users/confirm_email/#{&1}") ) "Profile updated successfully, please check your email to confirm the new address." @@ -60,7 +60,7 @@ defmodule AtomicWeb.ProfileLive.FormComponent do {:noreply, socket |> put_flash(:success, flash_text) - |> push_navigate(to: Routes.profile_show_path(socket, :show, user_params["slug"]))} + |> push_navigate(to: ~p"/profile/#{user_params["slug"]}")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :changeset, changeset)} diff --git a/lib/atomic_web/live/profile_live/show.html.heex b/lib/atomic_web/live/profile_live/show.html.heex index 60dde0ff6..3948d6798 100644 --- a/lib/atomic_web/live/profile_live/show.html.heex +++ b/lib/atomic_web/live/profile_live/show.html.heex @@ -39,7 +39,7 @@ <%= if @is_current_user do %>
              - <.button patch={Routes.profile_edit_path(@socket, :edit, @user)}> + <.button patch={~p"/profile/#{@user}/edit"}> <%= gettext("Edit") %>
              diff --git a/lib/atomic_web/live/scanner_live/index.ex b/lib/atomic_web/live/scanner_live/index.ex index 392fe516c..d1ca055dc 100644 --- a/lib/atomic_web/live/scanner_live/index.ex +++ b/lib/atomic_web/live/scanner_live/index.ex @@ -36,7 +36,7 @@ defmodule AtomicWeb.ScannerLive.Index do {:noreply, socket |> put_flash(:error, "You are not authorized to this") - |> redirect(to: Routes.scanner_index_path(socket, :index))} + |> redirect(to: ~p"/scanner")} end end @@ -49,7 +49,7 @@ defmodule AtomicWeb.ScannerLive.Index do socket |> put_flash(:success, "Participation confirmed!") |> assign(:changeset, nil) - |> redirect(to: Routes.scanner_index_path(socket, :index))} + |> redirect(to: ~p"/scanner")} {:error, changeset} -> {:noreply, diff --git a/lib/atomic_web/live/user_live/edit.html.heex b/lib/atomic_web/live/user_live/edit.html.heex index 4896ca8b5..111c50140 100644 --- a/lib/atomic_web/live/user_live/edit.html.heex +++ b/lib/atomic_web/live/user_live/edit.html.heex @@ -1 +1 @@ -<.live_component module={AtomicWeb.UserLive.FormComponent} user={@user} id={@current_user.id} courses={@courses} title={@page_title} action={@live_action} return_to={Routes.home_index_path(@conn, :index)} /> +<.live_component module={AtomicWeb.UserLive.FormComponent} user={@user} id={@current_user.id} courses={@courses} title={@page_title} action={@live_action} return_to={~p"/"} /> diff --git a/lib/atomic_web/templates/error/404.html.heex b/lib/atomic_web/templates/error/404.html.heex index 6ff1b92f9..141375312 100644 --- a/lib/atomic_web/templates/error/404.html.heex +++ b/lib/atomic_web/templates/error/404.html.heex @@ -6,11 +6,7 @@ <%= live_title_tag(assigns[:page_title] || "Atomic", suffix: " · 404") %> - - - - - +
              @@ -18,7 +14,7 @@ Error 404
              -

              Page not found

              +

              Page Not Found

              <.link href="/" class="inline-flex items-center rounded-md bg-orange-500 px-3 py-2 my-4 text-sm font-semibold text-white shadow-sm hover:bg-orange-600 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-orange-500"> <%= gettext("Go back home") %> diff --git a/lib/atomic_web/templates/error/500.html.heex b/lib/atomic_web/templates/error/500.html.heex index ae5c8411b..6b6f4a100 100644 --- a/lib/atomic_web/templates/error/500.html.heex +++ b/lib/atomic_web/templates/error/500.html.heex @@ -6,11 +6,7 @@ <%= live_title_tag(assigns[:page_title] || "500", suffix: " · Atomic") %> - - - - - +
              diff --git a/lib/atomic_web/templates/layout/_user_menu.html.heex b/lib/atomic_web/templates/layout/_user_menu.html.heex index 814712910..0f2d932c9 100644 --- a/lib/atomic_web/templates/layout/_user_menu.html.heex +++ b/lib/atomic_web/templates/layout/_user_menu.html.heex @@ -1,7 +1,7 @@ <%= if @current_user do %>
            • <%= @current_user.email %>
            • -
            • <%= link("Log out", to: Routes.user_session_path(@conn, :delete), method: :delete) %>
            • +
            • <%= link("Log out", to: ~p"/users/log_out", method: :delete) %>
            • <% else %> -
            • <%= link("Register", to: Routes.user_registration_path(@conn, :new)) %>
            • -
            • <%= link("Log in", to: Routes.user_session_path(@conn, :new)) %>
            • +
            • <%= link("Register", to: ~p"/users/register") %>
            • +
            • <%= link("Log in", to: ~p"/users/log_in") %>
            • <% end %> diff --git a/lib/atomic_web/templates/layout/root.html.heex b/lib/atomic_web/templates/layout/root.html.heex index f305f6b42..2310c0d3f 100644 --- a/lib/atomic_web/templates/layout/root.html.heex +++ b/lib/atomic_web/templates/layout/root.html.heex @@ -6,8 +6,8 @@ <%= csrf_meta_tag() %> <%= live_title_tag(assigns[:page_title] || "") %> - - diff --git a/lib/atomic_web/templates/user_change_password/edit.html.heex b/lib/atomic_web/templates/user_change_password/edit.html.heex index 983425f86..e666bdbee 100644 --- a/lib/atomic_web/templates/user_change_password/edit.html.heex +++ b/lib/atomic_web/templates/user_change_password/edit.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={@changeset} action={Routes.user_change_password_path(@conn, :update)} id="update_password" class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0"> + <.form :let={f} for={@changeset} action={~p"/users/change_password"} id="update_password" class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0">

              <%= gettext("Change Password") %>

              diff --git a/lib/atomic_web/templates/user_confirmation/new.html.heex b/lib/atomic_web/templates/user_confirmation/new.html.heex index e87a0e37f..5a2bade2a 100644 --- a/lib/atomic_web/templates/user_confirmation/new.html.heex +++ b/lib/atomic_web/templates/user_confirmation/new.html.heex @@ -1,6 +1,6 @@

              Resend confirmation instructions

              -<.form :let={f} for={%{}} as={:user} action={Routes.user_confirmation_path(@conn, :create)}> +<.form :let={f} for={%{}} as={:user} action={~p"/users/confirm"}> <%= label(f, :email) %> <%= email_input(f, :email, required: true) %> @@ -10,5 +10,5 @@

              - <%= link("Register", to: Routes.user_registration_path(@conn, :new)) %> | <%= link("Log in", to: Routes.user_session_path(@conn, :new)) %> + <%= link("Register", to: ~p"/users/register") %> | <%= link("Log in", to: ~p"/users/log_in") %>

              diff --git a/lib/atomic_web/templates/user_registration/new.html.heex b/lib/atomic_web/templates/user_registration/new.html.heex index 1ffbf4d0a..de7342dcd 100644 --- a/lib/atomic_web/templates/user_registration/new.html.heex +++ b/lib/atomic_web/templates/user_registration/new.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={@changeset} action={Routes.user_registration_path(@conn, :create)} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 sm:mx-0"> + <.form :let={f} for={@changeset} action={~p"/users/register"} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 sm:mx-0">

              <%= gettext("Register") %>

              @@ -66,7 +66,7 @@ Already have an account? - <%= link("Login", to: Routes.user_session_path(@conn, :new), class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %> + <%= link("Login", to: ~p"/users/log_in", class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %>
              diff --git a/lib/atomic_web/templates/user_reset_password/edit.html.heex b/lib/atomic_web/templates/user_reset_password/edit.html.heex index 9b6ddc621..c27f499ed 100644 --- a/lib/atomic_web/templates/user_reset_password/edit.html.heex +++ b/lib/atomic_web/templates/user_reset_password/edit.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={@changeset} action={Routes.user_reset_password_path(@conn, :update, @token)} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0"> + <.form :let={f} for={@changeset} action={~p"/users/reset_password/#{@token}"} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0">

              <%= gettext("Reset Password") %>

              diff --git a/lib/atomic_web/templates/user_reset_password/new.html.heex b/lib/atomic_web/templates/user_reset_password/new.html.heex index 47cf1f5e5..2db6e8e5e 100644 --- a/lib/atomic_web/templates/user_reset_password/new.html.heex +++ b/lib/atomic_web/templates/user_reset_password/new.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={%{}} as={:user} action={Routes.user_reset_password_path(@conn, :create)} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0"> + <.form :let={f} for={%{}} as={:user} action={~p"/users/reset_password"} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0">

              <%= gettext("Recover Account") %>

              @@ -39,7 +39,7 @@
              - <%= link(gettext("Remember your password?"), to: Routes.user_session_path(@conn, :new), class: "font-medium text-orange-400 hover:text-orange-500 focus:outline-none") %> + <%= link(gettext("Remember your password?"), to: ~p"/users/log_in", class: "font-medium text-orange-400 hover:text-orange-500 focus:outline-none") %>
              diff --git a/lib/atomic_web/templates/user_session/new.html.heex b/lib/atomic_web/templates/user_session/new.html.heex index 19c6f5377..f4e5eb15f 100644 --- a/lib/atomic_web/templates/user_session/new.html.heex +++ b/lib/atomic_web/templates/user_session/new.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={@conn} action={Routes.user_session_path(@conn, :create)} as={:user} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0"> + <.form :let={f} for={@conn} action={~p"/users/log_in"} as={:user} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 space-y-6 sm:mx-0">

              <%= gettext("Log") %><%= gettext("in") %>

              @@ -52,7 +52,7 @@ New here? - <%= link("Register", to: Routes.user_registration_path(@conn, :new), class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %> + <%= link("Register", to: ~p"/users/register", class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %>
              @@ -66,7 +66,7 @@
              - <%= link(gettext("Forgot your password?"), to: Routes.user_reset_password_path(@conn, :new), class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %> + <%= link(gettext("Forgot your password?"), to: ~p"/users/reset_password", class: "font-medium text-orange-500 hover:text-orange-500 focus:outline-none") %>
              diff --git a/lib/atomic_web/templates/user_settings/edit.html.heex b/lib/atomic_web/templates/user_settings/edit.html.heex index 86e9b2fa4..33d9d3e3a 100644 --- a/lib/atomic_web/templates/user_settings/edit.html.heex +++ b/lib/atomic_web/templates/user_settings/edit.html.heex @@ -4,7 +4,7 @@

              <%= gettext("Change Email") %>

              - <.form :let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email" class="flex flex-col items-center justify-center w-full h-full mx-8 sm:mx-0"> + <.form :let={f} for={@email_changeset} action={~p"/profile"} id="update_email" class="flex flex-col items-center justify-center w-full h-full mx-8 sm:mx-0"> <%= if @email_changeset.action do %>

              Oops, something went wrong! Please check the errors below.

              @@ -37,7 +37,7 @@

              <%= gettext("Change Password") %>

              - <.form :let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password" class="flex flex-col items-center justify-center w-full h-full mx-8 sm:mx-0"> + <.form :let={f} for={@password_changeset} action={~p"/profile"} id="update_password" class="flex flex-col items-center justify-center w-full h-full mx-8 sm:mx-0"> <%= if @password_changeset.action do %>

              Oops, something went wrong! Please check the errors below.

              diff --git a/lib/atomic_web/templates/user_setup/edit.html.heex b/lib/atomic_web/templates/user_setup/edit.html.heex index 686b451fd..a2b9fc985 100644 --- a/lib/atomic_web/templates/user_setup/edit.html.heex +++ b/lib/atomic_web/templates/user_setup/edit.html.heex @@ -1,5 +1,5 @@
              - <.form :let={f} for={@changeset} action={Routes.user_setup_path(@conn, :finish)} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 sm:mx-0"> + <.form :let={f} for={@changeset} action={~p"/users/setup"} class="flex flex-col items-center justify-center w-full h-full mx-8 mt-8 sm:mx-0">

              <%= gettext("Welcome to Atomic!") %>

              👋

              diff --git a/test/atomic_web/controllers/user_auth_test.exs b/test/atomic_web/controllers/user_auth_test.exs index c95f7500f..3eb6526e4 100644 --- a/test/atomic_web/controllers/user_auth_test.exs +++ b/test/atomic_web/controllers/user_auth_test.exs @@ -130,7 +130,7 @@ defmodule AtomicWeb.UserAuthTest do test "redirects if user is not authenticated", %{conn: conn} do conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([]) assert conn.halted - assert redirected_to(conn) == Routes.user_session_path(conn, :new) + assert redirected_to(conn) == ~p"/users/log_in" assert Phoenix.Flash.get(conn.assigns.flash, :error) == "You must log in to access this page." diff --git a/test/atomic_web/controllers/user_change_password_controller_test.exs b/test/atomic_web/controllers/user_change_password_controller_test.exs index 0b9e6bae9..ee9c2c589 100644 --- a/test/atomic_web/controllers/user_change_password_controller_test.exs +++ b/test/atomic_web/controllers/user_change_password_controller_test.exs @@ -8,22 +8,22 @@ defmodule AtomicWeb.UserSettingsControllerTest do describe "GET /users/change_password" do test "renders change password page", %{conn: conn} do - conn = get(conn, Routes.user_change_password_path(conn, :edit)) + conn = get(conn, ~p"/users/change_password") response = html_response(conn, 200) assert response =~ "Change Password" end test "redirects if user is not logged in" do conn = build_conn() - conn = get(conn, Routes.user_change_password_path(conn, :edit)) - assert redirected_to(conn) == Routes.user_session_path(conn, :new) + conn = get(conn, ~p"/users/change_password") + assert redirected_to(conn) == ~p"/users/log_in" end end describe "PUT /users/change_password" do test "updates the user password and resets tokens", %{conn: conn, user: user} do new_password_conn = - put(conn, Routes.user_change_password_path(conn, :update), %{ + put(conn, ~p"/users/change_password", %{ "action" => "update_password", "user" => %{ "current_password" => valid_user_password(), @@ -32,7 +32,7 @@ defmodule AtomicWeb.UserSettingsControllerTest do } }) - assert redirected_to(new_password_conn) == Routes.user_change_password_path(conn, :edit) + assert redirected_to(new_password_conn) == ~p"/users/change_password" assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token) assert Phoenix.Flash.get(new_password_conn.assigns.flash, :info) =~ @@ -43,7 +43,7 @@ defmodule AtomicWeb.UserSettingsControllerTest do test "does not update password on invalid data", %{conn: conn} do old_password_conn = - put(conn, Routes.user_change_password_path(conn, :update), %{ + put(conn, ~p"/users/change_password", %{ "action" => "update_password", "user" => %{ "current_password" => "invalid", diff --git a/test/atomic_web/controllers/user_confirmation_controller_test.exs b/test/atomic_web/controllers/user_confirmation_controller_test.exs index b8ca01f15..120811301 100644 --- a/test/atomic_web/controllers/user_confirmation_controller_test.exs +++ b/test/atomic_web/controllers/user_confirmation_controller_test.exs @@ -11,7 +11,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do describe "GET /users/confirm" do test "renders the resend confirmation page", %{conn: conn} do - conn = get(conn, Routes.user_confirmation_path(conn, :new)) + conn = get(conn, ~p"/users/confirm") response = html_response(conn, 200) assert response =~ "

              Resend confirmation instructions

              " end @@ -21,7 +21,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do @tag :capture_log test "sends a new confirmation token", %{conn: conn, user: user} do conn = - post(conn, Routes.user_confirmation_path(conn, :create), %{ + post(conn, ~p"/users/confirm", %{ "user" => %{"email" => user.email} }) @@ -34,7 +34,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do Repo.update!(Accounts.User.confirm_changeset(user)) conn = - post(conn, Routes.user_confirmation_path(conn, :create), %{ + post(conn, ~p"/users/confirm", %{ "user" => %{"email" => user.email} }) @@ -45,7 +45,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do test "does not send confirmation token if email is invalid", %{conn: conn} do conn = - post(conn, Routes.user_confirmation_path(conn, :create), %{ + post(conn, ~p"/users/confirm", %{ "user" => %{"email" => "unknown@example.com"} }) @@ -62,7 +62,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do Accounts.deliver_user_confirmation_instructions(user, url) end) - conn = get(conn, Routes.user_confirmation_path(conn, :edit, token)) + conn = get(conn, ~p"/users/confirm/#{token}") assert redirected_to(conn) == "/users/log_in" assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "User confirmed successfully" assert Accounts.get_user!(user.id).confirmed_at @@ -70,7 +70,7 @@ defmodule AtomicWeb.UserConfirmationControllerTest do assert Repo.all(Accounts.UserToken) == [] # When not logged in - conn = get(conn, Routes.user_confirmation_path(conn, :edit, token)) + conn = get(conn, ~p"/users/confirm/#{token}") assert redirected_to(conn) == "/users/log_in" assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ @@ -80,14 +80,14 @@ defmodule AtomicWeb.UserConfirmationControllerTest do conn = build_conn() |> log_in_user(user) - |> get(Routes.user_confirmation_path(conn, :edit, token)) + |> get(~p"/users/confirm/#{token}") assert redirected_to(conn) == "/" refute Phoenix.Flash.get(conn.assigns.flash, :error) end test "does not confirm email with invalid token", %{conn: conn, user: user} do - conn = get(conn, Routes.user_confirmation_path(conn, :edit, "oops")) + conn = get(conn, ~p"/users/confirm/oops") assert redirected_to(conn) == "/users/log_in" assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ diff --git a/test/atomic_web/controllers/user_registration_controller_test.exs b/test/atomic_web/controllers/user_registration_controller_test.exs index 8a89dd164..a45e290d5 100644 --- a/test/atomic_web/controllers/user_registration_controller_test.exs +++ b/test/atomic_web/controllers/user_registration_controller_test.exs @@ -3,7 +3,7 @@ defmodule AtomicWeb.UserRegistrationControllerTest do describe "GET /users/register" do test "renders registration page", %{conn: conn} do - conn = get(conn, Routes.user_registration_path(conn, :new)) + conn = get(conn, ~p"/users/register") response = html_response(conn, 200) assert response =~ "Register" assert response =~ "Login" @@ -11,7 +11,7 @@ defmodule AtomicWeb.UserRegistrationControllerTest do end test "redirects if already logged in", %{conn: conn} do - conn = conn |> log_in_user(insert(:user)) |> get(Routes.user_registration_path(conn, :new)) + conn = conn |> log_in_user(insert(:user)) |> get(~p"/users/register") assert redirected_to(conn) == "/" end end @@ -27,7 +27,7 @@ defmodule AtomicWeb.UserRegistrationControllerTest do } conn = - post(conn, Routes.user_registration_path(conn, :create), %{ + post(conn, ~p"/users/register", %{ "user" => user_attrs }) diff --git a/test/atomic_web/controllers/user_reset_password_controller_test.exs b/test/atomic_web/controllers/user_reset_password_controller_test.exs index e7cb85804..5f8cc13d1 100644 --- a/test/atomic_web/controllers/user_reset_password_controller_test.exs +++ b/test/atomic_web/controllers/user_reset_password_controller_test.exs @@ -11,7 +11,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do describe "GET /users/reset_password" do test "renders the reset password page", %{conn: conn} do - conn = get(conn, Routes.user_reset_password_path(conn, :new)) + conn = get(conn, ~p"/users/reset_password") response = html_response(conn, 200) assert response =~ "Recover Account" end @@ -21,7 +21,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do @tag :capture_log test "sends a new reset password token given a valid email", %{conn: conn, user: user} do conn = - post(conn, Routes.user_reset_password_path(conn, :create), %{ + post(conn, ~p"/users/reset_password", %{ "user" => %{"input" => user.email} }) @@ -32,7 +32,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do end test "does not send reset password token if email is invalid", %{conn: conn} do - post(conn, Routes.user_reset_password_path(conn, :create), %{ + post(conn, ~p"/users/reset_password", %{ "user" => %{"input" => "unknown@example.com"} }) @@ -41,7 +41,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do test "sends a new reset password token given a valid slug", %{conn: conn, user: user} do conn = - post(conn, Routes.user_reset_password_path(conn, :create), %{ + post(conn, ~p"/users/reset_password", %{ "user" => %{"input" => user.slug} }) @@ -52,7 +52,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do end test "does not send reset password token if slug is invalid", %{conn: conn} do - post(conn, Routes.user_reset_password_path(conn, :create), %{ + post(conn, ~p"/users/reset_password", %{ "user" => %{"input" => "unknown"} }) @@ -71,7 +71,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do end test "renders reset password", %{conn: conn, token: token} do - conn = get(conn, Routes.user_reset_password_path(conn, :edit, token)) + conn = get(conn, ~p"/users/reset_password/#{token}") assert html_response(conn, 200) =~ "Reset Password" end end @@ -88,14 +88,14 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do test "resets password once", %{conn: conn, user: user, token: token} do conn = - put(conn, Routes.user_reset_password_path(conn, :update, token), %{ + put(conn, ~p"/users/reset_password/#{token}", %{ "user" => %{ "password" => "new valid password", "password_confirmation" => "new valid password" } }) - assert redirected_to(conn) == Routes.user_session_path(conn, :new) + assert redirected_to(conn) == ~p"/users/log_in" refute get_session(conn, :user_token) assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Password changed successfully" assert Accounts.get_user_by_email_and_password(user.email, "new valid password") @@ -103,7 +103,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do test "does not reset password on invalid data", %{conn: conn, token: token} do conn = - put(conn, Routes.user_reset_password_path(conn, :update, token), %{ + put(conn, ~p"/users/reset_password/#{token}", %{ "user" => %{ "password" => "too short", "password_confirmation" => "does not match" diff --git a/test/atomic_web/controllers/user_session_controller_test.exs b/test/atomic_web/controllers/user_session_controller_test.exs index 453635d0d..ebf5a5be8 100644 --- a/test/atomic_web/controllers/user_session_controller_test.exs +++ b/test/atomic_web/controllers/user_session_controller_test.exs @@ -9,7 +9,7 @@ defmodule AtomicWeb.UserSessionControllerTest do describe "GET /users/log_in" do test "renders log in page", %{conn: conn} do - conn = get(conn, Routes.user_session_path(conn, :new)) + conn = get(conn, ~p"/users/log_in") response = html_response(conn, 200) assert response =~ "Log" @@ -18,7 +18,7 @@ defmodule AtomicWeb.UserSessionControllerTest do end test "redirects if already logged in", %{conn: conn, user: user} do - conn = conn |> log_in_user(user) |> get(Routes.user_session_path(conn, :new)) + conn = conn |> log_in_user(user) |> get(~p"/users/log_in") assert redirected_to(conn) == "/" end end @@ -26,7 +26,7 @@ defmodule AtomicWeb.UserSessionControllerTest do describe "POST /users/log_in" do test "logs the user in", %{conn: conn, user: user} do conn = - post(conn, Routes.user_session_path(conn, :create), %{ + post(conn, ~p"/users/log_in", %{ "user" => %{"email" => user.email, "password" => valid_user_password()} }) @@ -41,7 +41,7 @@ defmodule AtomicWeb.UserSessionControllerTest do test "logs the user in with remember me", %{conn: conn, user: user} do conn = - post(conn, Routes.user_session_path(conn, :create), %{ + post(conn, ~p"/users/log_in", %{ "user" => %{ "email" => user.email, "password" => valid_user_password(), @@ -57,7 +57,7 @@ defmodule AtomicWeb.UserSessionControllerTest do conn = conn |> init_test_session(user_return_to: "/foo/bar") - |> post(Routes.user_session_path(conn, :create), %{ + |> post(~p"/users/log_in", %{ "user" => %{ "email" => user.email, "password" => valid_user_password() @@ -69,7 +69,7 @@ defmodule AtomicWeb.UserSessionControllerTest do test "emits error message with invalid credentials", %{conn: conn, user: user} do conn = - post(conn, Routes.user_session_path(conn, :create), %{ + post(conn, ~p"/users/log_in", %{ "user" => %{"email" => user.email, "password" => "invalid_password"} }) @@ -82,14 +82,14 @@ defmodule AtomicWeb.UserSessionControllerTest do describe "DELETE /users/log_out" do test "logs the user out", %{conn: conn, user: user} do - conn = conn |> log_in_user(user) |> delete(Routes.user_session_path(conn, :delete)) + conn = conn |> log_in_user(user) |> delete(~p"/users/log_out") assert redirected_to(conn) == "/users/log_in" refute get_session(conn, :user_token) assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully" end test "succeeds even if the user is not logged in", %{conn: conn} do - conn = delete(conn, Routes.user_session_path(conn, :delete)) + conn = delete(conn, ~p"/users/log_out") assert redirected_to(conn) == "/users/log_in" refute get_session(conn, :user_token) end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 67463acc2..db69e95d8 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -21,16 +21,16 @@ defmodule AtomicWeb.ConnCase do using do quote do + # The default endpoint for testing + @endpoint AtomicWeb.Endpoint + + use AtomicWeb, :verified_routes + # Import conveniences for testing with connections import Plug.Conn import Phoenix.ConnTest import AtomicWeb.ConnCase import Atomic.Factory - - alias AtomicWeb.Router.Helpers, as: Routes - - # The default endpoint for testing - @endpoint AtomicWeb.Endpoint end end From a1cf7aefec7ef68feec24bf1ae4b71b721a626dd Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 23 Sep 2024 19:40:39 +0100 Subject: [PATCH 2/2] [no ci] fix: linter --- lib/atomic_web/config.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atomic_web/config.ex b/lib/atomic_web/config.ex index fa7af886a..03f60860a 100644 --- a/lib/atomic_web/config.ex +++ b/lib/atomic_web/config.ex @@ -20,7 +20,7 @@ defmodule AtomicWeb.Config do end end - def user_pages() do + def user_pages do default_pages() ++ [ %{ @@ -60,7 +60,7 @@ defmodule AtomicWeb.Config do ] end - def default_pages() do + def default_pages do [ %{ key: :home,