diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-12-12 15:05:26 +0100 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-12-12 15:05:26 +0100 |
commit | fa7b51a709413a214fbd5157fe0f32138a889f0d (patch) | |
tree | 81fe7ab4e63ffc90d0392a17fadd7a79d893c95b /pkg/handler | |
parent | 1059bc71871c14b813b0bb27b4601e2c2ac65acd (diff) | |
download | cerrado-fa7b51a709413a214fbd5157fe0f32138a889f0d.tar.gz cerrado-fa7b51a709413a214fbd5157fe0f32138a889f0d.tar.bz2 cerrado-fa7b51a709413a214fbd5157fe0f32138a889f0d.zip |
feat: Filter private repository from the UIv0.0.17
Now the whole application takes public into account.
Diffstat (limited to 'pkg/handler')
-rw-r--r-- | pkg/handler/git/handler.go | 13 | ||||
-rw-r--r-- | pkg/handler/router.go | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index 4276159..6225b1a 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -13,6 +13,7 @@ import ( "git.gabrielgio.me/cerrado/pkg/ext" "git.gabrielgio.me/cerrado/pkg/service" + "git.gabrielgio.me/cerrado/pkg/u" "git.gabrielgio.me/cerrado/templates" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/formatters/html" @@ -44,11 +45,19 @@ func NewGitHandler(gitService *service.GitService, confRepo configurationReposit } func (g *GitHandler) List(w http.ResponseWriter, r *http.Request) error { + // this is the only handler that needs to handle authentication itself. + // everything else relay on name path parameter + logged := ext.IsLoggedIn(r.Context()) + repos, err := g.gitService.ListRepositories() if err != nil { return err } + if !logged { + repos = u.Filter(repos, isPublic) + } + f, err := os.Open(g.config.GetRootReadme()) if err != nil { return err @@ -375,3 +384,7 @@ func GetLexers(filename string) chroma.Lexer { } return lexer } + +func isPublic(r *service.Repository) bool { + return r.Public +} diff --git a/pkg/handler/router.go b/pkg/handler/router.go index 82ee8fd..8d27b74 100644 --- a/pkg/handler/router.go +++ b/pkg/handler/router.go @@ -34,6 +34,7 @@ func MountHandler( mux := ext.NewRouter() mux.AddMiddleware(ext.Compress) mux.AddMiddleware(ext.Log) + mux.AddMiddleware(ext.VerifyRespository(configRepo)) if configRepo.IsAuthEnabled() { mux.AddMiddleware(ext.Authenticate(authService)) |