diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d52136969aa..d676d33fb706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ All notable changes to this project will be documented in this file. - Main graph no longer shows empty values after current time for `day`, `month` and `year` periods - Include `bounce_rate` metric in Entry Pages breakdown - Dark mode theme has been refined with darker color scheme and better visual hierarchy +- Creating shared links now happens in a modal ### Fixed diff --git a/lib/plausible_web/live/shared_link_settings.ex b/lib/plausible_web/live/shared_link_settings.ex index 5bd7152d287d..3ebf4ea5c335 100644 --- a/lib/plausible_web/live/shared_link_settings.ex +++ b/lib/plausible_web/live/shared_link_settings.ex @@ -94,7 +94,7 @@ defmodule PlausibleWeb.Live.SharedLinkSettings do <.input_with_clipboard name={link.slug} id={link.slug} - value={shared_link_dest(@site, link)} + value={Plausible.Sites.shared_link_url(@site, link)} /> <.td actions> @@ -177,8 +177,4 @@ defmodule PlausibleWeb.Live.SharedLinkSettings do {:noreply, socket} end - - defp shared_link_dest(site, link) do - Routes.stats_path(PlausibleWeb.Endpoint, :shared_link, site.domain, auth: link.slug) - end end diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex index 6aafbfb2b34d..23b49bd16372 100644 --- a/lib/plausible_web/views/site_view.ex +++ b/lib/plausible_web/views/site_view.ex @@ -6,10 +6,6 @@ defmodule PlausibleWeb.SiteView do PlausibleWeb.Endpoint.url() end - def shared_link_dest(site, link) do - Plausible.Sites.shared_link_url(site, link) - end - def with_indefinite_article(word) do if String.starts_with?(word, ["a", "e", "i", "o", "u"]) do "an " <> word diff --git a/test/plausible/sites_test.exs b/test/plausible/sites_test.exs index 62401ccb72ba..fef7794db50e 100644 --- a/test/plausible/sites_test.exs +++ b/test/plausible/sites_test.exs @@ -319,7 +319,7 @@ defmodule Plausible.SitesTest do Plausible.Teams.complete_setup(site1.team) - # excluded + # excluded new_site(owner: user1, domain: "consolidated.example.com", consolidated: true) # guest site access @@ -373,7 +373,7 @@ defmodule Plausible.SitesTest do site5 = new_site(domain: "team.example.com", owner: user4) add_member(site5.team, user: user1, role: :editor) - # excluded + # excluded new_site(owner: user1, domain: "consolidated.example.com", consolidated: true) assert %{ @@ -413,7 +413,7 @@ defmodule Plausible.SitesTest do team5 = Plausible.Teams.complete_setup(site5.team) add_member(site5.team, user: user1, role: :admin) - # excluded + # excluded new_site(owner: user1, domain: "consolidated.example.com", consolidated: true) assert %{ @@ -435,7 +435,7 @@ defmodule Plausible.SitesTest do {:ok, _} = Sites.toggle_pin(pending_owner, site) - # excluded + # excluded new_site(owner: owner, domain: "consolidated.example.com", consolidated: true) new_site(owner: pending_owner, domain: "consolidated2.example.com", consolidated: true) @@ -1021,4 +1021,28 @@ defmodule Plausible.SitesTest do end end end + + describe "shared_link_url/2" do + test "contains base URL and slug" do + site = new_site(domain: "example.com/deep/path") + link = insert(:shared_link, site: site) + + # base url in tests is http://localhost:8000, in prod, it's https://plausible.io + assert "http://localhost:8000/share/example.com%2Fdeep%2Fpath?auth=" <> slug = + Sites.shared_link_url(site, link) + + # we assume slug is URL safe + assert ^slug = link.slug + end + + test "doesn't share the same domain formatting with public dashboard links" do + site = new_site(domain: "a-café.fr") + link = insert(:shared_link, site: site) + + assert "http://localhost:8000/a-café.fr" = PlausibleWeb.StatsView.pretty_stats_url(site) + + assert "http://localhost:8000/share/a-caf%C3%A9.fr?" <> _q = + Sites.shared_link_url(site, link) + end + end end diff --git a/test/plausible_web/live/shared_link_settings_test.exs b/test/plausible_web/live/shared_link_settings_test.exs index aec1b35affad..8e79d95f7a00 100644 --- a/test/plausible_web/live/shared_link_settings_test.exs +++ b/test/plausible_web/live/shared_link_settings_test.exs @@ -79,16 +79,20 @@ defmodule PlausibleWeb.Live.SharedLinkSettingsTest do site: site, session: session } do - _link_with_password = + link_with_password = insert(:shared_link, site: site, name: "Protected", password: "secret") - _link_without_password = insert(:shared_link, site: site, name: "Public") + link_without_password = insert(:shared_link, site: site, name: "Public") lv = get_liveview(conn, session) html = render(lv) assert html =~ "Protected" + assert html =~ "value=\"#{Plausible.Sites.shared_link_url(site, link_with_password)}\"" + assert html =~ "Public" + assert html =~ "value=\"#{Plausible.Sites.shared_link_url(site, link_without_password)}\"" + # Check for lock icons assert element_exists?(html, ~s|svg|) end