mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-20 08:51:01 +00:00
sync repo permissions on login (#1853)
if indeed a bug, fixes #1851 after re-log close #1666
This commit is contained in:
parent
eaae6b44c7
commit
a958049485
1 changed files with 29 additions and 0 deletions
|
@ -145,6 +145,35 @@ func HandleAuth(c *gin.Context) {
|
|||
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)
|
||||
|
||||
c.Redirect(http.StatusSeeOther, "/")
|
||||
|
|
Loading…
Reference in a new issue