diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex index 4031388bc..ffdf8b7f9 100644 --- a/lib/plausible/sites.ex +++ b/lib/plausible/sites.ex @@ -19,14 +19,14 @@ defmodule Plausible.Sites do |> Repo.transaction() end - def create_shared_link(site, name) do + def create_shared_link(site, name, password \\ nil) do changes = SharedLink.changeset( %SharedLink{ site_id: site.id, slug: Nanoid.generate() }, - %{name: name} + %{name: name, password: password} ) Repo.insert(changes) diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 20bcd236f..633967c77 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -517,7 +517,7 @@ defmodule PlausibleWeb.SiteController do def create_shared_link(conn, %{"website" => website, "shared_link" => link}) do site = Sites.get_for_user!(conn.assigns[:current_user].id, website) - case Sites.create_shared_link(site, link["name"]) do + case Sites.create_shared_link(site, link["name"], link["password"]) do {:ok, _created} -> redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")