aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-15 02:48:05 +0800
committerUnknwon <u@gogs.io>2015-08-15 02:48:05 +0800
commit30b428bf0eabb9f6cd73894d776502e1b7e351b7 (patch)
treec7e51f33011d5813374f9d90c6e4c5fef3f79cbb
parente4d6b5d488981d78417e9c85eda8226ebb8b7e37 (diff)
downloadgitea-30b428bf0eabb9f6cd73894d776502e1b7e351b7.tar.gz
gitea-30b428bf0eabb9f6cd73894d776502e1b7e351b7.zip
#1419: 500 when visit a issue with issue/comments of deleted user
-rw-r--r--cmd/web.go2
-rw-r--r--models/issue.go2
-rw-r--r--models/user.go21
-rw-r--r--routers/repo/issue.go4
-rw-r--r--templates/repo/issue/view_content.tmpl6
5 files changed, 28 insertions, 7 deletions
diff --git a/cmd/web.go b/cmd/web.go
index a091c5c69d..c441e91966 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 712dd6bb2d..4b7da8ce6c 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 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
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index d992cecc53..dc86dedff0 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 d368027591..fc84d101bc 100644
--- a/templates/repo/issue/view_content.tmpl
+++ b/templates/repo/issue/view_content.tmpl
@@ -56,12 +56,12 @@
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF -->
{{if eq .Type 0}}
<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}}">
</a>
<div class="content">
<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">
{{if gt .ShowTag 0}}
<div class="tag">
@@ -125,6 +125,7 @@
{{.CsrfTokenHtml}}
<input id="status" name="status" type="hidden">
<div class="text right">
+ {{if .IsIssueOwner}}
{{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">
{{.i18n.Tr "repo.issues.reopen_issue"}}
@@ -134,6 +135,7 @@
{{.i18n.Tr "repo.issues.close_issue"}}
</div>
{{end}}
+ {{end}}
<button class="ui green button">
{{.i18n.Tr "repo.issues.create_comment"}}
</button>