Skip to content

Commit af7dd46

Browse files
authored
Fix shared link hostname (#5870)
* Fix missing share link hostname * Update changelog * Tests
1 parent 2ca24e7 commit af7dd46

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ All notable changes to this project will be documented in this file.
3333
- Main graph no longer shows empty values after current time for `day`, `month` and `year` periods
3434
- Include `bounce_rate` metric in Entry Pages breakdown
3535
- Dark mode theme has been refined with darker color scheme and better visual hierarchy
36+
- Creating shared links now happens in a modal
3637

3738
### Fixed
3839

lib/plausible_web/live/shared_link_settings.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ defmodule PlausibleWeb.Live.SharedLinkSettings do
9494
<.input_with_clipboard
9595
name={link.slug}
9696
id={link.slug}
97-
value={shared_link_dest(@site, link)}
97+
value={Plausible.Sites.shared_link_url(@site, link)}
9898
/>
9999
</.td>
100100
<.td actions>
@@ -177,8 +177,4 @@ defmodule PlausibleWeb.Live.SharedLinkSettings do
177177

178178
{:noreply, socket}
179179
end
180-
181-
defp shared_link_dest(site, link) do
182-
Routes.stats_path(PlausibleWeb.Endpoint, :shared_link, site.domain, auth: link.slug)
183-
end
184180
end

lib/plausible_web/views/site_view.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ defmodule PlausibleWeb.SiteView do
66
PlausibleWeb.Endpoint.url()
77
end
88

9-
def shared_link_dest(site, link) do
10-
Plausible.Sites.shared_link_url(site, link)
11-
end
12-
139
def with_indefinite_article(word) do
1410
if String.starts_with?(word, ["a", "e", "i", "o", "u"]) do
1511
"an " <> word

test/plausible/sites_test.exs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ defmodule Plausible.SitesTest do
319319

320320
Plausible.Teams.complete_setup(site1.team)
321321

322-
# excluded
322+
# excluded
323323
new_site(owner: user1, domain: "consolidated.example.com", consolidated: true)
324324

325325
# guest site access
@@ -373,7 +373,7 @@ defmodule Plausible.SitesTest do
373373
site5 = new_site(domain: "team.example.com", owner: user4)
374374
add_member(site5.team, user: user1, role: :editor)
375375

376-
# excluded
376+
# excluded
377377
new_site(owner: user1, domain: "consolidated.example.com", consolidated: true)
378378

379379
assert %{
@@ -413,7 +413,7 @@ defmodule Plausible.SitesTest do
413413
team5 = Plausible.Teams.complete_setup(site5.team)
414414
add_member(site5.team, user: user1, role: :admin)
415415

416-
# excluded
416+
# excluded
417417
new_site(owner: user1, domain: "consolidated.example.com", consolidated: true)
418418

419419
assert %{
@@ -435,7 +435,7 @@ defmodule Plausible.SitesTest do
435435

436436
{:ok, _} = Sites.toggle_pin(pending_owner, site)
437437

438-
# excluded
438+
# excluded
439439
new_site(owner: owner, domain: "consolidated.example.com", consolidated: true)
440440
new_site(owner: pending_owner, domain: "consolidated2.example.com", consolidated: true)
441441

@@ -1021,4 +1021,28 @@ defmodule Plausible.SitesTest do
10211021
end
10221022
end
10231023
end
1024+
1025+
describe "shared_link_url/2" do
1026+
test "contains base URL and slug" do
1027+
site = new_site(domain: "example.com/deep/path")
1028+
link = insert(:shared_link, site: site)
1029+
1030+
# base url in tests is http://localhost:8000, in prod, it's https://plausible.io
1031+
assert "http://localhost:8000/share/example.com%2Fdeep%2Fpath?auth=" <> slug =
1032+
Sites.shared_link_url(site, link)
1033+
1034+
# we assume slug is URL safe
1035+
assert ^slug = link.slug
1036+
end
1037+
1038+
test "doesn't share the same domain formatting with public dashboard links" do
1039+
site = new_site(domain: "a-café.fr")
1040+
link = insert(:shared_link, site: site)
1041+
1042+
assert "http://localhost:8000/a-café.fr" = PlausibleWeb.StatsView.pretty_stats_url(site)
1043+
1044+
assert "http://localhost:8000/share/a-caf%C3%A9.fr?" <> _q =
1045+
Sites.shared_link_url(site, link)
1046+
end
1047+
end
10241048
end

test/plausible_web/live/shared_link_settings_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@ defmodule PlausibleWeb.Live.SharedLinkSettingsTest do
7979
site: site,
8080
session: session
8181
} do
82-
_link_with_password =
82+
link_with_password =
8383
insert(:shared_link, site: site, name: "Protected", password: "secret")
8484

85-
_link_without_password = insert(:shared_link, site: site, name: "Public")
85+
link_without_password = insert(:shared_link, site: site, name: "Public")
8686

8787
lv = get_liveview(conn, session)
8888
html = render(lv)
8989

9090
assert html =~ "Protected"
91+
assert html =~ "value=\"#{Plausible.Sites.shared_link_url(site, link_with_password)}\""
92+
9193
assert html =~ "Public"
94+
assert html =~ "value=\"#{Plausible.Sites.shared_link_url(site, link_without_password)}\""
95+
9296
# Check for lock icons
9397
assert element_exists?(html, ~s|svg|)
9498
end

0 commit comments

Comments
 (0)