summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormavenbline <42911384+mavenbline@users.noreply.github.com>2020-02-08 17:59:40 +0300
committerGitHub <noreply@github.com>2020-02-08 16:59:40 +0200
commit74a4a1e17f99d147db9329718a5ecc87984b0ecd (patch)
tree26c0e79473f178e6f3655f9f2f7055bd366f641a
parent7d8a2d05cf637fb290de01ab0f666e4d4ebce033 (diff)
downloadgitea-74a4a1e17f99d147db9329718a5ecc87984b0ecd.tar.gz
gitea-74a4a1e17f99d147db9329718a5ecc87984b0ecd.zip
Fix invalid repo urls after change username (#10150)
* Fix invalid repo urls after change username * Update user.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
-rw-r--r--models/user.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/models/user.go b/models/user.go
index 213b5f76ab..a68db6cf40 100644
--- a/models/user.go
+++ b/models/user.go
@@ -1044,13 +1044,23 @@ func ChangeUserName(u *User, newUserName string) (err error) {
} else if isExist {
return ErrUserAlreadyExist{newUserName}
}
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if _, err = sess.Exec("UPDATE `repository` SET owner_name=? WHERE owner_name=?", newUserName, u.Name); err != nil {
+ return fmt.Errorf("Change repo owner name: %v", err)
+ }
// Do not fail if directory does not exist
if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Rename user directory: %v", err)
}
- return nil
+ return sess.Commit()
}
// checkDupEmail checks whether there are the same email with the user