Skip to content

Commit e31c02d

Browse files
authored
fix bug on issue view when not login (#1624)
* fix bug on issue view when not login * hide issue watch when not login * update the tests * fix test on issue
1 parent 61b08b5 commit e31c02d

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

integrations/issue_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestNoLoginViewIssue(t *testing.T) {
15+
prepareTestEnv(t)
16+
17+
req, err := http.NewRequest("GET", "/user2/repo1/issues/1", nil)
18+
assert.NoError(t, err)
19+
resp := MakeRequest(req)
20+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21+
}

models/fixtures/repo_unit.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-
2+
id: 1
3+
repo_id: 1
4+
type: 1
5+
index: 0
6+
config: "{}"
7+
created_unix: 946684810
8+
9+
-
10+
id: 2
11+
repo_id: 1
12+
type: 2
13+
index: 0
14+
config: "{}"
15+
created_unix: 946684810

routers/repo/issue.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,20 @@ func ViewIssue(ctx *context.Context) {
465465
}
466466
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
467467

468-
iw, exists, err := models.GetIssueWatch(ctx.User.ID, issue.ID)
469-
if err != nil {
470-
ctx.Handle(500, "GetIssueWatch", err)
471-
return
472-
}
473-
if !exists {
474-
iw = &models.IssueWatch{
475-
UserID: ctx.User.ID,
476-
IssueID: issue.ID,
477-
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
468+
var iw *models.IssueWatch
469+
var exists bool
470+
if ctx.User != nil {
471+
iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
472+
if err != nil {
473+
ctx.Handle(500, "GetIssueWatch", err)
474+
return
475+
}
476+
if !exists {
477+
iw = &models.IssueWatch{
478+
UserID: ctx.User.ID,
479+
IssueID: issue.ID,
480+
IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
481+
}
478482
}
479483
}
480484
ctx.Data["IssueWatch"] = iw

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
</div>
100100
</div>
101101

102+
{{if $.IssueWatch}}
102103
<div class="ui divider"></div>
103104

104105
<div class="ui watching">
@@ -119,5 +120,6 @@
119120
</form>
120121
</div>
121122
</div>
123+
{{end}}
122124
</div>
123125
</div>

0 commit comments

Comments
 (0)