mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-22 06:06:18 +00:00
Update org name on login (#3409)
and create a new org once a user is created (logged in for the first time) closes https://github.com/woodpecker-ci/woodpecker/issues/3342 --------- Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
364d708923
commit
bf0a9455ce
1 changed files with 29 additions and 0 deletions
|
@ -116,9 +116,38 @@ func HandleAuth(c *gin.Context) {
|
|||
// the user was stored as org. now we adopt it to the user.
|
||||
if org, err := _store.OrgFindByName(u.Login); err == nil && org != nil {
|
||||
org.IsUser = true
|
||||
u.OrgID = org.ID
|
||||
if err := _store.OrgUpdate(org); err != nil {
|
||||
log.Error().Err(err).Msgf("on user creation, could not mark org as user")
|
||||
}
|
||||
} else {
|
||||
if err != nil && !errors.Is(err, types.RecordNotExist) {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
org = &model.Org{
|
||||
Name: u.Login,
|
||||
IsUser: true,
|
||||
Private: false,
|
||||
}
|
||||
if err := _store.OrgCreate(org); err != nil {
|
||||
log.Error().Err(err).Msgf("on user creation, could create org for user")
|
||||
}
|
||||
u.OrgID = org.ID
|
||||
}
|
||||
}
|
||||
|
||||
// update org name
|
||||
if u.Login != tmpuser.Login {
|
||||
org, err := _store.OrgGet(u.OrgID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("cannot get org %s", u.Login)
|
||||
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=internal_error")
|
||||
return
|
||||
}
|
||||
org.Name = u.Login
|
||||
if err := _store.OrgUpdate(org); err != nil {
|
||||
log.Error().Err(err).Msgf("on user creation, could not mark org as user")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue