#1419: 500 when visit a issue with issue/comments of deleted user
This commit is contained in:
parent
e4d6b5d488
commit
30b428bf0e
|
@ -453,12 +453,12 @@ func runWeb(ctx *cli.Context) {
|
||||||
m.Combo("/new").Get(repo.NewIssue).
|
m.Combo("/new").Get(repo.NewIssue).
|
||||||
Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
|
Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
|
||||||
|
|
||||||
|
m.Combo("/:index/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
||||||
m.Group("/:index", func() {
|
m.Group("/:index", func() {
|
||||||
m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
|
m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
|
||||||
m.Post("/label", repo.UpdateIssueLabel)
|
m.Post("/label", repo.UpdateIssueLabel)
|
||||||
m.Post("/milestone", repo.UpdateIssueMilestone)
|
m.Post("/milestone", repo.UpdateIssueMilestone)
|
||||||
m.Post("/assignee", repo.UpdateIssueAssignee)
|
m.Post("/assignee", repo.UpdateIssueAssignee)
|
||||||
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
|
||||||
}, reqRepoAdmin)
|
}, reqRepoAdmin)
|
||||||
})
|
})
|
||||||
m.Group("/labels", func() {
|
m.Group("/labels", func() {
|
||||||
|
|
|
@ -1364,7 +1364,7 @@ func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsErrUserNotExist(err) {
|
if IsErrUserNotExist(err) {
|
||||||
c.PosterID = -1
|
c.PosterID = -1
|
||||||
c.Poster = &User{Name: "someone"}
|
c.Poster = NewFakeUser()
|
||||||
} else {
|
} else {
|
||||||
log.Error(3, "GetUserByID[%d]: %v", c.ID, err)
|
log.Error(3, "GetUserByID[%d]: %v", c.ID, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,10 @@ func (u *User) HomeLink() string {
|
||||||
// AvatarLink returns user gravatar link.
|
// AvatarLink returns user gravatar link.
|
||||||
func (u *User) AvatarLink() string {
|
func (u *User) AvatarLink() string {
|
||||||
defaultImgUrl := setting.AppSubUrl + "/img/avatar_default.jpg"
|
defaultImgUrl := setting.AppSubUrl + "/img/avatar_default.jpg"
|
||||||
|
if u.Id == -1 {
|
||||||
|
return defaultImgUrl
|
||||||
|
}
|
||||||
|
|
||||||
imgPath := path.Join(setting.AvatarUploadPath, com.ToStr(u.Id))
|
imgPath := path.Join(setting.AvatarUploadPath, com.ToStr(u.Id))
|
||||||
switch {
|
switch {
|
||||||
case u.UseCustomAvatar:
|
case u.UseCustomAvatar:
|
||||||
|
@ -321,6 +325,15 @@ func GetUserSalt() string {
|
||||||
return base.GetRandomString(10)
|
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.
|
// CreateUser creates record of a new user.
|
||||||
func CreateUser(u *User) (err error) {
|
func CreateUser(u *User) (err error) {
|
||||||
if err = IsUsableName(u.Name); err != nil {
|
if err = IsUsableName(u.Name); err != nil {
|
||||||
|
@ -546,6 +559,7 @@ func DeleteUser(u *User) error {
|
||||||
&Collaboration{UserID: u.Id},
|
&Collaboration{UserID: u.Id},
|
||||||
&EmailAddress{Uid: u.Id},
|
&EmailAddress{Uid: u.Id},
|
||||||
&Watch{UserID: u.Id},
|
&Watch{UserID: u.Id},
|
||||||
|
&IssueUser{UID: u.Id},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -563,11 +577,16 @@ func DeleteUser(u *User) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if err = DeletePublicKey(key); err != nil {
|
if err = deletePublicKey(sess, key); err != nil {
|
||||||
return err
|
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 {
|
if _, err = sess.Delete(u); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,7 @@ func ViewIssue(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Issue"] = issue
|
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)
|
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.
|
// 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") {
|
(form.Status == "reopen" || form.Status == "close") {
|
||||||
issue.Repo = ctx.Repo.Repository
|
issue.Repo = ctx.Repo.Repository
|
||||||
if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil {
|
if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil {
|
||||||
|
|
|
@ -56,12 +56,12 @@
|
||||||
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF -->
|
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF -->
|
||||||
{{if eq .Type 0}}
|
{{if eq .Type 0}}
|
||||||
<div class="comment">
|
<div class="comment">
|
||||||
<a class="avatar" href="{{.Poster.HomeLink}}">
|
<a class="avatar" {{if gt .Poster.Id 0}}href="{{.Poster.HomeLink}}"{{end}}>
|
||||||
<img src="{{.Poster.AvatarLink}}">
|
<img src="{{.Poster.AvatarLink}}">
|
||||||
</a>
|
</a>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="ui top attached header">
|
<div class="ui top attached header">
|
||||||
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
|
<span class="text grey"><a {{if gt .Poster.Id 0}}href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
|
||||||
<div class="ui right actions">
|
<div class="ui right actions">
|
||||||
{{if gt .ShowTag 0}}
|
{{if gt .ShowTag 0}}
|
||||||
<div class="tag">
|
<div class="tag">
|
||||||
|
@ -125,6 +125,7 @@
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<input id="status" name="status" type="hidden">
|
<input id="status" name="status" type="hidden">
|
||||||
<div class="text right">
|
<div class="text right">
|
||||||
|
{{if .IsIssueOwner}}
|
||||||
{{if .Issue.IsClosed}}
|
{{if .Issue.IsClosed}}
|
||||||
<div id="status-button" class="ui green basic button" data-status="{{.i18n.Tr "repo.issues.reopen_issue"}}" data-status-and-comment="{{.i18n.Tr "repo.issues.reopen_comment_issue"}}" data-status-val="reopen">
|
<div id="status-button" class="ui green basic button" data-status="{{.i18n.Tr "repo.issues.reopen_issue"}}" data-status-and-comment="{{.i18n.Tr "repo.issues.reopen_comment_issue"}}" data-status-val="reopen">
|
||||||
{{.i18n.Tr "repo.issues.reopen_issue"}}
|
{{.i18n.Tr "repo.issues.reopen_issue"}}
|
||||||
|
@ -134,6 +135,7 @@
|
||||||
{{.i18n.Tr "repo.issues.close_issue"}}
|
{{.i18n.Tr "repo.issues.close_issue"}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
<button class="ui green button">
|
<button class="ui green button">
|
||||||
{{.i18n.Tr "repo.issues.create_comment"}}
|
{{.i18n.Tr "repo.issues.create_comment"}}
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue