diff --git a/cmd/web.go b/cmd/web.go index a091c5c69..c441e9196 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -453,12 +453,12 @@ func runWeb(ctx *cli.Context) { m.Combo("/new").Get(repo.NewIssue). Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) + m.Combo("/:index/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) m.Group("/:index", func() { m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) m.Post("/label", repo.UpdateIssueLabel) m.Post("/milestone", repo.UpdateIssueMilestone) m.Post("/assignee", repo.UpdateIssueAssignee) - m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) }, reqRepoAdmin) }) m.Group("/labels", func() { diff --git a/models/issue.go b/models/issue.go index 712dd6bb2..4b7da8ce6 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1364,7 +1364,7 @@ func (c *Comment) AfterSet(colName string, _ xorm.Cell) { if err != nil { if IsErrUserNotExist(err) { c.PosterID = -1 - c.Poster = &User{Name: "someone"} + c.Poster = NewFakeUser() } else { log.Error(3, "GetUserByID[%d]: %v", c.ID, err) } diff --git a/models/user.go b/models/user.go index f2151a708..ca49a5b8f 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 } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index d992cecc5..dc86dedff 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -508,7 +508,7 @@ func ViewIssue(ctx *middleware.Context) { } ctx.Data["Issue"] = issue - // ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner() || (ctx.IsSigned && issue.PosterID == ctx.User.Id) + ctx.Data["IsIssueOwner"] = ctx.Repo.IsAdmin() || (ctx.IsSigned && issue.IsPoster(ctx.User.Id)) ctx.HTML(200, ISSUE_VIEW) } @@ -685,7 +685,7 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { } // Check if issue owner/poster changes the status of issue. - if (ctx.Repo.IsOwner() || issue.IsPoster(ctx.User.Id)) && + if (ctx.Repo.IsOwner() || (ctx.IsSigned && issue.IsPoster(ctx.User.Id))) && (form.Status == "reopen" || form.Status == "close") { issue.Repo = ctx.Repo.Repository if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil { diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index d36802759..fc84d101b 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -56,12 +56,12 @@ {{if eq .Type 0}}