From dc8d20496cf66de2abcdfa50877aaa5b6d68fc86 Mon Sep 17 00:00:00 2001
From: Uku Taht
Date: Tue, 14 Dec 2021 12:10:34 +0200
Subject: [PATCH] Show locked message in shared link
---
.../controllers/stats_controller.ex | 42 ++++++++++++-------
.../templates/stats/site_locked.html.eex | 8 ++--
.../stats/waiting_first_pageview.html.eex | 8 ++--
.../controllers/stats_controller_test.exs | 10 +++++
4 files changed, 45 insertions(+), 23 deletions(-)
diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex
index 10058c50d..7641e20d3 100644
--- a/lib/plausible_web/controllers/stats_controller.ex
+++ b/lib/plausible_web/controllers/stats_controller.ex
@@ -162,22 +162,32 @@ defmodule PlausibleWeb.StatsController do
end
defp render_shared_link(conn, shared_link) do
- conn
- |> assign(:skip_plausible_tracking, true)
- |> put_resp_header("x-robots-tag", "noindex")
- |> delete_resp_header("x-frame-options")
- |> render("stats.html",
- site: shared_link.site,
- has_goals: Plausible.Sites.has_goals?(shared_link.site),
- title: "Plausible · " <> shared_link.site.domain,
- offer_email_report: false,
- demo: false,
- skip_plausible_tracking: true,
- shared_link_auth: shared_link.slug,
- embedded: conn.params["embed"] == "true",
- background: conn.params["background"],
- theme: conn.params["theme"]
- )
+ cond do
+ !shared_link.site.locked ->
+ conn
+ |> assign(:skip_plausible_tracking, true)
+ |> put_resp_header("x-robots-tag", "noindex")
+ |> delete_resp_header("x-frame-options")
+ |> render("stats.html",
+ site: shared_link.site,
+ has_goals: Plausible.Sites.has_goals?(shared_link.site),
+ title: "Plausible · " <> shared_link.site.domain,
+ offer_email_report: false,
+ demo: false,
+ skip_plausible_tracking: true,
+ shared_link_auth: shared_link.slug,
+ embedded: conn.params["embed"] == "true",
+ background: conn.params["background"],
+ theme: conn.params["theme"]
+ )
+
+ shared_link.site.locked ->
+ owner = Plausible.Sites.owner_for(shared_link.site)
+
+ conn
+ |> assign(:skip_plausible_tracking, true)
+ |> render("site_locked.html", owner: owner, site: shared_link.site)
+ end
end
defp remove_email_report_banner(conn, site) do
diff --git a/lib/plausible_web/templates/stats/site_locked.html.eex b/lib/plausible_web/templates/stats/site_locked.html.eex
index abb775276..bbe71587c 100644
--- a/lib/plausible_web/templates/stats/site_locked.html.eex
+++ b/lib/plausible_web/templates/stats/site_locked.html.eex
@@ -38,9 +38,11 @@
This site is currently locked and cannot be accessed. You can check back later or contact the site owner to unlock it.
-
- <%= link("Back to my sites", to: "/sites", class: "inline-flex items-center px-4 py-2 border border-transparent shadow-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:text-sm") %>
-
+ <%= if @conn.assigns[:current_user] do %>
+
+ <%= link("Back to my sites", to: "/sites", class: "inline-flex items-center px-4 py-2 border border-transparent shadow-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:text-sm") %>
+
+ <% end %>
<% end %>
diff --git a/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex b/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex
index 01774ae66..91c896633 100644
--- a/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex
+++ b/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex
@@ -20,12 +20,12 @@
- Need to see the snippet again? <%= link("Click here", to: "/#{URI.encode_www_form(@site.domain)}/snippet", class: "text-indigo-600 text-underline")%>
- Not working? <%= link("Troubleshoot the integration", to: "https://plausible.io/docs/troubleshoot-integration#keep-seeing-a-blinking-green-dot", class: "text-indigo-600 text-underline", rel: "noreferrer") %> with our guide
+ Need to see the snippet again? <%= link("Click here", to: "/#{URI.encode_www_form(@site.domain)}/snippet", class: "text-indigo-600 dark:text-indigo-500 text-underline")%>
+ Not working? <%= link("Troubleshoot the integration", to: "https://plausible.io/docs/troubleshoot-integration#keep-seeing-a-blinking-green-dot", class: "text-indigo-600 dark:text-indigo-500 text-underline", rel: "noreferrer") %> with our guide
<%= if Application.get_env(:plausible, :is_selfhost) do %>
- first
Still not working? Ask on our <%= link("community-supported forum", to: "https://github.com/plausible/analytics/discussions", class: "text-indigo-600 text-underline" ) %>
+ first
Still not working? Ask on our <%= link("community-supported forum", to: "https://github.com/plausible/analytics/discussions", class: "text-indigo-600 dark:text-indigo-500 text-underline" ) %>
<% else %>
- first
Still not working? <%= link("Contact us", to: "https://plausible.io/contact", class: "text-indigo-600 text-underline" ) %> and we will help you with your setup
+ first
Still not working? <%= link("Contact us", to: "https://plausible.io/contact", class: "text-indigo-600 dark:text-indigo-500 text-underline" ) %> and we will help you with your setup
<% end %>
diff --git a/test/plausible_web/controllers/stats_controller_test.exs b/test/plausible_web/controllers/stats_controller_test.exs
index b7bc91be5..207dea888 100644
--- a/test/plausible_web/controllers/stats_controller_test.exs
+++ b/test/plausible_web/controllers/stats_controller_test.exs
@@ -193,6 +193,16 @@ defmodule PlausibleWeb.StatsControllerTest do
conn = get(conn, "/share/test-site.com/?auth=#{link.slug}")
assert Plug.Conn.get_resp_header(conn, "x-frame-options") == []
end
+
+ test "shows locked page if page is locked", %{conn: conn} do
+ site = insert(:site, domain: "test-site.com", locked: true)
+ link = insert(:shared_link, site: site)
+
+ conn = get(conn, "/share/test-site.com/?auth=#{link.slug}")
+
+ assert html_response(conn, 200) =~ "Site locked"
+ refute String.contains?(html_response(conn, 200), "Back to my sites")
+ end
end
describe "POST /share/:slug/authenticate" do