From b315e1d7ff32d5745e86557cc7773f63fddcd97e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 1 Dec 2023 09:49:54 +0100 Subject: [PATCH 1/6] refactor: use Phoenix verified routes Signed-off-by: Thomas Citharel --- .sobelow-skips | 6 +- lib/federation/web_finger/web_finger.ex | 4 +- .../mobilizon/maintenance/detect_spam.ex | 7 +-- lib/mobilizon/actors/actor.ex | 3 +- lib/mobilizon/discussions/comment.ex | 5 +- lib/mobilizon/discussions/discussion.ex | 5 +- lib/mobilizon/events/event.ex | 5 +- lib/mobilizon/posts/post.ex | 5 +- lib/service/activity/renderer/comment.ex | 9 +-- lib/service/activity/renderer/conversation.ex | 9 +-- lib/service/activity/renderer/discussion.ex | 11 +--- lib/service/activity/renderer/event.ex | 10 +--- lib/service/activity/renderer/group.ex | 7 +-- lib/service/activity/renderer/member.ex | 10 +--- lib/service/activity/renderer/post.ex | 10 +--- lib/service/activity/renderer/resource.ex | 7 +-- lib/service/auth/applications.ex | 5 +- lib/service/export/feed.ex | 9 +-- lib/service/metadata/actor.ex | 22 ++----- lib/service/metadata/event.ex | 9 +-- lib/service/metadata/instance.ex | 6 +- lib/service/metadata/post.ex | 10 +--- lib/service/site_map.ex | 4 +- lib/web/cache/activity_pub.ex | 5 +- lib/web/controllers/application_controller.ex | 7 +-- lib/web/controllers/node_info_controller.ex | 5 +- .../activity/_comment_activity_item.html.heex | 16 ++--- .../activity/_comment_activity_item.text.eex | 8 +-- .../_conversation_activity_item.html.heex | 8 +-- .../_conversation_activity_item.text.eex | 4 +- .../_discussion_activity_item.html.heex | 8 +-- .../_discussion_activity_item.text.eex | 8 +-- .../activity/_event_activity_item.html.heex | 20 ++----- .../activity/_event_activity_item.text.eex | 10 ++-- .../activity/_group_activity_item.html.heex | 8 +-- .../activity/_group_activity_item.text.eex | 4 +- .../activity/_post_activity_item.html.heex | 8 +-- .../activity/_post_activity_item.text.eex | 4 +- .../_resource_activity_item.html.heex | 24 ++------ .../activity/_resource_activity_item.text.eex | 12 ++-- ...ymous_participation_confirmation.html.heex | 4 +- ...nymous_participation_confirmation.text.eex | 2 +- .../email/before_event_notification.html.heex | 4 +- .../email/before_event_notification.text.eex | 2 +- .../email/email_anonymous_activity.html.heex | 20 +++---- .../email/email_anonymous_activity.text.eex | 4 +- .../email/email_changed_new.html.heex | 4 +- .../email/email_changed_new.text.eex | 2 +- .../email/email_direct_activity.html.heex | 16 +++-- .../email/email_direct_activity.text.eex | 2 +- .../event_participation_approved.html.heex | 2 +- .../event_participation_approved.text.eex | 2 +- .../event_participation_confirmed.html.heex | 2 +- .../event_participation_confirmed.text.eex | 2 +- .../templates/email/event_updated.html.heex | 2 +- .../templates/email/event_updated.text.eex | 2 +- .../templates/email/group_invite.html.heex | 2 +- lib/web/templates/email/group_invite.text.eex | 2 +- .../email/group_membership_approval.html.heex | 6 +- .../email/group_membership_approval.text.eex | 2 +- .../group_membership_rejection.html.heex | 2 +- .../email/group_membership_rejection.text.eex | 2 +- .../email/notification_each_week.text.eex | 4 +- .../email/on_day_notification.text.eex | 4 +- .../participation/card/_picture.html.heex | 2 +- .../email/participation/card/_title.html.heex | 11 ++-- .../email/participation/card/_title.text.eex | 2 +- .../email/participation/event_card.html.heex | 6 +- .../email/participation/event_card.text.eex | 4 +- ...nding_participation_notification.html.heex | 2 +- ...ending_participation_notification.text.eex | 2 +- lib/web/templates/email/report.html.heex | 2 +- lib/web/templates/email/report.text.eex | 2 +- lib/web/views/email_view.ex | 2 +- lib/web/views/json_ld/object_view.ex | 11 +--- test/federation/activity_pub/utils_test.exs | 2 +- test/service/metadata/metadata_test.exs | 4 +- test/support/factory.ex | 16 ++--- .../activity_pub_controller_test.exs | 18 +++--- .../application_controller_test.exs | 4 +- test/web/controllers/feed_controller_test.exs | 58 +++++-------------- .../controllers/nodeinfo_controller_test.exs | 4 +- test/web/controllers/page_controller_test.exs | 14 ++--- 83 files changed, 227 insertions(+), 372 deletions(-) diff --git a/.sobelow-skips b/.sobelow-skips index 3ce31fbbd..0d409653b 100644 --- a/.sobelow-skips +++ b/.sobelow-skips @@ -1,15 +1,15 @@ 155A1FB53DE39EC8EFCFD7FB94EA823D 1C29EE70E90ECED01AF28EC58D2575B5 +2BB1D36656B423758A470021718FCB09 31CE26BC979C57B9E3CC97B40C290CE5 3529E7A4CECC24D02678820E6F521162 -37E854EA3BDF7275C6A7631F80804EC4 +3644C4E850300482AA409471EFE1EFB3 4E7C044C59E0BCB76AA826789998F624 53CBBEB6243FAF5C37249CBA17DE6F4C 5BCE3651A03711295046DE48BDFE007E -5C16A2AE6A24E4795F95DDE20EEC458E 5C4CED447689F00D9D1ACEB9B895ED29 -630C0972985257251EDF89A7117DE423 +90EB7E986B2A3A0C3851B6BF158ECD73 94ACF7B17C3FF42F64E57DD1DA936BD8 A32E125003F1EDFAD95C487C6A969725 ACF6272A1DBB3A2ABD96C0C120B5CA69 diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index 467e46b57..bc65bec4f 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -14,7 +14,7 @@ defmodule Mobilizon.Federation.WebFinger do alias Mobilizon.Federation.WebFinger.XmlBuilder alias Mobilizon.Service.HTTP.{HostMetaClient, WebfingerClient} alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes require Jason require Logger import SweetXml @@ -85,7 +85,7 @@ defmodule Mobilizon.Federation.WebFinger do %{"rel" => "self", "type" => "application/activity+json", "href" => actor.url}, %{ "rel" => "http://ostatus.org/schema/1.0/subscribe", - "template" => "#{Routes.page_url(Endpoint, :interact, uri: nil)}{uri}" + "template" => "#{url(~p"/interact?#{[uri: nil]}")}{uri}" } ] |> maybe_add_avatar(actor) diff --git a/lib/mix/tasks/mobilizon/maintenance/detect_spam.ex b/lib/mix/tasks/mobilizon/maintenance/detect_spam.ex index 1af1902aa..80ab1d6c6 100644 --- a/lib/mix/tasks/mobilizon/maintenance/detect_spam.ex +++ b/lib/mix/tasks/mobilizon/maintenance/detect_spam.ex @@ -9,8 +9,7 @@ defmodule Mix.Tasks.Mobilizon.Maintenance.DetectSpam do alias Mobilizon.Service.AntiSpam import Mix.Tasks.Mobilizon.Common alias Mobilizon.Federation.ActivityPub.Actions - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @shortdoc "Scan all profiles and events against spam detector and report them" @@ -163,9 +162,7 @@ defmodule Mix.Tasks.Mobilizon.Maintenance.DetectSpam do end defp handle_spam_event(event_id, event_title, event_uuid, organizer_actor_id, options) do - shell_info( - "Detected event #{event_title} as spam: #{Routes.page_url(Endpoint, :event, event_uuid)}" - ) + shell_info("Detected event #{event_title} as spam: #{url(~p"/events/#{event_uuid}")}") unless dry_run?(options) do report_spam_event(event_id, event_title, organizer_actor_id, options) diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 3d5cedc8a..14432ec1a 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -19,6 +19,7 @@ defmodule Mobilizon.Actors.Actor do alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 2] import Mobilizon.Service.Guards, only: [is_valid_string: 1] @@ -445,7 +446,7 @@ defmodule Mobilizon.Actors.Actor do # Relay has a special URI def build_url("relay", :page, _args), - do: Endpoint |> Routes.activity_pub_url(:relay) |> URI.decode() + do: ~p"/relay" |> url() |> URI.decode() def build_url(preferred_username, endpoint, args) when endpoint in [:page, :resources, :posts, :discussions, :events, :todos] do diff --git a/lib/mobilizon/discussions/comment.ex b/lib/mobilizon/discussions/comment.ex index 151f45218..77c5817b5 100644 --- a/lib/mobilizon/discussions/comment.ex +++ b/lib/mobilizon/discussions/comment.ex @@ -15,8 +15,7 @@ defmodule Mobilizon.Discussions.Comment do alias Mobilizon.Medias.Media alias Mobilizon.Mention - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @type t :: %__MODULE__{ text: String.t(), @@ -160,7 +159,7 @@ defmodule Mobilizon.Discussions.Comment do end @spec generate_url(String.t()) :: String.t() - defp generate_url(uuid), do: Routes.page_url(Endpoint, :comment, uuid) + defp generate_url(uuid), do: url(~p"/comments/#{uuid}") @spec put_tags(Ecto.Changeset.t(), map) :: Ecto.Changeset.t() defp put_tags(changeset, %{"tags" => tags}), diff --git a/lib/mobilizon/discussions/discussion.ex b/lib/mobilizon/discussions/discussion.ex index 5d5f513e8..b2ba6a597 100644 --- a/lib/mobilizon/discussions/discussion.ex +++ b/lib/mobilizon/discussions/discussion.ex @@ -27,8 +27,7 @@ defmodule Mobilizon.Discussions.Discussion do alias Mobilizon.Actors.Actor alias Mobilizon.Discussions.Comment alias Mobilizon.Discussions.Discussion.TitleSlug - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 2] @type t :: %__MODULE__{ @@ -101,5 +100,5 @@ defmodule Mobilizon.Discussions.Discussion do @spec generate_url(String.t(), String.t()) :: String.t() defp generate_url(preferred_username, slug), - do: Routes.page_url(Endpoint, :discussion, preferred_username, slug) + do: url(~p"/@:#{preferred_username}/c/#{slug}") end diff --git a/lib/mobilizon/events/event.ex b/lib/mobilizon/events/event.ex index 9a1692e35..ff76568ae 100644 --- a/lib/mobilizon/events/event.ex +++ b/lib/mobilizon/events/event.ex @@ -32,8 +32,7 @@ defmodule Mobilizon.Events.Event do alias Mobilizon.Medias.Media alias Mobilizon.Storage.Repo - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @type t :: %__MODULE__{ id: integer(), @@ -140,7 +139,7 @@ defmodule Mobilizon.Events.Event do @spec changeset(t | Ecto.Schema.t(), map) :: Changeset.t() def changeset(%__MODULE__{} = event, attrs) do attrs = Map.update(attrs, :uuid, Ecto.UUID.generate(), &(&1 || Ecto.UUID.generate())) - attrs = Map.update(attrs, :url, Routes.page_url(Endpoint, :event, attrs.uuid), & &1) + attrs = Map.update(attrs, :url, url(~p"/events/#{attrs.uuid}"), & &1) event |> cast(attrs, @attrs) diff --git a/lib/mobilizon/posts/post.ex b/lib/mobilizon/posts/post.ex index 870b438d5..a6d9d9bf7 100644 --- a/lib/mobilizon/posts/post.ex +++ b/lib/mobilizon/posts/post.ex @@ -27,8 +27,7 @@ defmodule Mobilizon.Posts.Post do alias Mobilizon.Medias.Media alias Mobilizon.Posts.Post.TitleSlug alias Mobilizon.Posts.PostVisibility - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext @type t :: %__MODULE__{ @@ -128,7 +127,7 @@ defmodule Mobilizon.Posts.Post do @spec generate_url(String.t()) :: String.t() defp generate_url(id_and_slug) when is_binary(id_and_slug), - do: Routes.page_url(Endpoint, :post, id_and_slug) + do: url(~p"/p/#{id_and_slug}") defp generate_url(_), do: nil diff --git a/lib/service/activity/renderer/comment.ex b/lib/service/activity/renderer/comment.ex index c7551c6d2..fe77ebcad 100644 --- a/lib/service/activity/renderer/comment.ex +++ b/lib/service/activity/renderer/comment.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Comment do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -78,11 +77,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Comment do end defp event_url(activity) do - Routes.page_url( - Endpoint, - :event, - activity.subject_params["event_uuid"] - ) + url(~p"/events/#{activity.subject_params["event_uuid"]}") end defp event_comment_url(activity) do diff --git a/lib/service/activity/renderer/conversation.ex b/lib/service/activity/renderer/conversation.ex index e2a081188..d0bf1fa1e 100644 --- a/lib/service/activity/renderer/conversation.ex +++ b/lib/service/activity/renderer/conversation.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Conversation do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -61,11 +60,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Conversation do end defp conversation_url(activity) do - Routes.page_url( - Endpoint, - :conversation, - activity.subject_params["conversation_id"] - ) + url(~p"/conversations/#{activity.subject_params["conversation_id"]}") end defp profile(activity), do: Actor.display_name_and_username(activity.author) diff --git a/lib/service/activity/renderer/discussion.ex b/lib/service/activity/renderer/discussion.ex index 224a93763..7dc3aca13 100644 --- a/lib/service/activity/renderer/discussion.ex +++ b/lib/service/activity/renderer/discussion.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Discussion do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -113,12 +112,8 @@ defmodule Mobilizon.Service.Activity.Renderer.Discussion do end defp discussion_url(activity) do - Endpoint - |> Routes.page_url( - :discussion, - Actor.preferred_username_and_domain(activity.group), - activity.subject_params["discussion_slug"] - ) + ~p"/@#{Actor.preferred_username_and_domain(activity.group)}/c/#{activity.subject_params["discussion_slug"]}" + |> url() |> URI.decode() end diff --git a/lib/service/activity/renderer/event.ex b/lib/service/activity/renderer/event.ex index 3bf07232f..f06770146 100644 --- a/lib/service/activity/renderer/event.ex +++ b/lib/service/activity/renderer/event.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Event do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -81,11 +80,8 @@ defmodule Mobilizon.Service.Activity.Renderer.Event do end defp event_url(activity) do - Endpoint - |> Routes.page_url( - :event, - activity.subject_params["event_uuid"] - ) + ~p"/events/#{activity.subject_params["event_uuid"]}" + |> url() |> URI.decode() end diff --git a/lib/service/activity/renderer/group.ex b/lib/service/activity/renderer/group.ex index a9df9d826..ca3216c67 100644 --- a/lib/service/activity/renderer/group.ex +++ b/lib/service/activity/renderer/group.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Group do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -30,8 +29,8 @@ defmodule Mobilizon.Service.Activity.Renderer.Group do end defp group_url(activity) do - Endpoint - |> Routes.page_url(:actor, Actor.preferred_username_and_domain(activity.group)) + ~p"/@#{Actor.preferred_username_and_domain(activity.group)}" + |> url() |> URI.decode() end diff --git a/lib/service/activity/renderer/member.ex b/lib/service/activity/renderer/member.ex index 47509b532..f1da19aa1 100644 --- a/lib/service/activity/renderer/member.ex +++ b/lib/service/activity/renderer/member.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -81,12 +80,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Member do defp member_url(activity) do group_url = - Endpoint - |> Routes.page_url( - :actor, - Actor.preferred_username_and_domain(activity.group) - ) - |> URI.decode() + ~p"/@#{Actor.preferred_username_and_domain(activity.group)}" |> url() |> URI.decode() "#{group_url}/settings/members" end diff --git a/lib/service/activity/renderer/post.ex b/lib/service/activity/renderer/post.ex index 1491e58e8..1706217de 100644 --- a/lib/service/activity/renderer/post.ex +++ b/lib/service/activity/renderer/post.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Post do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -52,12 +51,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Post do end defp post_url(activity) do - Endpoint - |> Routes.page_url( - :post, - activity.subject_params["post_slug"] - ) - |> URI.decode() + URI.decode(~p"/p/#{activity.subject_params["post_slug"]}") end defp profile(activity), do: Actor.display_name_and_username(activity.author) diff --git a/lib/service/activity/renderer/resource.ex b/lib/service/activity/renderer/resource.ex index 4ad175048..7820872f4 100644 --- a/lib/service/activity/renderer/resource.ex +++ b/lib/service/activity/renderer/resource.ex @@ -5,8 +5,7 @@ defmodule Mobilizon.Service.Activity.Renderer.Resource do alias Mobilizon.Activities.Activity alias Mobilizon.Actors.Actor alias Mobilizon.Service.Activity.Renderer - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext, only: [dgettext: 3] @behaviour Renderer @@ -73,8 +72,8 @@ defmodule Mobilizon.Service.Activity.Renderer.Resource do end defp resource_url(activity) do - Endpoint - |> Routes.page_url(:resource, activity.subject_params["resource_uuid"]) + ~p"/resource/#{activity.subject_params["resource_uuid"]}" + |> url() |> URI.decode() end diff --git a/lib/service/auth/applications.ex b/lib/service/auth/applications.ex index 04b8d3cca..44770ff37 100644 --- a/lib/service/auth/applications.ex +++ b/lib/service/auth/applications.ex @@ -8,7 +8,7 @@ defmodule Mobilizon.Service.Auth.Applications do alias Mobilizon.Service.Auth.Authenticator alias Mobilizon.Users.User alias Mobilizon.Web.Auth.Guardian - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes require Logger @app_access_tokens_ttl {8, :hour} @@ -260,8 +260,7 @@ defmodule Mobilizon.Service.Auth.Applications do with {:app, %Application{scope: app_scope} = application} <- {:app, Applications.get_application_by_client_id(client_id)}, {device_code, user_code, verification_uri} <- - {string_of_length(40), string_of_length(8), - Routes.page_url(Mobilizon.Web.Endpoint, :auth_device)}, + {string_of_length(40), string_of_length(8), url(~p"/login/device")}, {:scope_included, true} <- {:scope_included, request_scope_valid?(app_scope, scope)}, {:ok, %ApplicationDeviceActivation{} = application_device_activation} <- Applications.create_application_device_activation(%{ diff --git a/lib/service/export/feed.ex b/lib/service/export/feed.ex index 96f5644af..80ec7dcb4 100644 --- a/lib/service/export/feed.ex +++ b/lib/service/export/feed.ex @@ -15,7 +15,7 @@ defmodule Mobilizon.Service.Export.Feed do alias Mobilizon.Users.User alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes require Logger @@ -104,10 +104,7 @@ defmodule Mobilizon.Service.Export.Feed do defp build_actor_feed(%Actor{} = actor, events, posts, public \\ true) do display_name = Actor.display_name(actor) - self_url = - Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "atom") - |> URI.decode() + self_url = ~p"/@#{actor.preferred_username}/feed/atom" |> url() |> URI.decode() title = if public, @@ -215,7 +212,7 @@ defmodule Mobilizon.Service.Export.Feed do # Build an atom feed from actor and its public events @spec build_user_feed(list(Event.t()), User.t(), String.t()) :: String.t() defp build_user_feed(events, %User{email: email}, token) do - self_url = Endpoint |> Routes.feed_url(:going, token, "atom") |> URI.decode() + self_url = ~p"/events/going/#{token}/format" |> url() |> URI.decode() # Title uses default instance language self_url diff --git a/lib/service/metadata/actor.ex b/lib/service/metadata/actor.ex index e4174c45b..a8f801d13 100644 --- a/lib/service/metadata/actor.ex +++ b/lib/service/metadata/actor.ex @@ -2,9 +2,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do alias Phoenix.HTML alias Phoenix.HTML.Tag alias Mobilizon.Actors.Actor - alias Mobilizon.Web.Endpoint alias Mobilizon.Web.JsonLD.ObjectView - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, default_description: 1, escape_text: 1] @@ -25,13 +24,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do Tag.tag(:meta, property: "og:title", content: actor_display_name_escaped(group)), Tag.tag(:meta, property: "og:url", - content: - Endpoint - |> Routes.page_url( - :actor, - Actor.preferred_username_and_domain(group) - ) - |> URI.decode() + content: ~p"/@#{Actor.preferred_username_and_domain(group)}" |> url() |> URI.decode() ), Tag.tag(:meta, property: "og:description", content: group.summary), Tag.tag(:meta, property: "og:type", content: "profile"), @@ -91,20 +84,13 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Actors.Actor do rel: "alternate", type: "application/atom+xml", title: gettext("%{name}'s feed", name: actor_display_name_escaped(group)) |> HTML.raw(), - href: - Routes.feed_url(Endpoint, :actor, Actor.preferred_username_and_domain(group), :atom) + href: url(~p"/@#{Actor.preferred_username_and_domain(group)}/feed/atom") ), Tag.tag(:link, rel: "alternate", type: "text/calendar", title: gettext("%{name}'s feed", name: actor_display_name_escaped(group)) |> HTML.raw(), - href: - Routes.feed_url( - Endpoint, - :actor, - Actor.preferred_username_and_domain(group), - :ics - ) + href: url(~p"/@#{Actor.preferred_username_and_domain(group)}/feed/ics") ), Tag.tag(:link, rel: "alternate", diff --git a/lib/service/metadata/event.ex b/lib/service/metadata/event.ex index 29b5a8059..e311c66b7 100644 --- a/lib/service/metadata/event.ex +++ b/lib/service/metadata/event.ex @@ -6,7 +6,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do alias Mobilizon.Events.{Event, EventOptions} alias Mobilizon.Web.Endpoint alias Mobilizon.Web.JsonLD.ObjectView - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Service.Metadata.Utils, only: [ @@ -56,11 +56,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do "position" => 1, "name" => event.attributed_to |> Actor.display_name() |> escape_text(), "item" => - Endpoint - |> Routes.page_url( - :actor, - Actor.preferred_username_and_domain(event.attributed_to) - ) + ~p"/@#{Actor.preferred_username_and_domain(event.attributed_to)}" + |> url() |> URI.decode() }, %{ diff --git a/lib/service/metadata/instance.ex b/lib/service/metadata/instance.ex index 953453ebe..8bbc5db93 100644 --- a/lib/service/metadata/instance.ex +++ b/lib/service/metadata/instance.ex @@ -9,7 +9,7 @@ defmodule Mobilizon.Service.Metadata.Instance do alias Mobilizon.Config alias Mobilizon.Service.Metadata.Utils alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext @doc """ @@ -58,13 +58,13 @@ defmodule Mobilizon.Service.Metadata.Instance do rel: "alternate", type: "application/atom+xml", title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(), - href: Routes.feed_url(Endpoint, :instance, :atom) + href: url(~p"/feed/instance/atom") ), Tag.tag(:link, rel: "alternate", type: "text/calendar", title: gettext("%{name}'s feed", name: Config.instance_name()) |> HTML.raw(), - href: Routes.feed_url(Endpoint, :instance, :ics) + href: url(~p"/feed/instance/ics") ) ] end diff --git a/lib/service/metadata/post.ex b/lib/service/metadata/post.ex index 90daf3dc3..9ff64f9a4 100644 --- a/lib/service/metadata/post.ex +++ b/lib/service/metadata/post.ex @@ -4,9 +4,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Posts.Post do alias Mobilizon.Actors.Actor alias Mobilizon.Medias.{File, Media} alias Mobilizon.Posts.Post - alias Mobilizon.Web.Endpoint + use Mobilizon.Web, :verified_routes alias Mobilizon.Web.JsonLD.ObjectView - alias Mobilizon.Web.Router.Helpers, as: Routes import Mobilizon.Service.Metadata.Utils, only: [process_description: 2, strip_tags: 1, escape_text: 1] @@ -35,11 +34,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Posts.Post do "position" => 1, "name" => post.attributed_to |> Actor.display_name() |> escape_text, "item" => - Endpoint - |> Routes.page_url( - :actor, - Actor.preferred_username_and_domain(post.attributed_to) - ) + ~p"/@#{Actor.preferred_username_and_domain(post.attributed_to)}" + |> url() |> URI.decode() }, %{ diff --git a/lib/service/site_map.ex b/lib/service/site_map.ex index 9db246442..24609d7ba 100644 --- a/lib/service/site_map.ex +++ b/lib/service/site_map.ex @@ -6,14 +6,14 @@ defmodule Mobilizon.Service.SiteMap do alias Mobilizon.{Actors, Events, Posts} alias Mobilizon.Storage.Repo alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @default_static_frequency :monthly @spec generate_sitemap :: {:ok, :ok} def generate_sitemap do static_routes = [ - {Routes.page_url(Endpoint, :index, []), :daily}, + {url(~p"/*path"), :daily}, "#{Endpoint.url()}/search", "#{Endpoint.url()}/about/instance", "#{Endpoint.url()}/terms", diff --git a/lib/web/cache/activity_pub.ex b/lib/web/cache/activity_pub.ex index 9b05cb650..7e2130682 100644 --- a/lib/web/cache/activity_pub.ex +++ b/lib/web/cache/activity_pub.ex @@ -13,8 +13,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do alias Mobilizon.Posts.Post alias Mobilizon.Resources.Resource alias Mobilizon.Todos.{Todo, TodoList} - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @cache :activity_pub @@ -73,7 +72,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do {:commit, event} nil -> - with url <- Routes.page_url(Endpoint, :event, uuid), + with url <- url(~p"/events/#{uuid}"), %Tombstone{} = tomstone <- Tombstone.find_tombstone(url) do tomstone else diff --git a/lib/web/controllers/application_controller.ex b/lib/web/controllers/application_controller.ex index a08960f12..02ecd1f06 100644 --- a/lib/web/controllers/application_controller.ex +++ b/lib/web/controllers/application_controller.ex @@ -111,11 +111,8 @@ defmodule Mobilizon.Web.ApplicationController do is_binary(state) and is_binary(scope) do redirect(conn, to: - Routes.page_path(conn, :authorize, - client_id: client_id, - redirect_uri: redirect_uri, - scope: scope, - state: state + url( + ~p"/oauth/authorize?#{[client_id: client_id, redirect_uri: redirect_uri, scope: scope, state: state]}" ) ) else diff --git a/lib/web/controllers/node_info_controller.ex b/lib/web/controllers/node_info_controller.ex index e5165e336..f9a09b7f8 100644 --- a/lib/web/controllers/node_info_controller.ex +++ b/lib/web/controllers/node_info_controller.ex @@ -9,9 +9,6 @@ defmodule Mobilizon.Web.NodeInfoController do alias Mobilizon.Config alias Mobilizon.Service.Statistics - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.Router.Helpers, as: Routes - @node_info_supported_versions ["2.0", "2.1"] @node_info_schema_uri "http://nodeinfo.diaspora.software/ns/schema/" @@ -22,7 +19,7 @@ defmodule Mobilizon.Web.NodeInfoController do |> Enum.map(fn version -> %{ rel: @node_info_schema_uri <> version, - href: Routes.node_info_url(Endpoint, :nodeinfo, version) + href: url(~p"/.well-known/nodeinfo/#{version}") } end) diff --git a/lib/web/templates/email/activity/_comment_activity_item.html.heex b/lib/web/templates/email/activity/_comment_activity_item.html.heex index 8daa72140..169608daf 100644 --- a/lib/web/templates/email/activity/_comment_activity_item.html.heex +++ b/lib/web/templates/email/activity/_comment_activity_item.html.heex @@ -3,9 +3,7 @@ <%= dgettext("activity", "%{profile} mentionned you in a comment under event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -14,9 +12,7 @@ <%= dgettext("activity", "%{profile} has posted an announcement under event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -26,9 +22,7 @@ <%= dgettext("activity", "%{profile} has posted a new reply under your event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}#comment-#{@activity.subject_params["comment_reply_to_uuid"]}-#{@activity.subject_params["comment_uuid"]}\"> + " url() |> URI.decode()}#comment-#{@activity.subject_params["comment_reply_to_uuid"]}-#{@activity.subject_params["comment_uuid"]}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -40,9 +34,7 @@ %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}#comment-#{@activity.subject_params["comment_uuid"]}\"> + " url() |> URI.decode()}#comment-#{@activity.subject_params["comment_uuid"]}\"> #{escape_html(@activity.subject_params["event_title"])} " } diff --git a/lib/web/templates/email/activity/_comment_activity_item.text.eex b/lib/web/templates/email/activity/_comment_activity_item.text.eex index f097b2732..002ffe2c0 100644 --- a/lib/web/templates/email/activity/_comment_activity_item.text.eex +++ b/lib/web/templates/email/activity/_comment_activity_item.text.eex @@ -4,22 +4,22 @@ event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% :participation_event_comment -> %><%= dgettext("activity", "%{profile} has posted an announcement under event %{event}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% :participation_event_comment -> %><%= dgettext("activity", "%{profile} has posted an announcement under event %{event}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% :event_new_comment -> %><%= if @activity.subject_params["comment_reply_to"] do %><%=dgettext("activity", "%{profile} has posted a new reply under your event %{event}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% :event_new_comment -> %><%= if @activity.subject_params["comment_reply_to"] do %><%=dgettext("activity", "%{profile} has posted a new reply under your event %{event}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= "#{Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode()}#comment-#{@activity.subject_params["comment_reply_to_uuid"]}-#{@activity.subject_params["comment_uuid"]}" %><% else %><%= dgettext("activity", "%{profile} has posted a new comment under your event %{event}.", +<%= "#{url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode()}#comment-#{@activity.subject_params["comment_reply_to_uuid"]}-#{@activity.subject_params["comment_uuid"]}" %><% else %><%= dgettext("activity", "%{profile} has posted a new comment under your event %{event}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= "#{Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode()}#comment-#{@activity.subject_params["comment_uuid"]}"%><% end %><% end %> \ No newline at end of file +<%= "#{url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode()}#comment-#{@activity.subject_params["comment_uuid"]}"%><% end %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/activity/_conversation_activity_item.html.heex b/lib/web/templates/email/activity/_conversation_activity_item.html.heex index f59b2140c..8debdd3db 100644 --- a/lib/web/templates/email/activity/_conversation_activity_item.html.heex +++ b/lib/web/templates/email/activity/_conversation_activity_item.html.heex @@ -3,18 +3,14 @@ <%= dgettext("activity", "%{profile} mentionned you in a %{conversation}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", conversation: - " URI.decode()}\">conversation" + " url() |> URI.decode()}\">conversation" }) |> raw %> <% :conversation_replied -> %> <%= dgettext("activity", "%{profile} replied you in a %{conversation}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", conversation: - " URI.decode()}\">conversation" + " url() |> URI.decode()}\">conversation" }) |> raw %> <% end %> diff --git a/lib/web/templates/email/activity/_conversation_activity_item.text.eex b/lib/web/templates/email/activity/_conversation_activity_item.text.eex index 7fe1f8b4d..291c15c9f 100644 --- a/lib/web/templates/email/activity/_conversation_activity_item.text.eex +++ b/lib/web/templates/email/activity/_conversation_activity_item.text.eex @@ -3,9 +3,9 @@ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :conversation, @activity.subject_params["conversation_participant_id"]) |> URI.decode() %><% :conversation_replied -> %><%= dgettext("activity", "%{profile} replied you in a conversation.", +<%= url(~p"/conversations/#{@activity.subject_params["conversation_participant_id"]}") |> URI.decode() %><% :conversation_replied -> %><%= dgettext("activity", "%{profile} replied you in a conversation.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :conversation, @activity.subject_params["conversation_participant_id"]) |> URI.decode() %><% end %> \ No newline at end of file +<%= url(~p"/conversations/#{@activity.subject_params["conversation_participant_id"]}") |> URI.decode() %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/activity/_discussion_activity_item.html.heex b/lib/web/templates/email/activity/_discussion_activity_item.html.heex index e5ba67bc4..ce02312c5 100644 --- a/lib/web/templates/email/activity/_discussion_activity_item.html.heex +++ b/lib/web/templates/email/activity/_discussion_activity_item.html.heex @@ -3,7 +3,7 @@ <%= dgettext("activity", "%{profile} created the discussion %{discussion}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", discussion: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["discussion_title"])}" }) |> raw %> @@ -11,7 +11,7 @@ <%= dgettext("activity", "%{profile} replied to the discussion %{discussion}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", discussion: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["discussion_title"])}" }) |> raw %> @@ -19,7 +19,7 @@ <%= dgettext("activity", "%{profile} renamed the discussion %{discussion}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", discussion: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["discussion_title"])}" }) |> raw %> @@ -27,7 +27,7 @@ <%= dgettext("activity", "%{profile} archived the discussion %{discussion}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", discussion: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["discussion_title"])}" }) |> raw %> diff --git a/lib/web/templates/email/activity/_discussion_activity_item.text.eex b/lib/web/templates/email/activity/_discussion_activity_item.text.eex index 97e676649..a5d56ae22 100644 --- a/lib/web/templates/email/activity/_discussion_activity_item.text.eex +++ b/lib/web/templates/email/activity/_discussion_activity_item.text.eex @@ -4,25 +4,25 @@ discussion: @activity.subject_params["discussion_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :discussion, Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group), @activity.subject_params["discussion_slug"]) |> URI.decode() %><% :discussion_replied -> %><%= dgettext("activity", "%{profile} replied to the discussion %{discussion}.", +<%= ~p"/#{Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group)}/c/#{@activity.subject_params["discussion_slug"]}" |> url() |> URI.decode() %><% :discussion_replied -> %><%= dgettext("activity", "%{profile} replied to the discussion %{discussion}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), discussion: @activity.subject_params["discussion_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :discussion, Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group), @activity.subject_params["discussion_slug"]) |> URI.decode() %><% :discussion_renamed -> %><%= dgettext("activity", "%{profile} renamed the discussion %{discussion}.", +<%= ~p"/#{Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group)}/c/#{@activity.subject_params["discussion_slug"]}" |> url() |> URI.decode() %><% :discussion_renamed -> %><%= dgettext("activity", "%{profile} renamed the discussion %{discussion}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), discussion: @activity.subject_params["discussion_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :discussion, Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group), @activity.subject_params["discussion_slug"]) |> URI.decode() %><% :discussion_archived -> %><%= dgettext("activity", "%{profile} archived the discussion %{discussion}.", +<%= ~p"/#{Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group)}/c/#{@activity.subject_params["discussion_slug"]}" |> url() |> URI.decode() %><% :discussion_archived -> %><%= dgettext("activity", "%{profile} archived the discussion %{discussion}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), discussion: @activity.subject_params["discussion_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :discussion, Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group), @activity.subject_params["discussion_slug"]) |> URI.decode() %><% :discussion_deleted -> %><%= dgettext("activity", "%{profile} deleted the discussion %{discussion}.", +<%= ~p"/#{Mobilizon.Actors.Actor.preferred_username_and_domain(@activity.group)}/c/#{@activity.subject_params["discussion_slug"]}" |> url() |> URI.decode() %><% :discussion_deleted -> %><%= dgettext("activity", "%{profile} deleted the discussion %{discussion}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), discussion: @activity.subject_params["discussion_title"] diff --git a/lib/web/templates/email/activity/_event_activity_item.html.heex b/lib/web/templates/email/activity/_event_activity_item.html.heex index 0497d658d..8d8ba1ae8 100644 --- a/lib/web/templates/email/activity/_event_activity_item.html.heex +++ b/lib/web/templates/email/activity/_event_activity_item.html.heex @@ -3,9 +3,7 @@ <%= dgettext("activity", "The event %{event} was created by %{profile}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -14,9 +12,7 @@ <%= dgettext("activity", "The event %{event} was updated by %{profile}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -32,9 +28,7 @@ <%= dgettext("activity", "%{profile} replied to a comment on the event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -43,9 +37,7 @@ <%= dgettext("activity", "%{profile} posted a comment on the event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " }) @@ -55,9 +47,7 @@ <%= dgettext("activity", "%{profile} joined your event %{event}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", event: - " URI.decode()}\">#{escape_html(@activity.subject_params["event_title"])}" + " url() |> URI.decode()}\">#{escape_html(@activity.subject_params["event_title"])}" }) |> raw %> <% end %> diff --git a/lib/web/templates/email/activity/_event_activity_item.text.eex b/lib/web/templates/email/activity/_event_activity_item.text.eex index 30b05abc0..e5183f0ce 100644 --- a/lib/web/templates/email/activity/_event_activity_item.text.eex +++ b/lib/web/templates/email/activity/_event_activity_item.text.eex @@ -4,13 +4,13 @@ event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% :event_updated -> %><%= dgettext("activity", "The event %{event} was updated by %{profile}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% :event_updated -> %><%= dgettext("activity", "The event %{event} was updated by %{profile}.", %{ profile: display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% :event_deleted -> %><%= dgettext("activity", "The event %{event} was deleted by %{profile}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% :event_deleted -> %><%= dgettext("activity", "The event %{event} was deleted by %{profile}.", %{ profile: display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] @@ -22,16 +22,16 @@ event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} posted a comment on the event %{event}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} posted a comment on the event %{event}.", %{ profile: display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% end %><% :event_new_participation -> %><%= dgettext("activity", "%{profile} joined your event %{event}.", +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% end %><% :event_new_participation -> %><%= dgettext("activity", "%{profile} joined your event %{event}.", %{ profile: display_name_and_username(@activity.author), event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %><% end %> \ No newline at end of file +<%= url(~p"/events/#{@activity.subject_params["event_uuid"]}") |> URI.decode() %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/activity/_group_activity_item.html.heex b/lib/web/templates/email/activity/_group_activity_item.html.heex index 36ad49b16..bfd8b2b6b 100644 --- a/lib/web/templates/email/activity/_group_activity_item.html.heex +++ b/lib/web/templates/email/activity/_group_activity_item.html.heex @@ -3,9 +3,7 @@ <%= dgettext("activity", "%{profile} created the group %{group}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", group: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["group_name"])} " }) @@ -14,9 +12,7 @@ <%= dgettext("activity", "%{profile} updated the group %{group}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", group: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["group_name"])} " }) diff --git a/lib/web/templates/email/activity/_group_activity_item.text.eex b/lib/web/templates/email/activity/_group_activity_item.text.eex index 48308f74b..b414c3bd8 100644 --- a/lib/web/templates/email/activity/_group_activity_item.text.eex +++ b/lib/web/templates/email/activity/_group_activity_item.text.eex @@ -4,10 +4,10 @@ group: @activity.subject_params["group_name"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, @activity.subject_params["group_federated_username"]) |> URI.decode() %><% :group_updated -> %><%= dgettext("activity", "%{profile} updated the group %{group}.", +<%= ~p"/@#{@activity.subject_params["group_federated_username"]}" |> url() |> URI.decode() %><% :group_updated -> %><%= dgettext("activity", "%{profile} updated the group %{group}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), group: @activity.subject_params["group_name"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, @activity.subject_params["group_federated_username"]) |> URI.decode() %><% end %> \ No newline at end of file +<%= ~p"/@#{@activity.subject_params["group_federated_username"]}" |> url() |> URI.decode() %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/activity/_post_activity_item.html.heex b/lib/web/templates/email/activity/_post_activity_item.html.heex index 52c03e781..83a80b1bb 100644 --- a/lib/web/templates/email/activity/_post_activity_item.html.heex +++ b/lib/web/templates/email/activity/_post_activity_item.html.heex @@ -3,9 +3,7 @@ <%= dgettext("activity", "The post %{post} was created by %{profile}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", post: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["post_title"])} " }) @@ -14,9 +12,7 @@ <%= dgettext("activity", "The post %{post} was updated by %{profile}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", post: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["post_title"])} " }) diff --git a/lib/web/templates/email/activity/_post_activity_item.text.eex b/lib/web/templates/email/activity/_post_activity_item.text.eex index ee9c37c9b..8bafea653 100644 --- a/lib/web/templates/email/activity/_post_activity_item.text.eex +++ b/lib/web/templates/email/activity/_post_activity_item.text.eex @@ -4,13 +4,13 @@ post: @activity.subject_params["post_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :post, @activity.subject_params["post_slug"]) |> URI.decode() %><% :post_updated -> %><%= dgettext("activity", "The post %{post} was updated by %{profile}.", +<%= url(~p"/p/#{@activity.subject_params["post_slug"]}") |> URI.decode() %><% :post_updated -> %><%= dgettext("activity", "The post %{post} was updated by %{profile}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), post: @activity.subject_params["post_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :post, @activity.subject_params["post_slug"]) |> URI.decode() %><% :post_deleted -> %><%= dgettext("activity", "The post %{post} was deleted by %{profile}.", +<%= url(~p"/p/#{@activity.subject_params["post_slug"]}") |> URI.decode() %><% :post_deleted -> %><%= dgettext("activity", "The post %{post} was deleted by %{profile}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), post: @activity.subject_params["post_title"] diff --git a/lib/web/templates/email/activity/_resource_activity_item.html.heex b/lib/web/templates/email/activity/_resource_activity_item.html.heex index 67745aed6..b4300eabc 100644 --- a/lib/web/templates/email/activity/_resource_activity_item.html.heex +++ b/lib/web/templates/email/activity/_resource_activity_item.html.heex @@ -4,9 +4,7 @@ <%= dgettext("activity", "%{profile} created the folder %{resource}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} " }) @@ -15,9 +13,7 @@ <%= dgettext("activity", "%{profile} created the resource %{resource}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} " }) @@ -31,9 +27,7 @@ %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} ", old_resource_title: @@ -48,9 +42,7 @@ %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} ", old_resource_title: @@ -64,9 +56,7 @@ <%= dgettext("activity", "%{profile} moved the folder %{resource}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} " }) @@ -75,9 +65,7 @@ <%= dgettext("activity", "%{profile} moved the resource %{resource}.", %{ profile: "#{escaped_display_name_and_username(@activity.author)}", resource: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["resource_title"])} " }) diff --git a/lib/web/templates/email/activity/_resource_activity_item.text.eex b/lib/web/templates/email/activity/_resource_activity_item.text.eex index bd9ded7ab..1a8a59356 100644 --- a/lib/web/templates/email/activity/_resource_activity_item.text.eex +++ b/lib/web/templates/email/activity/_resource_activity_item.text.eex @@ -5,39 +5,39 @@ resource: @activity.subject_params["resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} created the resource %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} created the resource %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% end %><% :resource_renamed -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} renamed the folder from %{old_resource_title} to %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% end %><% :resource_renamed -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} renamed the folder from %{old_resource_title} to %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"], old_resource_title: @activity.subject_params["old_resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} renamed the resource from %{old_resource_title} to %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} renamed the resource from %{old_resource_title} to %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"], old_resource_title: @activity.subject_params["old_resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% end %><% :resource_moved -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} moved the folder %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% end %><% :resource_moved -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} moved the folder %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} moved the resource %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% else %><%= dgettext("activity", "%{profile} moved the resource %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :resource, @activity.subject_params["resource_uuid"]) |> URI.decode() %><% end %><% :resource_deleted -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} deleted the folder %{resource}.", +<%= url(~p"/resource/#{@activity.subject_params["resource_uuid"]}") |> URI.decode() %><% end %><% :resource_deleted -> %><%= if @activity.subject_params["is_folder"] do %><%= dgettext("activity", "%{profile} deleted the folder %{resource}.", %{ profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author), resource: @activity.subject_params["resource_title"] diff --git a/lib/web/templates/email/anonymous_participation_confirmation.html.heex b/lib/web/templates/email/anonymous_participation_confirmation.html.heex index 56c20f57b..fa37af8ff 100644 --- a/lib/web/templates/email/anonymous_participation_confirmation.html.heex +++ b/lib/web/templates/email/anonymous_participation_confirmation.html.heex @@ -63,7 +63,9 @@ url() + |> URI.decode() } target="_blank" style="font-size: 20px; font-family: 'Roboto', Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" diff --git a/lib/web/templates/email/anonymous_participation_confirmation.text.eex b/lib/web/templates/email/anonymous_participation_confirmation.text.eex index ae4943c15..6ed689983 100644 --- a/lib/web/templates/email/anonymous_participation_confirmation.text.eex +++ b/lib/web/templates/email/anonymous_participation_confirmation.text.eex @@ -2,5 +2,5 @@ == <%= gettext "Hi there! You just registered to join this event: « %{title} ». Please confirm the e-mail address you provided:", title: @participant.event.title %> <%= gettext "If you didn't trigger this email, you may safely ignore it." %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :participation_email_confirmation, @participant.metadata.confirmation_token) %> +<%= url(~p"/participation/email/confirm/#{@participant.metadata.confirmation_token}") %> <%= ngettext "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", 1 %> diff --git a/lib/web/templates/email/before_event_notification.html.heex b/lib/web/templates/email/before_event_notification.html.heex index 1013b4c12..fbb22607b 100644 --- a/lib/web/templates/email/before_event_notification.html.heex +++ b/lib/web/templates/email/before_event_notification.html.heex @@ -58,9 +58,7 @@ url() |> URI.decode()} target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" > diff --git a/lib/web/templates/email/before_event_notification.text.eex b/lib/web/templates/email/before_event_notification.text.eex index cb72a7cce..c3fe1ff70 100644 --- a/lib/web/templates/email/before_event_notification.text.eex +++ b/lib/web/templates/email/before_event_notification.text.eex @@ -2,5 +2,5 @@ == <%= gettext "Get ready for %{title}", title: @participant.event.title %> <%= gettext "Go to event page" %> -<%= gettext "View the event on: %{link}", link: Routes.page_url(Mobilizon.Web.Endpoint, :event, @participant.event.uuid) %> +<%= gettext "View the event on: %{link}", link: url(~p"/events/#{@participant.event.uuid}") %> <%= gettext "If you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button." %> diff --git a/lib/web/templates/email/email_anonymous_activity.html.heex b/lib/web/templates/email/email_anonymous_activity.html.heex index c3e45e01d..74bd229e4 100644 --- a/lib/web/templates/email/email_anonymous_activity.html.heex +++ b/lib/web/templates/email/email_anonymous_activity.html.heex @@ -54,9 +54,7 @@ profile: "#{escape_html(display_name_and_username(@activity.author))}", event: - " URI.decode()}\"> + " url() |> URI.decode()}\"> #{escape_html(@activity.subject_params["event_title"])} " } @@ -77,8 +75,10 @@ url() + |> URI.decode() + } target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" > @@ -111,9 +111,7 @@ profile: "#{escape_html(display_name_and_username(@activity.author))}", event: - " URI.decode()}\">#{escape_html(@activity.subject_params["conversation_event_title"])}" + " url() |> URI.decode()}\">#{escape_html(@activity.subject_params["conversation_event_title"])}" } ) |> raw %> @@ -174,8 +172,10 @@ url() + |> URI.decode() + } target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" > diff --git a/lib/web/templates/email/email_anonymous_activity.text.eex b/lib/web/templates/email/email_anonymous_activity.text.eex index 26a5f16f6..9d2e35f0b 100644 --- a/lib/web/templates/email/email_anonymous_activity.text.eex +++ b/lib/web/templates/email/email_anonymous_activity.text.eex @@ -9,7 +9,7 @@ event: @activity.subject_params["event_title"] } ) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %> +<%= ~p"/events/#{@activity.subject_params["event_uuid"]}" |> url() |> URI.decode() %> <% :conversation -> %> <%= dgettext("activity", "%{profile} has posted a private announcement about event %{event}.", %{ @@ -26,5 +26,5 @@ -- <%= dgettext("activity", "This information is sent privately to you as a person who registered for this event. Share the informations above with other people with caution.") %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["conversation_event_uuid"]) |> URI.decode() %> +<%= ~p"/events/#{@activity.subject_params["conversation_event_uuid"]}" |> url() |> URI.decode() %> <% end %> \ No newline at end of file diff --git a/lib/web/templates/email/email_changed_new.html.heex b/lib/web/templates/email/email_changed_new.html.heex index 0baf06d15..42131ceac 100644 --- a/lib/web/templates/email/email_changed_new.html.heex +++ b/lib/web/templates/email/email_changed_new.html.heex @@ -61,9 +61,7 @@ url() |> URI.decode()} target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" > diff --git a/lib/web/templates/email/email_changed_new.text.eex b/lib/web/templates/email/email_changed_new.text.eex index 5b9d7ed9f..68e80ac9c 100644 --- a/lib/web/templates/email/email_changed_new.text.eex +++ b/lib/web/templates/email/email_changed_new.text.eex @@ -1,5 +1,5 @@ <%= gettext "Confirm new email" %> == <%= gettext "Hi there! It seems like you wanted to change the email address linked to your account on %{instance}. If you still wish to do so, please click the button below to confirm the change. You will then be able to log in to %{instance} with this new email address.", %{instance: @instance_name} %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :user_email_validation, @token) %> +<%= url(~p"/validate/email/#{@token}") %> <%= gettext "If you didn't trigger the change yourself, please ignore this message." %> diff --git a/lib/web/templates/email/email_direct_activity.html.heex b/lib/web/templates/email/email_direct_activity.html.heex index 0312449a7..1a3af16ed 100644 --- a/lib/web/templates/email/email_direct_activity.html.heex +++ b/lib/web/templates/email/email_direct_activity.html.heex @@ -94,7 +94,9 @@ URI.decode()}" + ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)}" + |> url() + |> URI.decode() } target="_blank" style="text-decoration: none;" @@ -123,7 +125,9 @@ URI.decode()}" + ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)}" + |> url() + |> URI.decode() } target="_blank" style="text-decoration: none;color: #474467;font-family: 'Roboto', Helvetica, Arial, sans-serif;font-size: 18px;font-weight: bold;line-height: 25px;" @@ -138,7 +142,9 @@ URI.decode()}" + ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)}" + |> url() + |> URI.decode() } target="_blank" style="text-decoration: none;display: block;color: #7a7a7a;font-family: 'Roboto', Helvetica, Arial, sans-serif;font-size: 16px;font-weight: 400;line-height: 25px;" @@ -214,7 +220,9 @@ URI.decode()}/timeline" + ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)}/timeline" + |> url() + |> URI.decode() } target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" diff --git a/lib/web/templates/email/email_direct_activity.text.eex b/lib/web/templates/email/email_direct_activity.text.eex index 7658bba4a..e09918658 100644 --- a/lib/web/templates/email/email_direct_activity.text.eex +++ b/lib/web/templates/email/email_direct_activity.text.eex @@ -21,7 +21,7 @@ <% end %> <%= if length(group_activities) > 5 do %> <%= dngettext "activity", "View one more activity", "View %{count} more activities", length(group_activities) - 5, %{count: length(group_activities) - 5} %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)) |> URI.decode() %>/timeline +<%= ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(hd(group_activities).group)}" |> url() |> URI.decode() %>/timeline <% end %> <% end %> <%= dgettext("activity", "Don't want to receive activity notifications? You may change frequency or disable them in your settings.") %> diff --git a/lib/web/templates/email/event_participation_approved.html.heex b/lib/web/templates/email/event_participation_approved.html.heex index eedd2836c..7018db80d 100644 --- a/lib/web/templates/email/event_participation_approved.html.heex +++ b/lib/web/templates/email/event_participation_approved.html.heex @@ -74,7 +74,7 @@ url() |> URI.decode()} target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" > diff --git a/lib/web/templates/email/event_participation_approved.text.eex b/lib/web/templates/email/event_participation_approved.text.eex index 5b71ca3f1..ff93a0954 100644 --- a/lib/web/templates/email/event_participation_approved.text.eex +++ b/lib/web/templates/email/event_participation_approved.text.eex @@ -6,6 +6,6 @@ <%= gettext "Good news: one of the event organizers just approved your request. Update your calendar, because you're on the guest list now!" %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %> +<%= ~p"/events/#{@event.uuid}" |> url() |> URI.decode() %> <%= gettext "Would you wish to update or cancel your attendance, simply access the event page through the link above and click on the Attending button." %> diff --git a/lib/web/templates/email/event_participation_confirmed.html.heex b/lib/web/templates/email/event_participation_confirmed.html.heex index 8e57958d3..bfb5eec9f 100644 --- a/lib/web/templates/email/event_participation_confirmed.html.heex +++ b/lib/web/templates/email/event_participation_confirmed.html.heex @@ -74,7 +74,7 @@ diff --git a/lib/web/templates/email/event_participation_confirmed.text.eex b/lib/web/templates/email/event_participation_confirmed.text.eex index 56f9edad8..8831a2824 100644 --- a/lib/web/templates/email/event_participation_confirmed.text.eex +++ b/lib/web/templates/email/event_participation_confirmed.text.eex @@ -2,5 +2,5 @@ == <%= gettext "You recently requested to attend %{title}.", title: @event.title %> <%= gettext "You have confirmed your participation. Update your calendar, because you're on the guest list now!" %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %> +<%= url(~p"/events/#{@event.uuid}") %> <%= gettext "Would you wish to update or cancel your attendance, simply access the event page through the link above and click on the Attending button." %> diff --git a/lib/web/templates/email/event_updated.html.heex b/lib/web/templates/email/event_updated.html.heex index 92e53021d..b6af2e869 100644 --- a/lib/web/templates/email/event_updated.html.heex +++ b/lib/web/templates/email/event_updated.html.heex @@ -148,7 +148,7 @@ diff --git a/lib/web/templates/email/event_updated.text.eex b/lib/web/templates/email/event_updated.text.eex index 8ac662667..3d0a67755 100644 --- a/lib/web/templates/email/event_updated.text.eex +++ b/lib/web/templates/email/event_updated.text.eex @@ -9,6 +9,6 @@ <%= gettext "New end date:" %> <%= render("date/event_tz_date.text", event: @event, date: @event.ends_on, timezone: @timezone, locale: @locale) %><% end %><%= if MapSet.member?(@changes, :physical_address) do %> <%= gettext "New location:" %> <%= Mobilizon.Addresses.Address.representation(@event.physical_address) %><% end %> -<%= gettext "Visit the updated event page: %{link}", link: Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %> +<%= gettext "Visit the updated event page: %{link}", link: url(~p"/events/#{@event.uuid}") %> <%= ngettext "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", 1 %> diff --git a/lib/web/templates/email/group_invite.html.heex b/lib/web/templates/email/group_invite.html.heex index 1a34b44e8..1dcd13441 100644 --- a/lib/web/templates/email/group_invite.html.heex +++ b/lib/web/templates/email/group_invite.html.heex @@ -76,7 +76,7 @@ diff --git a/lib/web/templates/email/group_invite.text.eex b/lib/web/templates/email/group_invite.text.eex index 72b03aeb5..0a2fb01f4 100644 --- a/lib/web/templates/email/group_invite.text.eex +++ b/lib/web/templates/email/group_invite.text.eex @@ -3,4 +3,4 @@ <%= gettext "%{inviter} just invited you to join their group %{group}", group: @group.name, inviter: @inviter.name %> <%= @group.url %> <%= gettext "To accept this invitation, head over to your groups." %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :my_groups) %> +<%= url(~p"/groups/me") %> diff --git a/lib/web/templates/email/group_membership_approval.html.heex b/lib/web/templates/email/group_membership_approval.html.heex index acefe2fb1..02992d216 100644 --- a/lib/web/templates/email/group_membership_approval.html.heex +++ b/lib/web/templates/email/group_membership_approval.html.heex @@ -48,7 +48,7 @@ "Your membership request for group %{link_start}%{group}%{link_end} has been approved.", group: escape_html(display_name(@group)), link_start: - " URI.decode()}\">", + " url() |> URI.decode()}\">", link_end: "" ) |> raw %> @@ -66,7 +66,9 @@ URI.decode()}" + ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(@group)}" + |> url() + |> URI.decode() } target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" diff --git a/lib/web/templates/email/group_membership_approval.text.eex b/lib/web/templates/email/group_membership_approval.text.eex index adf657fdf..d3df3ceab 100644 --- a/lib/web/templates/email/group_membership_approval.text.eex +++ b/lib/web/templates/email/group_membership_approval.text.eex @@ -2,4 +2,4 @@ == <%= gettext "Your membership request for group %{group} has been approved.", group: Mobilizon.Actors.Actor.display_name(@group) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, Mobilizon.Actors.Actor.preferred_username_and_domain(@group)) |> URI.decode() %> +<%= ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(@group)}" |> url() |> URI.decode() %> diff --git a/lib/web/templates/email/group_membership_rejection.html.heex b/lib/web/templates/email/group_membership_rejection.html.heex index e4d271200..76dfa0b73 100644 --- a/lib/web/templates/email/group_membership_rejection.html.heex +++ b/lib/web/templates/email/group_membership_rejection.html.heex @@ -48,7 +48,7 @@ "Your membership request for group %{link_start}%{group}%{link_end} has been rejected.", group: escape_html(display_name(@group)), link_start: - " URI.decode()}\">", + " url() |> URI.decode()}\">", link_end: "" ) |> raw %> diff --git a/lib/web/templates/email/group_membership_rejection.text.eex b/lib/web/templates/email/group_membership_rejection.text.eex index 7ecf7c2b7..f8c629d99 100644 --- a/lib/web/templates/email/group_membership_rejection.text.eex +++ b/lib/web/templates/email/group_membership_rejection.text.eex @@ -2,4 +2,4 @@ == <%= gettext "Your membership request for group %{group} has been rejected.", group: Mobilizon.Actors.Actor.display_name(@group) %> -<%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, Mobilizon.Actors.Actor.preferred_username_and_domain(@group)) |> URI.decode() %> +<%= ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(@group)}" |> url() |> URI.decode() %> diff --git a/lib/web/templates/email/notification_each_week.text.eex b/lib/web/templates/email/notification_each_week.text.eex index 2ea9c6df6..86bd5d4cf 100644 --- a/lib/web/templates/email/notification_each_week.text.eex +++ b/lib/web/templates/email/notification_each_week.text.eex @@ -3,9 +3,9 @@ <%= ngettext "You have one event this week:", "You have %{total} events this week:", @total, total: @total %> <%= if @total > 1 do %> <%= for participation <- @participations do %> - - <%= render("date/event_tz_date.text", event: participation.event, date: participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= participation.event.title %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, participation.event.uuid) %> + - <%= render("date/event_tz_date.text", event: participation.event, date: participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= participation.event.title %> <%= url(~p"/events/#{participation.event.uuid}") %> <% end %> <% else %> - <%= render("date/event_tz_date.text", event: @participation.event, date: @participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= @participation.event.title %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @participation.event.uuid) %> + <%= render("date/event_tz_date.text", event: @participation.event, date: @participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= @participation.event.title %> <%= url(~p"/events/#{@participation.event.uuid}") %> <% end %> <%= ngettext "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", @total %> diff --git a/lib/web/templates/email/on_day_notification.text.eex b/lib/web/templates/email/on_day_notification.text.eex index 0747c291f..fe3fabd5e 100644 --- a/lib/web/templates/email/on_day_notification.text.eex +++ b/lib/web/templates/email/on_day_notification.text.eex @@ -3,9 +3,9 @@ <%= ngettext "You have one event today:", "You have %{total} events today:", @total, total: @total %> <%= if @total > 1 do %> <%= for participation <- @participations do %> - - <%= render("date/event_tz_date.text", event: participation.event, date: participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= participation.event.title %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, participation.event.uuid) %> + - <%= render("date/event_tz_date.text", event: participation.event, date: participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= participation.event.title %> <%= url(~p"/events/#{participation.event.uuid}") %> <% end %> <% else %> - <%= render("date/event_tz_date.text", event: @participation.event, date: @participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= @participation.event.title %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @participation.event.uuid) %> + <%= render("date/event_tz_date.text", event: @participation.event, date: @participation.event.begins_on, timezone: @timezone, locale: @locale) %> - <%= @participation.event.title %> <%= url(~p"/events/#{@participation.event.uuid}") %> <% end %> <%= ngettext "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", @total %> diff --git a/lib/web/templates/email/participation/card/_picture.html.heex b/lib/web/templates/email/participation/card/_picture.html.heex index 341ec1313..b1b710121 100644 --- a/lib/web/templates/email/participation/card/_picture.html.heex +++ b/lib/web/templates/email/participation/card/_picture.html.heex @@ -7,7 +7,7 @@ align="left" > diff --git a/lib/web/templates/email/participation/card/_title.html.heex b/lib/web/templates/email/participation/card/_title.html.heex index 3d9f6fe0a..8b202ceb8 100644 --- a/lib/web/templates/email/participation/card/_title.html.heex +++ b/lib/web/templates/email/participation/card/_title.html.heex @@ -7,7 +7,7 @@ align="left" > @@ -35,12 +35,11 @@ <%= if @event.attributed_to do %> URI.decode() } style="color: rgb(254,56,89); font-family: Helvetica,Arial,sans-serif; font-weight: normal; text-align: left; line-height: 1.3; text-decoration: none; vertical-align: baseline; margin: 0; padding: 0; border: 0;" target="_blank" diff --git a/lib/web/templates/email/participation/card/_title.text.eex b/lib/web/templates/email/participation/card/_title.text.eex index 0ffc0a4da..1e9fb06b6 100644 --- a/lib/web/templates/email/participation/card/_title.text.eex +++ b/lib/web/templates/email/participation/card/_title.text.eex @@ -1,3 +1,3 @@ <%= gettext("Title: %{title}", title: @event.title) %> -<%= if @event.attributed_to do %><%= gettext("Organizer: %{organizer}", organizer: @event.attributed_to.name || @event.attributed_to.preferred_username) %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :actor, Mobilizon.Actors.Actor.preferred_username_and_domain(@event.attributed_to)) |> URI.decode() %><% else %><%= gettext("Organizer: %{organizer}", organizer: @event.organizer_actor.name || @event.organizer_actor.preferred_username) %><% end %> \ No newline at end of file +<%= if @event.attributed_to do %><%= gettext("Organizer: %{organizer}", organizer: @event.attributed_to.name || @event.attributed_to.preferred_username) %> <%= ~p"/@#{Mobilizon.Actors.Actor.preferred_username_and_domain(@event.attributed_to)}" |> url() |> URI.decode() %><% else %><%= gettext("Organizer: %{organizer}", organizer: @event.organizer_actor.name || @event.organizer_actor.preferred_username) %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/participation/event_card.html.heex b/lib/web/templates/email/participation/event_card.html.heex index 6bf839613..3724441b4 100644 --- a/lib/web/templates/email/participation/event_card.html.heex +++ b/lib/web/templates/email/participation/event_card.html.heex @@ -40,7 +40,7 @@ align="center" > @@ -84,7 +84,7 @@ align="center" > @@ -125,7 +125,7 @@ align="left" > diff --git a/lib/web/templates/email/participation/event_card.text.eex b/lib/web/templates/email/participation/event_card.text.eex index c50bdf02c..1e1b89354 100644 --- a/lib/web/templates/email/participation/event_card.text.eex +++ b/lib/web/templates/email/participation/event_card.text.eex @@ -2,8 +2,8 @@ <%= render("participation/card/_metadata.text", event: @event, timezone: @timezone, locale: @locale, action: @action) %> -<%= case @action do %><% "participation" -> %><%= gettext("Manage your participation:") %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %><% "event" -> %><%= gettext("Participate:") %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %><% nil -> %><% end %> +<%= case @action do %><% "participation" -> %><%= gettext("Manage your participation:") %> <%= url(~p"/events/#{@event.uuid}") %><% "event" -> %><%= gettext("Participate:") %> <%= url(~p"/events/#{@event.uuid}") %><% nil -> %><% end %> <%= if @event.description do %><%= gettext("Details:") %> <%= process_description(@event.description) %> -<%= if String.length(@event.description) > 200 do %><%= gettext("Read more: %{url}", url: Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid)) %><% end %><% end %> \ No newline at end of file +<%= if String.length(@event.description) > 200 do %><%= gettext("Read more: %{url}", url: url(~p"/events/#{@event.uuid}")) %><% end %><% end %> \ No newline at end of file diff --git a/lib/web/templates/email/pending_participation_notification.html.heex b/lib/web/templates/email/pending_participation_notification.html.heex index d031a7345..fb493f4fd 100644 --- a/lib/web/templates/email/pending_participation_notification.html.heex +++ b/lib/web/templates/email/pending_participation_notification.html.heex @@ -81,7 +81,7 @@ "/participations"}" + "#{url(~p"/events/#{@event.uuid}") <> "/participations"}" } target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" diff --git a/lib/web/templates/email/pending_participation_notification.text.eex b/lib/web/templates/email/pending_participation_notification.text.eex index 961f32d93..69b2d4d51 100644 --- a/lib/web/templates/email/pending_participation_notification.text.eex +++ b/lib/web/templates/email/pending_participation_notification.text.eex @@ -5,6 +5,6 @@ <%= render("participation/event_card.text", event: @event, timezone: @timezone, locale: @locale, action: nil) %> -<%= gettext "Manage pending requests" %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) <> "/participations" %> +<%= gettext "Manage pending requests" %> <%= url(~p"/events/#{@event.uuid}") <> "/participations" %> <%= gettext "You are receiving this email because you chose to get notifications for pending attendance requests to your events. You can disable or change your notification settings in your user account settings under « Notifications »." %>s diff --git a/lib/web/templates/email/report.html.heex b/lib/web/templates/email/report.html.heex index 9dedeeb8c..0a8ad5bbe 100644 --- a/lib/web/templates/email/report.html.heex +++ b/lib/web/templates/email/report.html.heex @@ -227,7 +227,7 @@ <%= @report.content %> <% end %> -<%= gettext "View report:" %> <%= Routes.page_url(Mobilizon.Web.Endpoint, :moderation_report, @report.id) %> +<%= gettext "View report:" %> <%= url(~p"/moderation/report/#{@report.id}") %> diff --git a/lib/web/views/email_view.ex b/lib/web/views/email_view.ex index c24aa87f7..6890b7afe 100644 --- a/lib/web/views/email_view.ex +++ b/lib/web/views/email_view.ex @@ -8,7 +8,7 @@ defmodule Mobilizon.Web.EmailView do alias Mobilizon.Service.Address alias Mobilizon.Service.DateTime, as: DateTimeRenderer alias Mobilizon.Service.Formatter.{HTML, Text} - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes import Mobilizon.Web.Gettext import Mobilizon.Service.Metadata.Utils, only: [process_description: 1] import Phoenix.HTML, only: [raw: 1, html_escape: 1, safe_to_string: 1] diff --git a/lib/web/views/json_ld/object_view.ex b/lib/web/views/json_ld/object_view.ex index 3e61880f6..cf5928b9c 100644 --- a/lib/web/views/json_ld/object_view.ex +++ b/lib/web/views/json_ld/object_view.ex @@ -7,7 +7,6 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do alias Mobilizon.Posts.Post alias Mobilizon.Web.Endpoint alias Mobilizon.Web.JsonLD.ObjectView - alias Mobilizon.Web.Router.Helpers, as: Routes import Mobilizon.Service.Metadata.Utils, only: [process_description: 3] @@ -123,13 +122,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do "author" => %{ "@type" => "Organization", "name" => Actor.display_name(post.attributed_to), - "url" => - Endpoint - |> Routes.page_url( - :actor, - Actor.preferred_username_and_domain(post.attributed_to) - ) - |> URI.decode() + "url" => URI.decode(url(~p"/@#{Actor.preferred_username_and_domain(post.attributed_to)}")) }, "datePublished" => post.publish_at, "dateModified" => post.updated_at, @@ -156,7 +149,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do "reservationFor" => render("event.json", %{event: participant.event}), "reservationStatus" => reservation_status(participant.role), "modifiedTime" => participant.updated_at, - "modifyReservationUrl" => Routes.page_url(Endpoint, :event, participant.event.uuid) + "modifyReservationUrl" => url(~p"/events/#{participant.event.uuid}") } if participant.code do diff --git a/test/federation/activity_pub/utils_test.exs b/test/federation/activity_pub/utils_test.exs index 83f058681..8dc6ef0ff 100644 --- a/test/federation/activity_pub/utils_test.exs +++ b/test/federation/activity_pub/utils_test.exs @@ -29,7 +29,7 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do "content" => "My Comment", "actor" => reply.actor.url, "uuid" => reply.uuid, - "id" => Routes.page_url(Endpoint, :comment, reply.uuid), + "id" => url(~p"/comments/#{reply.uuid}"), "inReplyTo" => comment.url, "attributedTo" => reply.actor.url, "mediaType" => "text/html", diff --git a/test/service/metadata/metadata_test.exs b/test/service/metadata/metadata_test.exs index ef01ea137..a891910c4 100644 --- a/test/service/metadata/metadata_test.exs +++ b/test/service/metadata/metadata_test.exs @@ -18,7 +18,7 @@ defmodule Mobilizon.Service.MetadataTest do assert group |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == String.trim(""" - + """) assert group @@ -26,7 +26,7 @@ defmodule Mobilizon.Service.MetadataTest do |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == String.trim(""" - + """) end diff --git a/test/support/factory.ex b/test/support/factory.ex index dca2e660e..c4a784411 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -9,7 +9,7 @@ defmodule Mobilizon.Factory do alias Mobilizon.Crypto alias Mobilizon.Web.{Endpoint, Upload} - alias Mobilizon.Web.Router.Helpers, as: Routes + use Mobilizon.Web, :verified_routes @spec user_factory :: Mobilizon.Users.User.t() def user_factory do @@ -173,7 +173,7 @@ defmodule Mobilizon.Factory do origin_comment: nil, is_announcement: false, published_at: DateTime.utc_now(), - url: Routes.page_url(Endpoint, :comment, uuid) + url: url(~p"/comments/#{uuid}") } end @@ -199,7 +199,7 @@ defmodule Mobilizon.Factory do metadata: build_list(2, :event_metadata), local: true, publish_at: DateTime.utc_now(), - url: Routes.page_url(Endpoint, :event, uuid), + url: url(~p"/events/#{uuid}"), picture: insert(:media), uuid: uuid, join_options: :free, @@ -344,7 +344,7 @@ defmodule Mobilizon.Factory do title: sequence("todo list"), actor: build(:group), id: uuid, - url: Routes.page_url(Endpoint, :todo_list, uuid), + url: url(~p"/todo-list/#{uuid}"), published_at: DateTime.utc_now() } end @@ -360,7 +360,7 @@ defmodule Mobilizon.Factory do status: false, due_date: Timex.shift(DateTime.utc_now(), hours: 2), assigned_to: build(:actor), - url: Routes.page_url(Endpoint, :todo, uuid), + url: url(~p"/todo/#{uuid}"), creator: build(:actor), published_at: DateTime.utc_now() } @@ -379,7 +379,7 @@ defmodule Mobilizon.Factory do actor: build(:group), creator: build(:actor), parent: nil, - url: Routes.page_url(Endpoint, :resource, uuid), + url: url(~p"/resource/#{uuid}"), published_at: DateTime.utc_now(), path: "/#{title}" } @@ -411,7 +411,7 @@ defmodule Mobilizon.Factory do publish_at: DateTime.utc_now(), picture: insert(:media), media: [], - url: Routes.page_url(Endpoint, :post, uuid) + url: url(~p"/p/#{uuid}") } end @@ -440,7 +440,7 @@ defmodule Mobilizon.Factory do id: uuid, last_comment: nil, comments: [], - url: Routes.page_url(Endpoint, :discussion, group.preferred_username, slug) + url: ~p"/@#{group.preferred_username}/c/#{slug}" } end diff --git a/test/web/controllers/activity_pub_controller_test.exs b/test/web/controllers/activity_pub_controller_test.exs index e9cf2101f..e74bd05aa 100644 --- a/test/web/controllers/activity_pub_controller_test.exs +++ b/test/web/controllers/activity_pub_controller_test.exs @@ -71,7 +71,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn - |> get(Routes.page_url(Endpoint, :event, event.uuid)) + |> get(url(~p"/events/#{event.uuid}")) assert json_response(conn, 200) == PageView.render("event.activity-json", %{conn: %{assigns: %{object: event}}}) @@ -83,7 +83,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.page_url(Endpoint, :event, event.uuid)) + |> get(url(~p"/events/#{event.uuid}")) assert json_response(conn, 404) end @@ -94,7 +94,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.page_url(Endpoint, :event, event.uuid)) + |> get(url(~p"/events/#{event.uuid}")) assert redirected_to(conn) == "https://someremote.url/events/here" end @@ -107,7 +107,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.page_url(Endpoint, :comment, comment.uuid)) + |> get(url(~p"/comments/#{comment.uuid}")) assert json_response(conn, 200) == PageView.render("comment.activity-json", %{conn: %{assigns: %{object: comment}}}) @@ -119,7 +119,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.page_url(Endpoint, :comment, comment.uuid)) + |> get(url(~p"/comments/#{comment.uuid}")) assert redirected_to(conn) == "https://someremote.url/comments/here" end @@ -130,7 +130,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.page_url(Endpoint, :comment, comment.uuid)) + |> get(url(~p"/comments/#{comment.uuid}")) assert json_response(conn, 404) end @@ -567,7 +567,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn |> assign(:actor, remote_actor_2) |> put_req_header("accept", "application/activity+json") - |> get(Routes.activity_pub_url(Endpoint, :member, member.id)) + |> get(url(~p"/member/#{member.id}")) assert json_response(conn, 200) == ActorView.render("member.json", %{member: member}) @@ -590,7 +590,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn |> assign(:actor, remote_actor_2) |> put_req_header("accept", "application/activity+json") - |> get(Routes.activity_pub_url(Endpoint, :member, member.id)) + |> get(url(~p"/member/#{member.id}")) assert redirected_to(conn) == "https://someremote.url/member/here" end @@ -601,7 +601,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> put_req_header("accept", "application/activity+json") - |> get(Routes.activity_pub_url(Endpoint, :member, member.id)) + |> get(url(~p"/member/#{member.id}")) assert json_response(conn, 404) end diff --git a/test/web/controllers/application_controller_test.exs b/test/web/controllers/application_controller_test.exs index 52215ad81..2d515fcba 100644 --- a/test/web/controllers/application_controller_test.exs +++ b/test/web/controllers/application_controller_test.exs @@ -134,7 +134,7 @@ defmodule Mobilizon.Web.ApplicationControllerTest do res = json_response(conn, 200) - verification_uri = Routes.page_url(Mobilizon.Web.Endpoint, :auth_device) + verification_uri = url(~p"/login/device") assert %{ "device_code" => _device_code, @@ -158,7 +158,7 @@ defmodule Mobilizon.Web.ApplicationControllerTest do res = json_response(conn, 200) - verification_uri = Routes.page_url(Mobilizon.Web.Endpoint, :auth_device) + verification_uri = url(~p"/login/device") assert %{ "device_code" => _device_code, diff --git a/test/web/controllers/feed_controller_test.exs b/test/web/controllers/feed_controller_test.exs index d8163cfc8..4d043dc5f 100644 --- a/test/web/controllers/feed_controller_test.exs +++ b/test/web/controllers/feed_controller_test.exs @@ -26,7 +26,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn |> get( Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "atom") + |> ~p"/@#{actor.preferred_username}/feed/atom" |> URI.decode() ) @@ -63,7 +63,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn |> get( Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "atom") + |> ~p"/@#{actor.preferred_username}/feed/atom" |> URI.decode() ) @@ -79,7 +79,7 @@ defmodule Mobilizon.Web.FeedControllerTest do |> put_req_header("accept", "application/atom+xml") |> get( Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "atom") + |> ~p"/@#{actor.preferred_username}/feed/atom" |> URI.decode() ) @@ -132,11 +132,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn - |> get( - Endpoint - |> Routes.feed_url(:actor, group.preferred_username, "ics") - |> URI.decode() - ) + |> get(URI.decode(~p"/@#{group.preferred_username}/feed/ics")) assert res = response(conn, 200) assert res =~ "BEGIN:VCALENDAR" @@ -163,11 +159,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn - |> get( - Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "ics") - |> URI.decode() - ) + |> get(URI.decode(~p"/@#{actor.preferred_username}/feed/ics")) assert response(conn, 404) end @@ -179,11 +171,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn |> put_req_header("accept", "text/calendar") - |> get( - Endpoint - |> Routes.feed_url(:actor, actor.preferred_username, "ics") - |> URI.decode() - ) + |> get(URI.decode(~p"/@#{actor.preferred_username}/feed/ics")) assert response(conn, 200) =~ "BEGIN:VCALENDAR" assert response_content_type(conn, :calendar) =~ "charset=utf-8" @@ -209,7 +197,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn |> get( Endpoint - |> Routes.feed_url(:event, event1.uuid, "ics") + |> ~p"/events/#{event1.uuid}/export/ics" |> URI.decode() ) @@ -241,11 +229,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn - |> get( - Endpoint - |> Routes.feed_url(:going, ShortUUID.encode!(feed_token.token), "atom") - |> URI.decode() - ) + |> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "atom")) assert response(conn, 200) =~ "" assert response_content_type(conn, :xml) =~ "charset=utf-8" @@ -279,11 +263,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn |> put_req_header("accept", "application/atom+xml") - |> get( - Endpoint - |> Routes.feed_url(:going, ShortUUID.encode!(feed_token.token), "atom") - |> URI.decode() - ) + |> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "atom")) assert response(conn, 200) =~ "" assert response_content_type(conn, :xml) =~ "charset=utf-8" @@ -301,11 +281,7 @@ defmodule Mobilizon.Web.FeedControllerTest do test "it returns 404 for an not existing feed", %{conn: conn} do conn = conn - |> get( - Endpoint - |> Routes.feed_url(:going, "not existing", "atom") - |> URI.decode() - ) + |> get(URI.decode(~p"/events/going/not_existing/atom")) assert response(conn, 404) end @@ -329,11 +305,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn |> put_req_header("accept", "text/calendar") - |> get( - Endpoint - |> Routes.feed_url(:going, ShortUUID.encode!(feed_token.token), "ics") - |> URI.decode() - ) + |> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "ics")) assert response(conn, 200) =~ "BEGIN:VCALENDAR" assert response_content_type(conn, :calendar) =~ "charset=utf-8" @@ -363,11 +335,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn = conn |> put_req_header("accept", "text/calendar") - |> get( - Endpoint - |> Routes.feed_url(:going, ShortUUID.encode!(feed_token.token), "ics") - |> URI.decode() - ) + |> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "ics")) assert response(conn, 200) =~ "BEGIN:VCALENDAR" assert response_content_type(conn, :calendar) =~ "charset=utf-8" @@ -383,7 +351,7 @@ defmodule Mobilizon.Web.FeedControllerTest do conn |> get( Endpoint - |> Routes.feed_url(:going, "not existing", "ics") + |> ~p"/events/going/not_existing/ics" |> URI.decode() ) diff --git a/test/web/controllers/nodeinfo_controller_test.exs b/test/web/controllers/nodeinfo_controller_test.exs index 8708986e9..0b0287ae7 100644 --- a/test/web/controllers/nodeinfo_controller_test.exs +++ b/test/web/controllers/nodeinfo_controller_test.exs @@ -12,11 +12,11 @@ defmodule Mobilizon.Web.NodeInfoControllerTest do assert json_response(conn, 200) == %{ "links" => [ %{ - "href" => Routes.node_info_url(Endpoint, :nodeinfo, "2.0"), + "href" => ~p"/.well-known/nodeinfo/2.0Ã", "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0" }, %{ - "href" => Routes.node_info_url(Endpoint, :nodeinfo, "2.1"), + "href" => ~p"/.well-known/nodeinfo/2.1", "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1" } ] diff --git a/test/web/controllers/page_controller_test.exs b/test/web/controllers/page_controller_test.exs index 651cdd13f..432bec2c2 100644 --- a/test/web/controllers/page_controller_test.exs +++ b/test/web/controllers/page_controller_test.exs @@ -53,42 +53,42 @@ defmodule Mobilizon.Web.PageControllerTest do test "GET /events/:uuid", %{conn: conn} do event = insert(:event, visibility: :public) - conn = get(conn, Routes.page_url(Endpoint, :event, event.uuid)) + conn = get(conn, url(~p"/events/#{event.uuid}")) assert html_response(conn, 200) =~ event.title end test "GET /events/:uuid with unlisted event", %{conn: conn} do event = insert(:event, visibility: :unlisted) - conn = get(conn, Routes.page_url(Endpoint, :event, event.uuid)) + conn = get(conn, url(~p"/events/#{event.uuid}")) assert html_response(conn, 200) =~ event.title assert ["noindex"] == get_resp_header(conn, "x-robots-tag") end test "GET /events/:uuid with not existing event", %{conn: conn} do - conn = get(conn, Routes.page_url(Endpoint, :event, "not_existing_event")) + conn = get(conn, ~p"/events/not_existing_event") assert html_response(conn, 404) end test "GET /events/:uuid with event not public", %{conn: conn} do event = insert(:event, visibility: :restricted) - conn = get(conn, Routes.page_url(Endpoint, :event, event.uuid)) + conn = get(conn, url(~p"/events/#{event.uuid}")) assert html_response(conn, 404) end test "GET /comments/:uuid", %{conn: conn} do comment = insert(:comment) - conn = get(conn, Routes.page_url(Endpoint, :comment, comment.uuid)) + conn = get(conn, url(~p"/comments/#{comment.uuid}")) assert html_response(conn, 200) =~ comment.text end test "GET /comments/:uuid with not existing comment", %{conn: conn} do - conn = get(conn, Routes.page_url(Endpoint, :comment, "not_existing_comment")) + conn = get(conn, ~p"/comments/not_existing_comment") assert html_response(conn, 404) end test "GET /comments/:uuid with comment not public", %{conn: conn} do comment = insert(:comment, visibility: :private) - conn = get(conn, Routes.page_url(Endpoint, :comment, comment.uuid)) + conn = get(conn, url(~p"/comments/#{comment.uuid}")) assert html_response(conn, 404) end end From 9e6b232a785fdbdcd2f183ab69f5c13e91d752df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 1 Dec 2023 09:52:28 +0100 Subject: [PATCH 2/6] feat: add links to cancel anonymous participations in emails Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/participant.ex | 11 +- lib/graphql/schema/events/participant.ex | 4 +- lib/web/controllers/page_controller.ex | 2 + lib/web/email/participation.ex | 2 + lib/web/router.ex | 6 + ...ymous_participation_confirmation.html.heex | 33 +++++- .../event_participation_confirmed.html.heex | 69 ++++++++--- .../Participation/CancelParticipation.vue | 107 ++++++++++++++++++ src/graphql/event.ts | 5 + src/i18n/en_US.json | 8 +- src/i18n/fr_FR.json | 8 +- src/router/event.ts | 13 +++ 12 files changed, 244 insertions(+), 24 deletions(-) create mode 100644 src/components/Participation/CancelParticipation.vue diff --git a/lib/graphql/resolvers/participant.ex b/lib/graphql/resolvers/participant.ex index ad5058c1e..6b3efa5d0 100644 --- a/lib/graphql/resolvers/participant.ex +++ b/lib/graphql/resolvers/participant.ex @@ -176,7 +176,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do case Participations.leave(event, actor, %{local: false, cancellation_token: token}) do {:ok, _activity, %Participant{id: participant_id} = _participant} -> - {:ok, %{event: %{id: event_id}, actor: %{id: actor_id}, id: participant_id}} + {:ok, %Event{} = event} = Events.get_event_with_preload(event_id) + %Actor{} = actor = Actors.get_actor_with_preload!(actor_id) + {:ok, %{event: event, actor: actor, id: participant_id}} {:error, :is_only_organizer} -> {:error, @@ -202,8 +204,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, actor_id), {:has_event, {:ok, %Event{} = event}} <- {:has_event, Events.get_event_with_preload(event_id)}, - {:ok, _activity, _participant} <- Participations.leave(event, actor) do - {:ok, %{event: %{id: event_id}, actor: %{id: actor_id}}} + {:ok, _activity, %Participant{id: participant_id} = _participant} <- + Participations.leave(event, actor) do + {:ok, %Event{} = event} = Events.get_event_with_preload(event_id) + %Actor{} = actor = Actors.get_actor_with_preload!(actor_id) + {:ok, %{event: event, actor: actor, id: participant_id}} else {:has_event, _} -> {:error, "Event with this ID #{inspect(event_id)} doesn't exist"} diff --git a/lib/graphql/schema/events/participant.ex b/lib/graphql/schema/events/participant.ex index 0585173ae..07ba90e89 100644 --- a/lib/graphql/schema/events/participant.ex +++ b/lib/graphql/schema/events/participant.ex @@ -90,8 +90,8 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do object :deleted_participant do meta(:authorize, :all) field(:id, :id, description: "The participant ID") - field(:event, :deleted_object, description: "The participant's event") - field(:actor, :deleted_object, description: "The participant's actor") + field(:event, :event, description: "The participant's event") + field(:actor, :actor, description: "The participant's actor") end object :participant_mutations do diff --git a/lib/web/controllers/page_controller.ex b/lib/web/controllers/page_controller.ex index dcb80f391..104097c20 100644 --- a/lib/web/controllers/page_controller.ex +++ b/lib/web/controllers/page_controller.ex @@ -26,6 +26,8 @@ defmodule Mobilizon.Web.PageController do defdelegate moderation_report(conn, params), to: PageController, as: :index @spec participation_email_confirmation(Plug.Conn.t(), any) :: Plug.Conn.t() defdelegate participation_email_confirmation(conn, params), to: PageController, as: :index + @spec participation_email_cancellation(Plug.Conn.t(), any) :: Plug.Conn.t() + defdelegate participation_email_cancellation(conn, params), to: PageController, as: :index @spec user_email_validation(Plug.Conn.t(), any) :: Plug.Conn.t() defdelegate user_email_validation(conn, params), to: PageController, as: :index @spec my_groups(Plug.Conn.t(), any) :: Plug.Conn.t() diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index 9a101d102..6ac606bb8 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -99,6 +99,7 @@ defmodule Mobilizon.Web.Email.Participation do locale: locale, event: event, jsonLDMetadata: json_ld(participant), + participant: participant, subject: subject }) end @@ -123,6 +124,7 @@ defmodule Mobilizon.Web.Email.Participation do locale: locale, event: event, jsonLDMetadata: json_ld(participant), + participant: participant, subject: subject }) end diff --git a/lib/web/router.ex b/lib/web/router.ex index c290d2683..9a1534e88 100644 --- a/lib/web/router.ex +++ b/lib/web/router.ex @@ -195,6 +195,12 @@ defmodule Mobilizon.Web.Router do get("/participation/email/confirm/:token", PageController, :participation_email_confirmation) + get( + "/participation/email/cancel/:uuid/:token", + PageController, + :participation_email_cancellation + ) + get("/validate/email/:token", PageController, :user_email_validation) get("/groups/me", PageController, :my_groups) diff --git a/lib/web/templates/email/anonymous_participation_confirmation.html.heex b/lib/web/templates/email/anonymous_participation_confirmation.html.heex index fa37af8ff..50f4f9e8e 100644 --- a/lib/web/templates/email/anonymous_participation_confirmation.html.heex +++ b/lib/web/templates/email/anonymous_participation_confirmation.html.heex @@ -87,14 +87,39 @@ style="padding: 20px 30px 40px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >

- <%= ngettext( - "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", - "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", - 1 + <%= gettext( + "If you wish to cancel your participation, simply click on the link below." ) %>

+ + + + + + +
+ + + + +
+ url() + |> URI.decode() + } + target="_blank" + style="font-size: 20px; font-family: 'Roboto', Helvetica, Arial, sans-serif; color: #3C376E; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" + > + <%= gettext("Cancel my attendance") %> + +
+
+ + - - -

- <%= gettext( - "Would you wish to update or cancel your attendance, simply access the event page through the link above and click on the Attending button." - ) %> -

- - + <%= if @participant.metadata.cancellation_token do %> + + +

+ <%= gettext( + "If you wish to cancel your participation, simply click on the link below." + ) %> +

+ + + + + + + + +
+ + + + +
+ url() + |> URI.decode() + } + target="_blank" + style="font-size: 20px; font-family: 'Roboto', Helvetica, Arial, sans-serif; color: #3C376E; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;" + > + <%= gettext("Cancel my attendance") %> + +
+
+ + + <% else %> + + +

+ <%= gettext( + "Would you wish to update or cancel your attendance, simply access the event page through the link above and click on the Attending button." + ) %> +

+ + + <% end %>