mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Fix APP-2NA (#3119)
This commit is contained in:
parent
fea9bb32ee
commit
9debcdee24
@ -7,19 +7,24 @@ defmodule Plausible.Workers.SendEmailReport do
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"interval" => "weekly", "site_id" => site_id}}) do
|
||||
site = Repo.get(Plausible.Site, site_id) |> Repo.preload(:weekly_report)
|
||||
today = Timex.now(site.timezone) |> DateTime.to_date()
|
||||
date = Timex.shift(today, weeks: -1) |> Timex.end_of_week() |> Date.to_iso8601()
|
||||
query = Query.from(site, %{"period" => "7d", "date" => date})
|
||||
|
||||
for email <- site.weekly_report.recipients do
|
||||
unsubscribe_link =
|
||||
PlausibleWeb.Endpoint.url() <>
|
||||
"/sites/#{URI.encode_www_form(site.domain)}/weekly-report/unsubscribe?email=#{email}"
|
||||
if site do
|
||||
today = Timex.now(site.timezone) |> DateTime.to_date()
|
||||
date = Timex.shift(today, weeks: -1) |> Timex.end_of_week() |> Date.to_iso8601()
|
||||
query = Query.from(site, %{"period" => "7d", "date" => date})
|
||||
|
||||
send_report(email, site, "Weekly", unsubscribe_link, query)
|
||||
for email <- site.weekly_report.recipients do
|
||||
unsubscribe_link =
|
||||
PlausibleWeb.Endpoint.url() <>
|
||||
"/sites/#{URI.encode_www_form(site.domain)}/weekly-report/unsubscribe?email=#{email}"
|
||||
|
||||
send_report(email, site, "Weekly", unsubscribe_link, query)
|
||||
end
|
||||
|
||||
:ok
|
||||
else
|
||||
:discard
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@impl Oban.Worker
|
||||
|
@ -23,6 +23,11 @@ defmodule Plausible.Workers.SendEmailReportTest do
|
||||
)
|
||||
end
|
||||
|
||||
test "does not crash for deleted sites" do
|
||||
assert :discard =
|
||||
perform_job(SendEmailReport, %{"site_id" => 28_378_237, "interval" => "weekly"})
|
||||
end
|
||||
|
||||
test "calculates timezone correctly" do
|
||||
site =
|
||||
insert(:site,
|
||||
|
Loading…
Reference in New Issue
Block a user