summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-06-29 18:11:38 +0300
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-29 23:11:38 +0800
commit783b1967e257fdba2bd593d9f2108da2010b7448 (patch)
treece6b942c92ee7a45ffbca29cdd1dd0dae3964df8 /routers
parent33f3165296613c819ed82612da2f6738c1301ec1 (diff)
downloadgitea-783b1967e257fdba2bd593d9f2108da2010b7448.tar.gz
gitea-783b1967e257fdba2bd593d9f2108da2010b7448.zip
Fix release display and correct paging (#2080)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/release.go17
-rw-r--r--routers/repo/release.go15
2 files changed, 15 insertions, 17 deletions
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index a367e55717..ed5b8f4f78 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -34,22 +34,21 @@ func GetRelease(ctx *context.APIContext) {
// ListReleases list a repository's releases
func ListReleases(ctx *context.APIContext) {
- releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, 1, 2147483647)
+ access, err := models.AccessLevel(ctx.User.ID, ctx.Repo.Repository)
if err != nil {
- ctx.Error(500, "GetReleasesByRepoID", err)
+ ctx.Error(500, "AccessLevel", err)
return
}
- rels := make([]*api.Release, len(releases))
- access, err := models.AccessLevel(ctx.User.ID, ctx.Repo.Repository)
+
+ releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
+ IncludeDrafts: access >= models.AccessModeWrite,
+ }, 1, 2147483647)
if err != nil {
- ctx.Error(500, "AccessLevel", err)
+ ctx.Error(500, "GetReleasesByRepoID", err)
return
}
+ rels := make([]*api.Release, len(releases))
for i, release := range releases {
- if release.IsDraft && access < models.AccessModeWrite {
- // hide drafts from users without push access
- continue
- }
if err := release.LoadAttributes(); err != nil {
ctx.Error(500, "LoadAttributes", err)
return
diff --git a/routers/repo/release.go b/routers/repo/release.go
index 1b2c630a56..d9cc967801 100644
--- a/routers/repo/release.go
+++ b/routers/repo/release.go
@@ -65,13 +65,17 @@ func Releases(ctx *context.Context) {
limit = 10
}
- releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, limit)
+ opts := models.FindReleasesOptions{
+ IncludeDrafts: ctx.Repo.IsWriter(),
+ }
+
+ releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit)
if err != nil {
ctx.Handle(500, "GetReleasesByRepoID", err)
return
}
- count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, ctx.Repo.IsOwner())
+ count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, opts)
if err != nil {
ctx.Handle(500, "GetReleaseCountByRepoID", err)
return
@@ -91,11 +95,7 @@ func Releases(ctx *context.Context) {
}
var ok bool
- releasesToDisplay := make([]*models.Release, 0, len(releases))
for _, r := range releases {
- if r.IsDraft && !ctx.Repo.IsOwner() {
- continue
- }
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
r.Publisher, err = models.GetUserByID(r.PublisherID)
if err != nil {
@@ -113,12 +113,11 @@ func Releases(ctx *context.Context) {
return
}
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
- releasesToDisplay = append(releasesToDisplay, r)
}
pager := paginater.New(int(count), limit, page, 5)
ctx.Data["Page"] = pager
- ctx.Data["Releases"] = releasesToDisplay
+ ctx.Data["Releases"] = releases
ctx.HTML(200, tplReleases)
}