diff --git a/js/src/i18n/ca.json b/js/src/i18n/ca.json index a8b9e26d..a280aa4b 100644 --- a/js/src/i18n/ca.json +++ b/js/src/i18n/ca.json @@ -132,7 +132,7 @@ "Click to upload": "Clica per pujar", "Close": "Deshabilita", "Close comments for all (except for admins)": "Deshabilita els comentaris per a tothom excepte admins", - "Close events": "Activitats prop de tu", + "Events nearby": "Activitats prop de tu", "Closed": "Deshabilitats", "Comment deleted": "S'ha esborrat el comentari", "Comment from @{username} reported": "S'ha denunciat un comentari de @{username}", diff --git a/js/src/i18n/de.json b/js/src/i18n/de.json index 9b530654..b0147437 100644 --- a/js/src/i18n/de.json +++ b/js/src/i18n/de.json @@ -135,7 +135,7 @@ "Click to upload": "Klicken zum Hochladen", "Close": "Schließen", "Close comments for all (except for admins)": "Kommentare für alle sperren (außer für Admins)", - "Close events": "Veranstaltungen in Ihrer Nähe", + "Events nearby": "Veranstaltungen in Ihrer Nähe", "Closed": "Geschlossen", "Comment deleted": "Kommentar gelöscht", "Comment from @{username} reported": "Kommentar von @{username} gemeldet", diff --git a/js/src/i18n/en_US.json b/js/src/i18n/en_US.json index 7498744f..cffa26a7 100644 --- a/js/src/i18n/en_US.json +++ b/js/src/i18n/en_US.json @@ -858,7 +858,7 @@ "Your upcoming events": "Your upcoming events", "Last published events": "Last published events", "On {instance}": "On {instance}", - "Close events": "Close events", + "Events nearby": "Events nearby", "Within {number} kilometers of {place}": "|Within one kilometer of {place}|Within {number} kilometers of {place}", "@{username}": "@{username}", "Yesterday": "Yesterday", diff --git a/js/src/i18n/es.json b/js/src/i18n/es.json index df4a2d1d..e4fbc565 100644 --- a/js/src/i18n/es.json +++ b/js/src/i18n/es.json @@ -138,7 +138,7 @@ "Click to upload": "Haz clic para subir (upload)", "Close": "Cerrar", "Close comments for all (except for admins)": "Cerrar comentarios para todos (excepto para administradores)", - "Close events": "Eventos cercanos", + "Events nearby": "Eventos cercanos", "Closed": "Cerrado", "Collections": "Colecciones", "Comment deleted": "Comentario borrado", diff --git a/js/src/i18n/fr_FR.json b/js/src/i18n/fr_FR.json index 64f62c69..1866b0f3 100644 --- a/js/src/i18n/fr_FR.json +++ b/js/src/i18n/fr_FR.json @@ -128,7 +128,7 @@ "Click to upload": "Cliquez pour téléverser", "Close": "Fermé", "Close comments for all (except for admins)": "Fermer les commentaires à tout le monde (excepté les administrateur⋅rice·s)", - "Close events": "Événements proches", + "Events nearby": "Événements proches", "Closed": "Fermé", "Comment deleted": "Commentaire supprimé", "Comment from @{username} reported": "Commentaire de @{username} signalé", diff --git a/js/src/i18n/gd.json b/js/src/i18n/gd.json index 90dab098..b22b1f1d 100644 --- a/js/src/i18n/gd.json +++ b/js/src/i18n/gd.json @@ -122,7 +122,7 @@ "Click to upload": "Briog airson luchdadh suas", "Close": "Dùin", "Close comments for all (except for admins)": "Dùin na beachdan dhan a h-uile duine (ach rianairean)", - "Close events": "Tachartasan am fagas", + "Events nearby": "Tachartasan am fagas", "Closed": "Dùinte", "Comment deleted": "Chaidh am beachd a sguabadh às", "Comment from @{username} reported": "Chaidh gearan a dhèanamh mu bheachd le @{username}", diff --git a/js/src/i18n/gl.json b/js/src/i18n/gl.json index d994ec98..08a906db 100644 --- a/js/src/i18n/gl.json +++ b/js/src/i18n/gl.json @@ -131,7 +131,7 @@ "Click to upload": "Preme para subir", "Close": "Pechar", "Close comments for all (except for admins)": "Pechar comentarios para todos (excepto admins)", - "Close events": "Pechar eventos", + "Events nearby": "Pechar eventos", "Closed": "Pechado", "Comment deleted": "Comentario eliminado", "Comment from @{username} reported": "Comentario de @{username} denunciado", diff --git a/js/src/i18n/hu.json b/js/src/i18n/hu.json index 28c5ed29..3c05a810 100644 --- a/js/src/i18n/hu.json +++ b/js/src/i18n/hu.json @@ -127,7 +127,7 @@ "Click to upload": "Kattintson a feltöltéshez", "Close": "Lezárás", "Close comments for all (except for admins)": "Hozzászólások lezárása mindenkinél (kivéve az adminisztrátoroknál)", - "Close events": "Események bezárása", + "Events nearby": "Események bezárása", "Closed": "Lezárva", "Comment deleted": "Hozzászólás törölve", "Comment from @{username} reported": "@{username} felhasználótól érkezett hozzászólás jelentve", diff --git a/js/src/i18n/nn.json b/js/src/i18n/nn.json index 15368949..613e582b 100644 --- a/js/src/i18n/nn.json +++ b/js/src/i18n/nn.json @@ -127,7 +127,7 @@ "Click to upload": "Klikk for å lasta opp", "Close": "Steng", "Close comments for all (except for admins)": "Steng for kommentarar frå alle (unnateke administratorar)", - "Close events": "Hendingar i nærleiken", + "Events nearby": "Hendingar i nærleiken", "Closed": "Stengt", "Comment deleted": "Kommentaren er sletta", "Comment from @{username} reported": "Kommentaren frå @{username} er rapportert", diff --git a/js/src/i18n/ru.json b/js/src/i18n/ru.json index 9e67ecca..12ffa3d9 100644 --- a/js/src/i18n/ru.json +++ b/js/src/i18n/ru.json @@ -122,7 +122,7 @@ "Click to upload": "Нажмите, чтобы загрузить", "Close": "Закрыть", "Close comments for all (except for admins)": "Закрыть комментарии для всех (кроме админов)", - "Close events": "Ближайшие мероприятия", + "Events nearby": "Ближайшие мероприятия", "Closed": "Закрыто", "Comment deleted": "Комментарий удален", "Comment from @{username} reported": "Жалоба на комментарий от @{username} отправлена", diff --git a/js/src/i18n/sl.json b/js/src/i18n/sl.json index 3ab97fd3..ff91e5c1 100644 --- a/js/src/i18n/sl.json +++ b/js/src/i18n/sl.json @@ -123,7 +123,7 @@ "Click to upload": "Kliknite za pošiljanje", "Close": "Zapri", "Close comments for all (except for admins)": "Zapri komentarje za vse (razen za skrbnike)", - "Close events": "Zapri dogodke", + "Events nearby": "Zapri dogodke", "Closed": "Zaprto", "Comment deleted": "Komentar je izbrisan", "Comment from @{username} reported": "Prijavljen je bil komentar uporabnika @{username}", diff --git a/js/src/views/Home.vue b/js/src/views/Home.vue index 0b86d4ac..a8b7990b 100644 --- a/js/src/views/Home.vue +++ b/js/src/views/Home.vue @@ -252,7 +252,7 @@

- {{ $t("Close events") }} + {{ $t("Events nearby") }}

{{ diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 608955b0..824b9c3c 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -592,7 +592,7 @@ defmodule Mobilizon.Federation.ActivityPub do Enum.each(Users.list_moderators(), fn moderator -> moderator |> Admin.report(report) - |> Mailer.deliver_later() + |> Mailer.send_email_later() end) {:ok, activity, report} @@ -621,6 +621,10 @@ defmodule Mobilizon.Federation.ActivityPub do Logger.info("Actor was deleted") {:error, :actor_deleted} + {:error, e} -> + Logger.warn("Failed to make actor from url") + {:error, e} + e -> Logger.warn("Failed to make actor from url") {:error, e} @@ -801,6 +805,10 @@ defmodule Mobilizon.Federation.ActivityPub do Logger.info("Response HTTP 410") {:error, :actor_deleted} + {:error, e} -> + Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}") + {:error, e} + e -> Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}") {:error, e} diff --git a/lib/federation/activity_pub/types/discussions.ex b/lib/federation/activity_pub/types/discussions.ex index f9b615d6..3f06baed 100644 --- a/lib/federation/activity_pub/types/discussions.ex +++ b/lib/federation/activity_pub/types/discussions.ex @@ -132,7 +132,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Discussions do ) args - |> Map.update(:title, "", &String.trim/1) + # title might be nil + |> Map.update(:title, "", fn title -> String.trim(title || "") end) |> Map.put(:text, text) end end diff --git a/lib/graphql/resolvers/participant.ex b/lib/graphql/resolvers/participant.ex index ede77f0d..6b20a364 100644 --- a/lib/graphql/resolvers/participant.ex +++ b/lib/graphql/resolvers/participant.ex @@ -70,7 +70,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do participant, Map.get(args, :locale, "en") ) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() end {:ok, participant} diff --git a/lib/graphql/resolvers/user.ex b/lib/graphql/resolvers/user.ex index a07da007..82a4dde3 100644 --- a/lib/graphql/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -115,7 +115,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do def create_user(_parent, args, _resolution) do with :registration_ok <- check_registration_config(args), {:ok, %User{} = user} <- Users.register(args), - {:ok, %Bamboo.Email{}} <- + %Bamboo.Email{} <- Email.User.send_confirmation_email(user, Map.get(args, :locale, "en")) do {:ok, user} else @@ -206,7 +206,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do Users.get_user_by_email(email, activated: true, unconfirmed: false), {:can_reset_password, true} <- {:can_reset_password, Authenticator.can_reset_password?(user)}, - {:ok, %Bamboo.Email{} = _email_html} <- + {:ok, %Bamboo.Email{}} <- Email.User.send_password_reset_email(user, Map.get(args, :locale, locale)) do {:ok, email} else @@ -358,11 +358,11 @@ defmodule Mobilizon.GraphQL.Resolvers.User do {:ok, %User{} = user} <- Users.update_user_email(user, new_email) do user |> Email.User.send_email_reset_old_email() - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() user |> Email.User.send_email_reset_new_email() - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() {:ok, user} else diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index a1ca0996..c754964a 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -16,7 +16,7 @@ defmodule Mobilizon do alias Mobilizon.{Config, Storage, Web} alias Mobilizon.Federation.ActivityPub - alias Mobilizon.Service.ErrorPage + alias Mobilizon.Service.{ErrorPage, ErrorReporter} alias Mobilizon.Service.Export.{Feed, ICalendar} @name Mix.Project.config()[:name] @@ -66,6 +66,16 @@ defmodule Mobilizon do ] ++ task_children(@env) + Logger.add_backend(Sentry.LoggerBackend) + :ok = Oban.Telemetry.attach_default_logger() + + :telemetry.attach_many( + "oban-errors", + [[:oban, :job, :exception], [:oban, :circuit, :trip]], + &ErrorReporter.handle_event/4, + %{} + ) + Supervisor.start_link(children, strategy: :one_for_one, name: Mobilizon.Supervisor) end diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 21dc47a8..aabdf21e 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -1282,11 +1282,13 @@ defmodule Mobilizon.Actors do @doc """ Whether the actor needs to be updated. - Local actors obviously don't need to be updated + Local actors obviously don't need to be updated, neither do suspended ones """ @spec needs_update?(Actor.t()) :: boolean def needs_update?(%Actor{domain: nil}), do: false + def needs_update?(%Actor{suspended: true}), do: false + def needs_update?(%Actor{last_refreshed_at: nil, domain: domain}) when not is_nil(domain), do: true diff --git a/lib/service/error_reporter.ex b/lib/service/error_reporter.ex new file mode 100644 index 00000000..46900d94 --- /dev/null +++ b/lib/service/error_reporter.ex @@ -0,0 +1,17 @@ +defmodule Mobilizon.Service.ErrorReporter do + @moduledoc """ + Module to delegate all exceptions to Sentry + """ + def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do + extra = + job + |> Map.take([:id, :args, :meta, :queue, :worker]) + |> Map.merge(measure) + + Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: extra) + end + + def handle_event([:oban, :circuit, :trip], _measure, meta, _) do + Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta) + end +end diff --git a/lib/service/workers/notification.ex b/lib/service/workers/notification.ex index a3a7ff9a..19202f8b 100644 --- a/lib/service/workers/notification.ex +++ b/lib/service/workers/notification.ex @@ -23,7 +23,7 @@ defmodule Mobilizon.Service.Workers.Notification do Users.get_user_with_settings!(user_id) do email |> Notification.before_event_notification(participant, locale) - |> Mailer.deliver_later() + |> Mailer.send_email_later() :ok end @@ -48,7 +48,7 @@ defmodule Mobilizon.Service.Workers.Notification do true <- length(participations) > 0 do user |> Notification.on_day_notification(participations, total, locale) - |> Mailer.deliver_later() + |> Mailer.send_email_later() :ok else @@ -77,7 +77,7 @@ defmodule Mobilizon.Service.Workers.Notification do true <- length(participations) > 0 do user |> Notification.weekly_notification(participations, total, locale) - |> Mailer.deliver_later() + |> Mailer.send_email_later() :ok else @@ -99,7 +99,7 @@ defmodule Mobilizon.Service.Workers.Notification do Events.list_participants_for_event(event_id, [:not_approved]) do user |> Notification.pending_participation_notification(event, total) - |> Mailer.deliver_later() + |> Mailer.send_email_later() :ok else diff --git a/lib/web/auth/context.ex b/lib/web/auth/context.ex index 9f41dd61..aaa16e25 100644 --- a/lib/web/auth/context.ex +++ b/lib/web/auth/context.ex @@ -23,7 +23,8 @@ defmodule Mobilizon.Web.Auth.Context do context = case Guardian.Plug.current_resource(conn) do - %User{} = user -> + %User{id: user_id, email: user_email} = user -> + Sentry.Context.set_user_context(%{id: user_id, name: user_email}) Map.put(context, :current_user, user) nil -> diff --git a/lib/web/email/event.ex b/lib/web/email/event.ex index 2a34fb34..5b3e39dd 100644 --- a/lib/web/email/event.ex +++ b/lib/web/email/event.ex @@ -143,6 +143,6 @@ defmodule Mobilizon.Web.Email.Event do ) do email |> Email.Event.event_updated(actor, old_event, event, diff, timezone, locale) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() end end diff --git a/lib/web/email/follow.ex b/lib/web/email/follow.ex index ef12e495..25c3c953 100644 --- a/lib/web/email/follow.ex +++ b/lib/web/email/follow.ex @@ -62,7 +62,7 @@ defmodule Mobilizon.Web.Email.Follow do |> assign(:follower, follower) |> assign(:subject, subject) |> render(:instance_follow) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok end diff --git a/lib/web/email/group.ex b/lib/web/email/group.ex index 440c0f20..2c302900 100644 --- a/lib/web/email/group.ex +++ b/lib/web/email/group.ex @@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.Group do |> assign(:group, group) |> assign(:subject, subject) |> render(:group_invite) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok end @@ -70,7 +70,7 @@ defmodule Mobilizon.Web.Email.Group do |> assign(:group, group) |> assign(:subject, subject) |> render(:group_member_removal) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok end @@ -107,7 +107,7 @@ defmodule Mobilizon.Web.Email.Group do |> assign(:subject, subject) |> assign(:instance, instance) |> render(:group_suspension) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok end @@ -147,7 +147,7 @@ defmodule Mobilizon.Web.Email.Group do |> assign(:instance, instance) |> assign(:author, author) |> render(:group_deletion) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok else diff --git a/lib/web/email/mailer.ex b/lib/web/email/mailer.ex index 87316f1c..4996f769 100644 --- a/lib/web/email/mailer.ex +++ b/lib/web/email/mailer.ex @@ -3,4 +3,28 @@ defmodule Mobilizon.Web.Email.Mailer do Mobilizon Mailer. """ use Bamboo.Mailer, otp_app: :mobilizon + + def send_email_later(email) do + Mobilizon.Web.Email.Mailer.deliver_later!(email) + rescue + error -> + Sentry.capture_exception(error, + stacktrace: __STACKTRACE__, + extra: %{extra: "Error while sending email"} + ) + + reraise error, __STACKTRACE__ + end + + def send_email(email) do + Mobilizon.Web.Email.Mailer.deliver_now!(email) + rescue + error -> + Sentry.capture_exception(error, + stacktrace: __STACKTRACE__, + extra: %{extra: "Error while sending email"} + ) + + reraise error, __STACKTRACE__ + end end diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index 132c0d8a..dbd90e69 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -28,7 +28,7 @@ defmodule Mobilizon.Web.Email.Participation do email |> participation_updated(participation, locale) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() end :ok @@ -40,7 +40,7 @@ defmodule Mobilizon.Web.Email.Participation do with %User{locale: locale} = user <- Users.get_user!(user_id) do user |> participation_updated(participation, locale) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() :ok end diff --git a/lib/web/email/user.ex b/lib/web/email/user.ex index 01d31543..7dd74b70 100644 --- a/lib/web/email/user.ex +++ b/lib/web/email/user.ex @@ -80,7 +80,7 @@ defmodule Mobilizon.Web.Email.User do Users.update_user(user, %{ "confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) }), - {:ok, %Bamboo.Email{}} <- send_confirmation_email(user, locale) do + %Bamboo.Email{} <- send_confirmation_email(user, locale) do Logger.info("Sent confirmation email again to #{user.email}") {:ok, user.email} end @@ -90,7 +90,7 @@ defmodule Mobilizon.Web.Email.User do def send_confirmation_email(%User{} = user, locale \\ "en") do user |> Email.User.confirmation_email(locale) - |> Email.Mailer.deliver_later() + |> Email.Mailer.send_email_later() end @doc """ @@ -132,10 +132,10 @@ defmodule Mobilizon.Web.Email.User do "reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) }) ), - {:ok, %Bamboo.Email{} = mail} <- + %Bamboo.Email{} = mail <- user_updated |> Email.User.reset_password_email(locale) - |> Email.Mailer.deliver_later() do + |> Email.Mailer.send_email_later() do {:ok, mail} else {:error, reason} -> {:error, reason}