diff --git a/lib/kmxgit/git_manager.ex b/lib/kmxgit/git_manager.ex
index f7b5c5f..5c97151 100644
--- a/lib/kmxgit/git_manager.ex
+++ b/lib/kmxgit/git_manager.ex
@@ -52,7 +52,6 @@ defmodule Kmxgit.GitManager do
dir = git_dir(repo)
path1 = if path == "" do "." else path end
{out, status} = System.cmd("git", ["-C", dir, "ls-tree", tree, path1], stderr_to_stdout: true)
- IO.inspect {out, status}
case status do
0 ->
list = out
@@ -163,4 +162,19 @@ defmodule Kmxgit.GitManager do
end
end
end
+
+ def public_access(repo, true) do
+ dir = git_dir(repo)
+ if ! File.exists?(export = "#{dir}/git-daemon-export-ok") do
+ File.write!(export, "")
+ end
+ :ok
+ end
+ def public_access(repo, false) do
+ dir = git_dir(repo)
+ if File.exists?(export = "#{dir}/git-daemon-export-ok") do
+ File.rm!(export)
+ end
+ :ok
+ end
end
diff --git a/lib/kmxgit/repository_manager/repository.ex b/lib/kmxgit/repository_manager/repository.ex
index a8b0dcb..9156abc 100644
--- a/lib/kmxgit/repository_manager/repository.ex
+++ b/lib/kmxgit/repository_manager/repository.ex
@@ -119,8 +119,12 @@ defmodule Kmxgit.RepositoryManager.Repository do
"#{ssh_root}:#{full_slug(repo)}.git"
end
- def splat(repo) do
- String.split(repo.slug, "/")
+ def splat(repo, rest \\ []) do
+ String.split(repo.slug, "/") ++ rest
+ end
+
+ def git_splat(repo, rest \\ []) do
+ String.split("#{repo.slug}.git", "/") ++ rest
end
def owners(repo) do
diff --git a/lib/kmxgit_web.ex b/lib/kmxgit_web.ex
index eb72bf6..52ffa53 100644
--- a/lib/kmxgit_web.ex
+++ b/lib/kmxgit_web.ex
@@ -32,6 +32,13 @@ defmodule KmxgitWeb do
|> put_view(ErrorView)
|> render(:"404")
end
+
+ def forbidden(conn, _params \\ %{}) do
+ conn
+ |> put_status(403)
+ |> put_view(ErrorView)
+ |> render(:"403")
+ end
end
end
diff --git a/lib/kmxgit_web/controllers/admin/repository_controller.ex b/lib/kmxgit_web/controllers/admin/repository_controller.ex
index 6c0964a..90b9b90 100644
--- a/lib/kmxgit_web/controllers/admin/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/repository_controller.ex
@@ -104,7 +104,7 @@ defmodule KmxgitWeb.Admin.RepositoryController do
end) do
{:ok, repo1} ->
case GitManager.update_auth() do
- :ok -> nil
+ :ok -> :ok = GitManager.public_access(Repository.full_slug(repo1), repo1.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 ccb8a8f..5a799d4 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -281,7 +281,7 @@ defmodule KmxgitWeb.RepositoryController do
end) do
{:ok, repo1} ->
case GitManager.update_auth() do
- :ok -> nil
+ :ok -> :ok = GitManager.public_access(Repository.full_slug(repo1), repo1.public_access)
error -> IO.inspect(error)
end
conn