Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions lib/plausible_web/live/shared_link_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<.td actions>
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

@apata apata Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the benefit of ensuring proper encoding even for auth query parameter, which Plausible.Sites.shared_link_url/2 doesn't actually do. We could make use of this same logic in Plausible.Sites.shared_link_url/2, but it didn't make sense to me when I considered the relation between the modules Routes / Plausible.Sites.

end
end
4 changes: 0 additions & 4 deletions lib/plausible_web/views/site_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 28 additions & 4 deletions test/plausible/sites_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 %{
Expand Down Expand Up @@ -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 %{
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Comment on lines +1038 to +1045
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This codifies current non-ideal behavior that I noticed. It's worth thinking about how to unify the two and all our other route utils as well.

end
end
end
8 changes: 6 additions & 2 deletions test/plausible_web/live/shared_link_settings_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading