From 9fdda9008534c53e399adc36fe1a880bbe41ce56 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 2 Jun 2021 13:03:59 +0100 Subject: Fix case change in ownernames (#16045) If you change the case of a username the change needs to be propagated to their repositories. Signed-off-by: Andrew Thornton --- models/repo.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index daa94c0d50..58a393ae70 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1350,6 +1350,26 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) { return sess.Commit() } +// UpdateRepositoryOwnerNames updates repository owner_names (this should only be used when the ownerName has changed case) +func UpdateRepositoryOwnerNames(ownerID int64, ownerName string) error { + if ownerID == 0 { + return nil + } + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + if _, err := sess.Where("owner_id = ?", ownerID).Cols("owner_name").Update(&Repository{ + OwnerName: ownerName, + }); err != nil { + return err + } + + return sess.Commit() +} + // UpdateRepositoryUpdatedTime updates a repository's updated time func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error { _, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID) -- cgit v1.2.3