Skip to content

Commit 4df1a24

Browse files
ethantkoeniglunny
authored andcommitted
Let not-logged-in users view releases (#1999)
1 parent 6e452c4 commit 4df1a24

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

integrations/release_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ func TestViewReleases(t *testing.T) {
1919
resp := session.MakeRequest(t, req)
2020
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
2121
}
22+
23+
func TestViewReleasesNoLogin(t *testing.T) {
24+
prepareTestEnv(t)
25+
26+
req := NewRequest(t, "GET", "/user2/repo1/releases")
27+
resp := MakeRequest(req)
28+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
29+
}

routers/repo/release.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ func Releases(ctx *context.Context) {
7979

8080
// Temporary cache commits count of used branches to speed up.
8181
countCache := make(map[string]int64)
82-
cacheUsers := map[int64]*models.User{ctx.User.ID: ctx.User}
82+
cacheUsers := make(map[int64]*models.User)
83+
if ctx.User != nil {
84+
cacheUsers[ctx.User.ID] = ctx.User
85+
}
8386
var ok bool
8487

8588
releasesToDisplay := make([]*models.Release, 0, len(releases))

routers/routes/routes.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,16 @@ func RegisterRoutes(m *macaron.Macaron) {
529529
m.Group("/:username/:reponame", func() {
530530
m.Group("/releases", func() {
531531
m.Get("/", repo.MustBeNotBare, repo.Releases)
532+
}, repo.MustBeNotBare, context.RepoRef())
533+
m.Group("/releases", func() {
532534
m.Get("/new", repo.NewRelease)
533535
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
534536
m.Post("/delete", repo.DeleteRelease)
535-
}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
537+
}, reqSignIn, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
536538
m.Group("/releases", func() {
537539
m.Get("/edit/*", repo.EditRelease)
538540
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
539-
}, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
541+
}, reqSignIn, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
540542
var err error
541543
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
542544
if err != nil {
@@ -550,7 +552,7 @@ func RegisterRoutes(m *macaron.Macaron) {
550552
}
551553
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
552554
})
553-
}, reqSignIn, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeReleases))
555+
}, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeReleases))
554556

555557
m.Group("/:username/:reponame", func() {
556558
m.Group("", func() {

0 commit comments

Comments
 (0)