- Add a password or leave it blank so anyone with the link can see the stats.
- Once the link is created, we cannot reveal the password. Please make sure you save it in a secure place.
-
-
- <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/#{link.slug}", method: :delete, class: "py-2 px-4 bg-gray-200 dark:bg-gray-850 text-red-600 dark:text-red-500 rounded-l-none hover:bg-gray-300 dark:hover:bg-gray-825", data: [confirm: "Are you sure you want to delete this shared link? The stats will not be accessible with this link anymore."]) do %>
-
- <% end %>
+
+
+
+
+
+ <%= link(to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/#{link.slug}/edit", class: "px-4 py-2 inline-flex items-center text-indigo-800 bg-gray-200 border-r border-gray-300 rounded-none dark:bg-gray-850 dark:text-indigo-500 dark:border-gray-500 hover:bg-gray-300 dark:hover:bg-gray-825") do %>
+
+ <% end %>
+ <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/#{link.slug}", method: :delete, class: "py-2 px-4 inline-flex items-center bg-gray-200 dark:bg-gray-850 text-red-600 dark:text-red-500 rounded-l-none hover:bg-gray-300 dark:hover:bg-gray-825", data: [confirm: "Are you sure you want to delete this shared link? The stats will not be accessible with this link anymore."]) do %>
+
+ <% end %>
+
<% end %>
diff --git a/priv/repo/migrations/20210406073254_add_name_to_shared_links.exs b/priv/repo/migrations/20210406073254_add_name_to_shared_links.exs
new file mode 100644
index 000000000..108c28f0f
--- /dev/null
+++ b/priv/repo/migrations/20210406073254_add_name_to_shared_links.exs
@@ -0,0 +1,15 @@
+defmodule Plausible.Repo.Migrations.AddNameToSharedLinks do
+ use Ecto.Migration
+
+ def change do
+ alter table(:shared_links) do
+ add :name, :string
+ end
+
+ execute "UPDATE shared_links SET name=slug"
+
+ alter table(:shared_links) do
+ modify :name, :string, null: false
+ end
+ end
+end
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index 88bbf82ac..81ce569cf 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -493,23 +493,54 @@ defmodule PlausibleWeb.SiteControllerTest do
setup [:create_user, :log_in, :create_site]
test "creates shared link without password", %{conn: conn, site: site} do
- post(conn, "/sites/#{site.domain}/shared-links", %{"shared_link" => %{}})
+ post(conn, "/sites/#{site.domain}/shared-links", %{
+ "shared_link" => %{"name" => "Link name"}
+ })
link = Repo.one(Plausible.Site.SharedLink)
refute is_nil(link.slug)
assert is_nil(link.password_hash)
+ assert link.name == "Link name"
end
test "creates shared link with password", %{conn: conn, site: site} do
post(conn, "/sites/#{site.domain}/shared-links", %{
- "shared_link" => %{"password" => "password"}
+ "shared_link" => %{"password" => "password", "name" => "New name"}
})
link = Repo.one(Plausible.Site.SharedLink)
refute is_nil(link.slug)
refute is_nil(link.password_hash)
+ assert link.name == "New name"
+ end
+ end
+
+ describe "GET /sites/:website/shared-links/edit" do
+ setup [:create_user, :log_in, :create_site]
+
+ test "shows form to edit shared link", %{conn: conn, site: site} do
+ link = insert(:shared_link, site: site)
+ conn = get(conn, "/sites/#{site.domain}/shared-links/#{link.slug}/edit")
+
+ assert html_response(conn, 200) =~ "Edit shared link"
+ end
+ end
+
+ describe "PUT /sites/:website/shared-links/:slug" do
+ setup [:create_user, :log_in, :create_site]
+
+ test "can update link name", %{conn: conn, site: site} do
+ link = insert(:shared_link, site: site)
+
+ put(conn, "/sites/#{site.domain}/shared-links/#{link.slug}", %{
+ "shared_link" => %{"name" => "Updated link name"}
+ })
+
+ link = Repo.one(Plausible.Site.SharedLink)
+
+ assert link.name == "Updated link name"
end
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 78e36018d..35f33739b 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -147,6 +147,7 @@ defmodule Plausible.Factory do
def shared_link_factory do
%Plausible.Site.SharedLink{
+ name: "Link name",
slug: Nanoid.generate()
}
end