Commit 25717797868a11706e81b635ffd3b5266d8c3af3

Thomas de Grivel 2021-12-10T09:42:59

sort repositories

diff --git a/lib/kmxgit/organisation_manager/organisation.ex b/lib/kmxgit/organisation_manager/organisation.ex
index e531c0c..180a0d2 100644
--- a/lib/kmxgit/organisation_manager/organisation.ex
+++ b/lib/kmxgit/organisation_manager/organisation.ex
@@ -32,4 +32,9 @@ defmodule Kmxgit.OrganisationManager.Organisation do
       u.id == user.id
     end)
   end
+
+  def owned_repositories(org) do
+    org.owned_repositories
+    |> Enum.sort_by(&Repository.full_slug/1)
+  end
 end
diff --git a/lib/kmxgit/user_manager/user.ex b/lib/kmxgit/user_manager/user.ex
index 9d382c2..6269be5 100644
--- a/lib/kmxgit/user_manager/user.ex
+++ b/lib/kmxgit/user_manager/user.ex
@@ -191,4 +191,9 @@ defmodule Kmxgit.UserManager.User do
     end)
     |> Enum.join("\n")
   end
+
+  def owned_repositories(user) do
+    user.owned_repositories
+    |> Enum.sort_by(&Repository.full_slug/1)
+  end
 end
diff --git a/lib/kmxgit_web/controllers/slug_controller.ex b/lib/kmxgit_web/controllers/slug_controller.ex
index 056f5f8..3c0b871 100644
--- a/lib/kmxgit_web/controllers/slug_controller.ex
+++ b/lib/kmxgit_web/controllers/slug_controller.ex
@@ -2,8 +2,8 @@ defmodule KmxgitWeb.SlugController do
   use KmxgitWeb, :controller
 
   alias Kmxgit.RepositoryManager
-  alias Kmxgit.RepositoryManager.Repository
   alias Kmxgit.SlugManager
+  alias Kmxgit.UserManager.User
   alias KmxgitWeb.ErrorView
   alias KmxgitWeb.OrganisationView
   alias KmxgitWeb.UserView
@@ -17,7 +17,7 @@ defmodule KmxgitWeb.SlugController do
       if user do
         conn
         |> assign(:contributor_repos, RepositoryManager.list_contributor_repositories(user))
-        |> assign(:owned_repos, user.owned_repositories |> Enum.sort_by(&Repository.full_slug/1))
+        |> assign(:owned_repos, User.owned_repositories(user))
         |> assign(:page_title, gettext("User %{login}", login: user.slug.slug))
         |> assign(:user, user)
         |> put_view(UserView)
diff --git a/lib/kmxgit_web/templates/organisation/show.html.heex b/lib/kmxgit_web/templates/organisation/show.html.heex
index 78b7609..9a1aa47 100644
--- a/lib/kmxgit_web/templates/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/organisation/show.html.heex
@@ -21,7 +21,7 @@
       <hr/>
       <h2><%= gettext "Repositories" %></h2>
       <ul>
-        <%= for repo <- @org.owned_repositories do %>
+        <%= for repo <- Organisation.owned_repositories(@org) do %>
           <li>
             <%= link Repository.full_slug(repo), to: Routes.repository_path(@conn, :show, @org.slug.slug, Repository.splat(repo)) %>
           </li>