diff --git a/lib/kmxgit/repository_manager.ex b/lib/kmxgit/repository_manager.ex
index c60f8b0..b154719 100644
--- a/lib/kmxgit/repository_manager.ex
+++ b/lib/kmxgit/repository_manager.ex
@@ -12,6 +12,19 @@ defmodule Kmxgit.RepositoryManager do
alias Kmxgit.UserManager
alias Kmxgit.UserManager.User
+ def list_all_repositories() do
+ from(r in Repository)
+ |> join(:full, [r], o in Organisation, on: o.id == r.organisation_id)
+ |> join(:full, [r, o], os in Slug, on: os.organisation_id == o.id)
+ |> join(:full, [r, o, os], u in User, on: u.id == r.user_id)
+ |> join(:full, [r, o, os, u], us in Slug, on: us.user_id == u.id)
+ |> where([r, o, os, u, us], not is_nil(r))
+ |> order_by([r, o, os, u, us], [fragment("concat(lower(?), lower(?))", os.slug, us.slug), :slug])
+ |> preload([members: :slug,
+ organisation: [:slug, users: :slug],
+ user: :slug])
+ end
+
def list_repositories(params \\ %IndexParams{}) do
update_disk_usage()
from(r in Repository)
diff --git a/lib/kmxgit/user_manager.ex b/lib/kmxgit/user_manager.ex
index 0eea9ff..1df8014 100644
--- a/lib/kmxgit/user_manager.ex
+++ b/lib/kmxgit/user_manager.ex
@@ -11,6 +11,12 @@ defmodule Kmxgit.UserManager do
alias Kmxgit.SlugManager.Slug
alias Kmxgit.UserManager.{Avatar, User, UserToken, UserNotifier}
+ def list_all_users() do
+ from(u in User)
+ |> join(:inner, [u], s in Slug, on: s.user_id == u.id)
+ |> order_by([u, s], fragment("lower(?)", s.slug))
+ end
+
def list_users(params \\ %IndexParams{}) do
update_disk_usage()
from(u in User)
diff --git a/lib/kmxgit_web/controllers/page_controller.ex b/lib/kmxgit_web/controllers/page_controller.ex
index 9dcf406..6d491c2 100644
--- a/lib/kmxgit_web/controllers/page_controller.ex
+++ b/lib/kmxgit_web/controllers/page_controller.ex
@@ -12,7 +12,7 @@ defmodule KmxgitWeb.PageController do
alias Kmxgit.UserManager.{Guardian, User}
def auth(conn, _params) do
- a = RepositoryManager.list_repositories
+ a = RepositoryManager.list_all_repositories()
|> Enum.sort(fn a, b ->
Repository.full_slug(a) < Repository.full_slug(b)
end)
@@ -43,9 +43,9 @@ defmodule KmxgitWeb.PageController do
end
def keys(conn, _params) do
- k1 = UserManager.list_users
+ k1 = UserManager.list_all_users
|> Enum.map(&User.ssh_keys_with_env/1)
- k2 = RepositoryManager.list_repositories
+ k2 = RepositoryManager.list_all_repositories
|> Enum.map(&Repository.deploy_keys_with_env/1)
k = (k1 ++ k2) |> Enum.join("\n")
conn
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 8caacd0..04caf1b 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -211,7 +211,7 @@ defmodule KmxgitWeb.RepositoryController do
git
end
- defp git_put_files(git, repo, nil, subdir, conn) do
+ defp git_put_files(git, _, nil, _, _) do
git
end
defp git_put_files(git = %{valid: true}, repo, tree, subdir, conn) do