Config: per-user overrides for some settings

Allow per-user overrides for AppendOnly and PrivateRepos.
This commit is contained in:
Konrad Wojas 2021-01-08 19:53:42 +08:00
parent 383514ad7a
commit 36c7652c9b

View file

@ -83,8 +83,20 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// Allow per-user overrides
appendOnly := s.AppendOnly
privateRepos := s.PrivateRepos
if uc, ok := s.Config.Users[username]; ok {
if uc.AppendOnly != nil {
appendOnly = *uc.AppendOnly
}
if uc.PrivateRepos != nil {
privateRepos = *uc.PrivateRepos
}
}
// Check if the current user is allowed to access this path
if !s.NoAuth && s.PrivateRepos {
if !s.NoAuth && privateRepos {
if len(folderPath) == 0 || folderPath[0] != username {
httpDefaultError(w, http.StatusUnauthorized)
return
@ -102,7 +114,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Pass the request to the repo.Handler
opt := repo.Options{
AppendOnly: s.AppendOnly,
AppendOnly: appendOnly,
Debug: s.Debug,
QuotaManager: s.quotaManager, // may be nil
PanicOnError: s.PanicOnError,