summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go59
1 files changed, 2 insertions, 57 deletions
diff --git a/models/user.go b/models/user.go
index 5606cea379..9a6f93a474 100644
--- a/models/user.go
+++ b/models/user.go
@@ -395,62 +395,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
if !IsLegalName(newUserName) {
return ErrUserNameIllegal
}
-
- newUserName = strings.ToLower(newUserName)
-
- // Update accesses of user.
- accesses := make([]Access, 0, 10)
- if err = x.Find(&accesses, &Access{UserName: u.LowerName}); err != nil {
- return err
- }
-
- sess := x.NewSession()
- defer sess.Close()
- if err = sess.Begin(); err != nil {
- return err
- }
-
- for i := range accesses {
- accesses[i].UserName = newUserName
- if strings.HasPrefix(accesses[i].RepoName, u.LowerName+"/") {
- accesses[i].RepoName = strings.Replace(accesses[i].RepoName, u.LowerName, newUserName, 1)
- }
- if err = updateAccess(sess, &accesses[i]); err != nil {
- sess.Rollback()
- return err
- }
- }
-
- repos, err := GetRepositories(u.Id, true)
- if err != nil {
- return err
- }
- for i := range repos {
- accesses = make([]Access, 0, 10)
- // Update accesses of user repository.
- if err = x.Find(&accesses, &Access{RepoName: u.LowerName + "/" + repos[i].LowerName}); err != nil {
- return err
- }
-
- for j := range accesses {
- // if the access is not the user's access (already updated above)
- if accesses[j].UserName != u.LowerName {
- accesses[j].RepoName = newUserName + "/" + repos[i].LowerName
- if err = updateAccess(sess, &accesses[j]); err != nil {
- sess.Rollback()
- return err
- }
- }
- }
- }
-
- // Change user directory name.
- if err = os.Rename(UserPath(u.LowerName), UserPath(newUserName)); err != nil {
- sess.Rollback()
- return err
- }
-
- return sess.Commit()
+ return os.Rename(UserPath(u.LowerName), UserPath(newUserName))
}
// UpdateUser updates user's information.
@@ -523,7 +468,7 @@ func DeleteUser(u *User) error {
return err
}
// Delete all accesses.
- if _, err = x.Delete(&Access{UserName: u.LowerName}); err != nil {
+ if _, err = x.Delete(&Access{UserID: u.Id}); err != nil {
return err
}
// Delete all alternative email addresses