Commit f4b0129ba4235b4727cdd3f89db87ca13cca203a

Thomas de Grivel 2022-02-19T17:55:22

hide private repos

diff --git a/README.md b/README.md
index ccf40e9..f801096 100644
--- a/README.md
+++ b/README.md
@@ -157,6 +157,7 @@ location ~ ^(.*/info/refs|.*/git-upload-pack)$ {
    - DONE search
    - DONE pagination (50 per page)
    - DONE link to livedashboard
+ - DONE Hide private repos from public index
  - Releases
    - infos
    - static files
diff --git a/config/config.exs b/config/config.exs
index f639307..7760f7e 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,10 +1,3 @@
-# This file is responsible for configuring your application
-# and its dependencies with the aid of the Config module.
-#
-# This configuration file is loaded before any dependency and
-# is restricted to this project.
-
-# General application configuration
 import Config
 
 config :kmxgit,
diff --git a/lib/kmxgit_web/controllers/slug_controller.ex b/lib/kmxgit_web/controllers/slug_controller.ex
index d4fde39..e3449d2 100644
--- a/lib/kmxgit_web/controllers/slug_controller.ex
+++ b/lib/kmxgit_web/controllers/slug_controller.ex
@@ -11,6 +11,7 @@ defmodule KmxgitWeb.SlugController do
   alias KmxgitWeb.UserView
 
   def show(conn, params) do
+    current_user = conn.assigns.current_user
     slug = SlugManager.get_slug(params["slug"])
     if !slug do
       not_found(conn)
@@ -20,6 +21,9 @@ defmodule KmxgitWeb.SlugController do
         owned_repos = User.owned_repositories(user)
         contributor_repos = RepositoryManager.list_contributor_repositories(user)
         repos = owned_repos ++ contributor_repos
+        |> Enum.filter(fn repo ->
+          repo.public_access || Repository.member?(repo, current_user)
+        end)
         conn
         |> assign(:disk_usage, User.disk_usage(user))
         |> assign(:disk_usage_all, Repository.disk_usage(repos))