diff options
Diffstat (limited to 'routers/repo/milestone.go')
-rw-r--r-- | routers/repo/milestone.go | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/routers/repo/milestone.go b/routers/repo/milestone.go index 0bd7344878..f48c5de12e 100644 --- a/routers/repo/milestone.go +++ b/routers/repo/milestone.go @@ -207,39 +207,28 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { ctx.Redirect(ctx.Repo.RepoLink + "/milestones") } -// ChangeMilestonStatus response for change a milestone's status -func ChangeMilestonStatus(ctx *context.Context) { - m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) - if err != nil { - if models.IsErrMilestoneNotExist(err) { - ctx.NotFound("", err) - } else { - ctx.ServerError("GetMilestoneByRepoID", err) - } - return - } - +// ChangeMilestoneStatus response for change a milestone's status +func ChangeMilestoneStatus(ctx *context.Context) { + toClose := false switch ctx.Params(":action") { case "open": - if m.IsClosed { - if err = models.ChangeMilestoneStatus(m, false); err != nil { - ctx.ServerError("ChangeMilestoneStatus", err) - return - } - } - ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open") + toClose = false case "close": - if !m.IsClosed { - m.ClosedDateUnix = timeutil.TimeStampNow() - if err = models.ChangeMilestoneStatus(m, true); err != nil { - ctx.ServerError("ChangeMilestoneStatus", err) - return - } - } - ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=closed") + toClose = true default: ctx.Redirect(ctx.Repo.RepoLink + "/milestones") } + id := ctx.ParamsInt64(":id") + + if err := models.ChangeMilestoneStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil { + if models.IsErrMilestoneNotExist(err) { + ctx.NotFound("", err) + } else { + ctx.ServerError("ChangeMilestoneStatusByIDAndRepoID", err) + } + return + } + ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=" + ctx.Params(":action")) } // DeleteMilestone delete a milestone @@ -274,7 +263,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) { ctx.Data["Title"] = milestone.Name ctx.Data["Milestone"] = milestone - issues(ctx, milestoneID, util.OptionalBoolNone) + issues(ctx, milestoneID, 0, util.OptionalBoolNone) ctx.Data["CanWriteIssues"] = ctx.Repo.CanWriteIssuesOrPulls(false) ctx.Data["CanWritePulls"] = ctx.Repo.CanWriteIssuesOrPulls(true) |