diff --git a/config/config.exs b/config/config.exs
index a7beeb4..68b1887 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -8,6 +8,7 @@
import Config
config :kmxgit,
+ ssh_url: "git@git.kmx.io",
ecto_repos: [Kmxgit.Repo]
# Configures the endpoint
diff --git a/lib/kmxgit/organisation_manager.ex b/lib/kmxgit/organisation_manager.ex
index c368af7..c896ffe 100644
--- a/lib/kmxgit/organisation_manager.ex
+++ b/lib/kmxgit/organisation_manager.ex
@@ -8,7 +8,11 @@ defmodule Kmxgit.OrganisationManager do
alias Kmxgit.UserManager
def list_organisations do
- Repo.all from org in Organisation, preload: :slug
+ Repo.all from org in Organisation,
+ join: s in Slug,
+ on: s.organisation_id == org.id,
+ preload: :slug,
+ order_by: s.slug
end
def get_organisation!(id) do
diff --git a/lib/kmxgit/organisation_manager/organisation.ex b/lib/kmxgit/organisation_manager/organisation.ex
index eb255e1..91acb68 100644
--- a/lib/kmxgit/organisation_manager/organisation.ex
+++ b/lib/kmxgit/organisation_manager/organisation.ex
@@ -11,7 +11,7 @@ defmodule Kmxgit.OrganisationManager.Organisation do
field :description, :string
field :name, :string
has_many :owned_repositories, Repository
- many_to_many :users, User, join_through: "users_organisations", on_delete: :delete_all, on_replace: :delete
+ many_to_many :users, User, join_through: "users_organisations", on_replace: :delete, on_delete: :delete_all
has_one :slug, Slug, on_delete: :delete_all
timestamps()
end
diff --git a/lib/kmxgit/repository_manager.ex b/lib/kmxgit/repository_manager.ex
index 8fe92e1..3eaed38 100644
--- a/lib/kmxgit/repository_manager.ex
+++ b/lib/kmxgit/repository_manager.ex
@@ -10,10 +10,11 @@ defmodule Kmxgit.RepositoryManager do
alias Kmxgit.UserManager.User
def list_repositories do
- Repo.all from r in Repository,
+ Repo.all(from r in Repository,
preload: [members: :slug,
organisation: [:slug, users: :slug],
- user: :slug]
+ user: :slug])
+ |> Enum.sort_by(fn x -> Repository.full_slug(x) end)
end
def change_repository(repository \\ %Repository{}) do
diff --git a/lib/kmxgit/repository_manager/repository.ex b/lib/kmxgit/repository_manager/repository.ex
index 5a765e2..0381e85 100644
--- a/lib/kmxgit/repository_manager/repository.ex
+++ b/lib/kmxgit/repository_manager/repository.ex
@@ -39,6 +39,11 @@ defmodule Kmxgit.RepositoryManager.Repository do
"#{owner_slug(repo)}/#{repo.slug}"
end
+ def ssh_url(repo) do
+ ssh_root = Application.get_env(:kmxgit, :ssh_url)
+ "#{ssh_root}:#{full_slug(repo)}.git"
+ end
+
def splat(repo) do
String.split(repo.slug, "/")
end
diff --git a/lib/kmxgit/user_manager.ex b/lib/kmxgit/user_manager.ex
index ab8321a..c0f95b0 100644
--- a/lib/kmxgit/user_manager.ex
+++ b/lib/kmxgit/user_manager.ex
@@ -18,10 +18,10 @@ defmodule Kmxgit.UserManager do
def get_user!(id) do
user = Repo.one(from user in User,
where: [id: ^id],
- preload: [organisations: :slug],
- preload: [owned_repositories: [organisation: :slug, user: :slug]],
- preload: :slug
- )
+ preload: [:slug,
+ organisations: :slug,
+ owned_repositories: [organisation: :slug,
+ user: :slug]])
user || raise Ecto.NoResultsError
end
diff --git a/lib/kmxgit_web/router.ex b/lib/kmxgit_web/router.ex
index 861adc1..852e183 100644
--- a/lib/kmxgit_web/router.ex
+++ b/lib/kmxgit_web/router.ex
@@ -33,11 +33,11 @@ defmodule KmxgitWeb.Router do
scope "/", KmxgitWeb do
pipe_through [:browser, :auth]
- get "/", PageController, :index
- get "/_etc/auth.conf", PageController, :auth
- get "/_etc/authorized_keys", PageController, :keys
- get "/_new_admin", PageController, :new_admin
- post "/_new_admin", PageController, :new_admin_post
+ get "/", PageController, :index
+ get "/_etc/git/auth.conf", PageController, :auth
+ get "/_etc/ssh/authorized_keys", PageController, :keys
+ get "/_new_admin", PageController, :new_admin
+ post "/_new_admin", PageController, :new_admin_post
scope "/_sessions" do
get "/new", SessionController, :new
diff --git a/lib/kmxgit_web/templates/organisation/show.html.heex b/lib/kmxgit_web/templates/organisation/show.html.heex
index a70a157..0124ded 100644
--- a/lib/kmxgit_web/templates/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/organisation/show.html.heex
@@ -47,11 +47,8 @@
</td>
</tr>
<tr>
- <th><%= gettext "Users" %></th>
- <td>
- <%= for user <- @org.users do %>
- <%= link(user.slug.slug, to: Routes.slug_path(@conn, :show, user.slug.slug), class: "user") %>
- <% end %>
+ <th>
+ <%= gettext "Users" %><br/>
<%= if Enum.find(@org.users, &(&1.id == @current_user.id)) do %>
<%= link "-",
to: Routes.organisation_path(@conn, :remove_user, @org.slug.slug),
@@ -60,6 +57,15 @@
to: Routes.organisation_path(@conn, :add_user, @org.slug.slug),
class: "btn btn-primary btn-sm" %>
<% end %>
+ </th>
+ <td>
+ <ul>
+ <%= for user <- @org.users do %>
+ <li>
+ <%= link(user.slug.slug, to: Routes.slug_path(@conn, :show, user.slug.slug), class: "user") %>
+ </li>
+ <% end %>
+ </ul>
</td>
</tr>
</table>
diff --git a/lib/kmxgit_web/templates/repository/show.html.heex b/lib/kmxgit_web/templates/repository/show.html.heex
index c719d25..f6cf2b2 100644
--- a/lib/kmxgit_web/templates/repository/show.html.heex
+++ b/lib/kmxgit_web/templates/repository/show.html.heex
@@ -45,6 +45,10 @@
<h2><%= gettext "Properties" %></h2>
<table class="table admin-properties">
<tr>
+ <th><%= gettext "SSH" %></th>
+ <td><%= Repository.ssh_url(@repo) %></td>
+ </tr>
+ <tr>
<th><%= gettext "Description" %></th>
<td>
<%= if @repo.description do %>
@@ -53,17 +57,23 @@
</td>
</tr>
<tr>
- <th><%= gettext "Users" %></th>
- <td>
- <%= for user <- @members do %>
- <%= link user.slug.slug, to: Routes.slug_path(@conn, :show, user.slug.slug) %>
- <% end %>
+ <th>
+ <%= gettext "Users" %><br/>
<%= link "-",
to: Routes.repository_path(@conn, :remove_user, @owner.slug.slug, Repository.splat(@repo)),
class: "btn btn-danger btn-sm" %>
<%= link "+",
to: Routes.repository_path(@conn, :add_user, @owner.slug.slug, Repository.splat(@repo)),
class: "btn btn-primary btn-sm" %>
+ </th>
+ <td>
+ <ul>
+ <%= for user <- @members do %>
+ <li>
+ <%= link user.slug.slug, to: Routes.slug_path(@conn, :show, user.slug.slug) %>
+ </li>
+ <% end %>
+ </ul>
</td>
</tr>
</table>
diff --git a/lib/kmxgit_web/templates/user/show.html.heex b/lib/kmxgit_web/templates/user/show.html.heex
index 38bb2d7..65bb7a8 100644
--- a/lib/kmxgit_web/templates/user/show.html.heex
+++ b/lib/kmxgit_web/templates/user/show.html.heex
@@ -55,7 +55,7 @@
</tr>
<tr>
<th>
- <%= gettext "Organisations" %>
+ <%= gettext "Organisations" %><br/>
<%= if @user == @current_user do %>
<%= link("+", to: Routes.organisation_path(@conn, :new), class: "btn btn-primary btn-sm") %>
<% end %>