sync repo permissions on login (#1853)

if indeed a bug, fixes #1851 after re-log

close #1666
This commit is contained in:
Benedikt Kleiner 2023-06-24 10:08:34 +02:00 committed by GitHub
parent eaae6b44c7
commit a958049485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -145,6 +145,35 @@ func HandleAuth(c *gin.Context) {
return return
} }
repos, _ := server.Config.Services.Forge.Repos(c, u)
for _, forgeRepo := range repos {
dbRepo, err := _store.GetRepoForgeID(forgeRepo.ForgeRemoteID)
if err != nil && errors.Is(err, types.RecordNotExist) {
continue
}
if err != nil {
log.Error().Msgf("cannot list repos for %s. %s", u.Login, err)
c.Redirect(http.StatusSeeOther, "/login?error=internal_error")
return
}
if !dbRepo.IsActive {
continue
}
log.Debug().Msgf("Synced user permission for %s %s", u.Login, dbRepo.FullName)
perm := forgeRepo.Perm
perm.Repo = dbRepo
perm.RepoID = dbRepo.ID
perm.UserID = u.ID
perm.Synced = time.Now().Unix()
if err := _store.PermUpsert(perm); err != nil {
log.Error().Msgf("cannot update permissions for %s. %s", u.Login, err)
c.Redirect(http.StatusSeeOther, "/login?error=internal_error")
return
}
}
httputil.SetCookie(c.Writer, c.Request, "user_sess", tokenString) httputil.SetCookie(c.Writer, c.Request, "user_sess", tokenString)
c.Redirect(http.StatusSeeOther, "/") c.Redirect(http.StatusSeeOther, "/")