Commit 34da73a49557134f7311058c671e8f0dadfe30fb

Thomas de Grivel 2021-12-14T10:21:16

fix public access for newly created repos

diff --git a/lib/kmxgit_web/controllers/admin/repository_controller.ex b/lib/kmxgit_web/controllers/admin/repository_controller.ex
index 90b9b90..b0b927a 100644
--- a/lib/kmxgit_web/controllers/admin/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/repository_controller.ex
@@ -50,13 +50,21 @@ defmodule KmxgitWeb.Admin.RepositoryController do
   defp create_repo(conn, owner, params) do
     case Repo.transaction(fn ->
           case RepositoryManager.create_repository(owner, params) do
-            {:ok, repo} -> repo
+            {:ok, repo} ->
+              case GitManager.create(Repository.full_slug(repo)) do
+                {:ok, _} -> repo
+                {:error, e} ->
+                  repo
+                  |> Repository.changeset(params)
+                  |> Ecto.Changeset.add_error(:git, e)
+                  |> Repo.rollback
+              end
             {:error, changeset} -> Repo.rollback changeset
           end
         end) do
       {:ok, repo} ->
         case GitManager.update_auth() do
-          :ok -> nil
+          :ok -> :ok = GitManager.public_access(Repository.full_slug(repo), repo.public_access)
           error -> IO.inspect(error)
         end
         conn
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 7e08a64..77333b2 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -68,7 +68,7 @@ defmodule KmxgitWeb.RepositoryController do
                 {:ok, _} -> repo
                 {:error, e} ->
                   repo
-                  |> Repository.changeset(%{})
+                  |> Repository.changeset(params)
                   |> Ecto.Changeset.add_error(:git, e)
                   |> Repo.rollback
               end
@@ -78,7 +78,7 @@ defmodule KmxgitWeb.RepositoryController do
         end) do
       {:ok, repo} ->
         case GitManager.update_auth() do
-          :ok -> nil
+          :ok -> :ok = GitManager.public_access(Repository.full_slug(repo), repo.public_access)
           error -> IO.inspect(error)
         end
         conn