Fix shared link hostname (#5870)
* Fix missing share link hostname * Update changelog * Tests
This commit is contained in:
parent
2ca24e77cc
commit
af7dd46458
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue