diff options
author | Unknwon <u@gogs.io> | 2015-08-15 02:48:05 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-15 02:48:05 +0800 |
commit | 30b428bf0eabb9f6cd73894d776502e1b7e351b7 (patch) | |
tree | c7e51f33011d5813374f9d90c6e4c5fef3f79cbb /models/user.go | |
parent | e4d6b5d488981d78417e9c85eda8226ebb8b7e37 (diff) | |
download | gitea-30b428bf0eabb9f6cd73894d776502e1b7e351b7.tar.gz gitea-30b428bf0eabb9f6cd73894d776502e1b7e351b7.zip |
#1419: 500 when visit a issue with issue/comments of deleted user
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/models/user.go b/models/user.go index f2151a7080..ca49a5b8f6 100644 --- a/models/user.go +++ b/models/user.go @@ -119,6 +119,10 @@ func (u *User) HomeLink() string { // AvatarLink returns user gravatar link. func (u *User) AvatarLink() string { defaultImgUrl := setting.AppSubUrl + "/img/avatar_default.jpg" + if u.Id == -1 { + return defaultImgUrl + } + imgPath := path.Join(setting.AvatarUploadPath, com.ToStr(u.Id)) switch { case u.UseCustomAvatar: @@ -321,6 +325,15 @@ func GetUserSalt() string { return base.GetRandomString(10) } +// NewFakeUser creates and returns a fake user for someone has deleted his/her account. +func NewFakeUser() *User { + return &User{ + Id: -1, + Name: "Someone", + LowerName: "someone", + } +} + // CreateUser creates record of a new user. func CreateUser(u *User) (err error) { if err = IsUsableName(u.Name); err != nil { @@ -546,6 +559,7 @@ func DeleteUser(u *User) error { &Collaboration{UserID: u.Id}, &EmailAddress{Uid: u.Id}, &Watch{UserID: u.Id}, + &IssueUser{UID: u.Id}, ); err != nil { return err } @@ -563,11 +577,16 @@ func DeleteUser(u *User) error { return err } for _, key := range keys { - if err = DeletePublicKey(key); err != nil { + if err = deletePublicKey(sess, key); err != nil { return err } } + // Clear assignee. + if _, err = sess.Exec("UPDATE `issue` SET assignee_id=0 WHERE assignee_id=?", u.Id); err != nil { + return err + } + if _, err = sess.Delete(u); err != nil { return err } |