Skip to content

Commit

Permalink
fix bug on issue view when not login
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Apr 28, 2017
1 parent fca7ddc commit 5218564
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 23 additions & 0 deletions integrations/issue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
"net/http"
"testing"

"code.gitea.io/gitea/models"

"github.com/stretchr/testify/assert"
)

func TestNoLoginViewIssue(t *testing.T) {
assert.NoError(t, models.LoadFixtures())

req, err := http.NewRequest("GET", "/user1/repo1/issues/1", nil)
assert.NoError(t, err)
resp := MakeRequest(req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
}
26 changes: 18 additions & 8 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,26 @@ func ViewIssue(ctx *context.Context) {
}
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)

iw, exists, err := models.GetIssueWatch(ctx.User.ID, issue.ID)
if err != nil {
ctx.Handle(500, "GetIssueWatch", err)
return
}
if !exists {
var iw *models.IssueWatch
var exists bool
if ctx.User != nil {
iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
if err != nil {
ctx.Handle(500, "GetIssueWatch", err)
return
}
if !exists {
iw = &models.IssueWatch{
UserID: ctx.User.ID,
IssueID: issue.ID,
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
}
}
} else {
iw = &models.IssueWatch{
UserID: ctx.User.ID,
UserID: 0,
IssueID: issue.ID,
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
IsWatching: false,
}
}
ctx.Data["IssueWatch"] = iw
Expand Down

0 comments on commit 5218564

Please sign in to comment.