Commit d4e7c7f9d3cbcca727322e019b87c65c62baa018

Thomas de Grivel 2021-11-29T17:21:49

fix slug

diff --git a/bin/update_auth b/bin/update_auth
deleted file mode 100755
index 8676ea4..0000000
--- a/bin/update_auth
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-set -e
-cd /etc/git
-ftp -o auth.conf https://git.kmx.io/_etc/git/auth.conf
diff --git a/bin/update_etc_git_auth b/bin/update_etc_git_auth
new file mode 100755
index 0000000..8676ea4
--- /dev/null
+++ b/bin/update_etc_git_auth
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -e
+cd /etc/git
+ftp -o auth.conf https://git.kmx.io/_etc/git/auth.conf
diff --git a/lib/kmxgit/repository_manager/repository.ex b/lib/kmxgit/repository_manager/repository.ex
index 322d2ba..4920f5d 100644
--- a/lib/kmxgit/repository_manager/repository.ex
+++ b/lib/kmxgit/repository_manager/repository.ex
@@ -9,7 +9,7 @@ defmodule Kmxgit.RepositoryManager.Repository do
   schema "repositories" do
     field :description, :string
     belongs_to :organisation, Organisation
-    field :slug, :string, unique: true
+    field :slug, :string
     belongs_to :user, User
     many_to_many :members, User, join_through: "users_repositories", on_replace: :delete, on_delete: :delete_all
     timestamps()
@@ -20,10 +20,20 @@ defmodule Kmxgit.RepositoryManager.Repository do
     |> cast(attrs, [:description, :slug])
     |> validate_required([:slug])
     |> validate_format(:slug, ~r|^[A-Za-z][-_+.@0-9A-Za-z]{0,64}(/[A-Za-z][-_+.@0-9A-Za-z]{0,64})*$|)
-    |> unique_constraint(:slug, name: "repositories__lower_slug_index")
+    |> validate_slug_uniqueness()
     |> Markdown.validate_markdown(:description)
   end
 
+  def validate_slug_uniqueness(changeset = %Ecto.Changeset{changes: %{slug: slug}}) do
+    IO.inspect [changeset, slug]
+    changeset
+  end
+
+  def validate_slug_uniqueness(changeset) do
+    IO.inspect changeset
+    changeset
+  end
+
   def owner(%__MODULE__{organisation: org = %Organisation{}}) do
     org
   end