mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-05 23:34:19 -04:00
Use db.WithTx for AddTeamMember to avoid ctx abuse (#27095)
Compare with ignoring spaces: https://github.com/go-gitea/gitea/pull/27095/files?diff=split&w=1
This commit is contained in:
parent
7046065c0e
commit
4ffc30cb84
@ -366,12 +366,7 @@ func AddTeamMember(ctx context.Context, team *organization.Team, userID int64) e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, committer, err := db.TxContext(ctx)
|
err = db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer committer.Close()
|
|
||||||
|
|
||||||
// check in transaction
|
// check in transaction
|
||||||
isAlreadyMember, err = organization.IsTeamMember(ctx, team.OrgID, team.ID, userID)
|
isAlreadyMember, err = organization.IsTeamMember(ctx, team.OrgID, team.ID, userID)
|
||||||
if err != nil || isAlreadyMember {
|
if err != nil || isAlreadyMember {
|
||||||
@ -422,13 +417,18 @@ func AddTeamMember(ctx context.Context, team *organization.Team, userID int64) e
|
|||||||
accesses = accesses[:0]
|
accesses = accesses[:0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// this behaviour may spend much time so run it in a goroutine
|
// this behaviour may spend much time so run it in a goroutine
|
||||||
// FIXME: Update watch repos batchly
|
// FIXME: Update watch repos batchly
|
||||||
if setting.Service.AutoWatchNewRepos {
|
if setting.Service.AutoWatchNewRepos {
|
||||||
// Get team and its repositories.
|
// Get team and its repositories.
|
||||||
if err := team.LoadRepositories(ctx); err != nil {
|
if err := team.LoadRepositories(ctx); err != nil {
|
||||||
log.Error("getRepositories failed: %v", err)
|
log.Error("team.LoadRepositories failed: %v", err)
|
||||||
}
|
}
|
||||||
// FIXME: in the goroutine, it can't access the "ctx", it could only use db.DefaultContext at the moment
|
// FIXME: in the goroutine, it can't access the "ctx", it could only use db.DefaultContext at the moment
|
||||||
go func(repos []*repo_model.Repository) {
|
go func(repos []*repo_model.Repository) {
|
||||||
@ -440,7 +440,7 @@ func AddTeamMember(ctx context.Context, team *organization.Team, userID int64) e
|
|||||||
}(team.Repos)
|
}(team.Repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
return committer.Commit()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeTeamMember(ctx context.Context, team *organization.Team, userID int64) error {
|
func removeTeamMember(ctx context.Context, team *organization.Team, userID int64) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user