diff --git a/lib/plausible/auth/api_key.ex b/lib/plausible/auth/api_key.ex index 71fcd111b..13c700d3e 100644 --- a/lib/plausible/auth/api_key.ex +++ b/lib/plausible/auth/api_key.ex @@ -5,6 +5,7 @@ defmodule Plausible.Auth.ApiKey do @required [:user_id, :key, :name] schema "api_keys" do field :name, :string + field :key, :string, virtual: true field :key_hash, :string field :key_prefix, :string diff --git a/lib/plausible/site/shared_link.ex b/lib/plausible/site/shared_link.ex index a63c3f59b..e01c582f8 100644 --- a/lib/plausible/site/shared_link.ex +++ b/lib/plausible/site/shared_link.ex @@ -17,6 +17,7 @@ defmodule Plausible.Site.SharedLink do |> cast(attrs, [:slug, :password, :name]) |> validate_required([:slug, :name]) |> unique_constraint(:slug) + |> unique_constraint(:name, name: :shared_links_site_id_name_index) |> hash_password() end diff --git a/lib/plausible_web/templates/site/edit_shared_link.html.eex b/lib/plausible_web/templates/site/edit_shared_link.html.eex index 00b98d0b3..e36d12fb9 100644 --- a/lib/plausible_web/templates/site/edit_shared_link.html.eex +++ b/lib/plausible_web/templates/site/edit_shared_link.html.eex @@ -8,5 +8,5 @@ - <%= submit "Edit shared link", class: "button mt-4 w-full" %> + <%= submit "Update", class: "button mt-4 w-full" %> <% end %> diff --git a/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs b/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs new file mode 100644 index 000000000..585e79de2 --- /dev/null +++ b/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs @@ -0,0 +1,7 @@ +defmodule Plausible.Repo.Migrations.AddUniqueIndexToSharedLinkName do + use Ecto.Migration + + def change do + create unique_index(:shared_links, [:site_id, :name], name: :shared_links_site_id_name_index) + end +end