diff options
author | Peter Smit <peter@smitmail.eu> | 2015-02-05 15:29:08 +0200 |
---|---|---|
committer | Peter Smit <peter@smitmail.eu> | 2015-02-06 13:18:11 +0200 |
commit | 4e79adf6b5bf7ec7bc3b2b47469baafd1cb0b774 (patch) | |
tree | 7c9ffe3d741408b5b3c33974b5143b9a50646e02 /models/user.go | |
parent | 03af37554e34582e8c5a9d98ec9f2d3c9884f0d8 (diff) | |
download | gitea-4e79adf6b5bf7ec7bc3b2b47469baafd1cb0b774.tar.gz gitea-4e79adf6b5bf7ec7bc3b2b47469baafd1cb0b774.zip |
Refactoring of the Access Table
This commit does a lot of the work of refactoring the access table in a table with id's instead of strings.
The result does compile, but has not been tested. It may eat your kittens.
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 56 |
1 files changed, 2 insertions, 54 deletions
diff --git a/models/user.go b/models/user.go index 2da0881c81..b33e529aa6 100644 --- a/models/user.go +++ b/models/user.go @@ -396,59 +396,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { 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 = UpdateAccessWithSession(sess, &accesses[i]); err != nil { - 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 = UpdateAccessWithSession(sess, &accesses[j]); err != nil { - 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. @@ -521,7 +469,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 |