Skip to content

Commit 9a75c27

Browse files
authoredJan 26, 2022
Only view milestones from current repo (#18414)
The endpoint /{username}/{reponame}/milestone/{id} is not currently restricted to the repo. This PR restricts the milestones to those within the repo. Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 3bb028c commit 9a75c27

File tree

4 files changed

+4
-20
lines changed

4 files changed

+4
-20
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ require (
9797
github.com/quasoft/websspi v1.0.0
9898
github.com/rs/xid v1.3.0 // indirect
9999
github.com/russross/blackfriday/v2 v2.1.0 // indirect
100-
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
100+
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
101101
github.com/sergi/go-diff v1.2.0
102102
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
103103
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546

‎models/issue_milestone.go

-16
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,6 @@ func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error)
134134
return &mile, nil
135135
}
136136

137-
// GetMilestoneByID returns the milestone via id .
138-
func GetMilestoneByID(id int64) (*Milestone, error) {
139-
return getMilestoneByID(db.GetEngine(db.DefaultContext), id)
140-
}
141-
142-
func getMilestoneByID(e db.Engine, id int64) (*Milestone, error) {
143-
var m Milestone
144-
has, err := e.ID(id).Get(&m)
145-
if err != nil {
146-
return nil, err
147-
} else if !has {
148-
return nil, ErrMilestoneNotExist{ID: id, RepoID: 0}
149-
}
150-
return &m, nil
151-
}
152-
153137
// UpdateMilestone updates information of given milestone.
154138
func UpdateMilestone(m *Milestone, oldIsClosed bool) error {
155139
ctx, committer, err := db.TxContext()

‎routers/web/repo/issue.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func NewIssue(ctx *context.Context) {
799799

800800
milestoneID := ctx.FormInt64("milestone")
801801
if milestoneID > 0 {
802-
milestone, err := models.GetMilestoneByID(milestoneID)
802+
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
803803
if err != nil {
804804
log.Error("GetMilestoneByID: %d: %v", milestoneID, err)
805805
} else {
@@ -886,7 +886,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
886886
// Check milestone.
887887
milestoneID := form.MilestoneID
888888
if milestoneID > 0 {
889-
milestone, err := models.GetMilestoneByID(milestoneID)
889+
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
890890
if err != nil {
891891
ctx.ServerError("GetMilestoneByID", err)
892892
return nil, nil, 0, 0

‎routers/web/repo/milestone.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func DeleteMilestone(ctx *context.Context) {
264264
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
265265
func MilestoneIssuesAndPulls(ctx *context.Context) {
266266
milestoneID := ctx.ParamsInt64(":id")
267-
milestone, err := models.GetMilestoneByID(milestoneID)
267+
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
268268
if err != nil {
269269
if models.IsErrMilestoneNotExist(err) {
270270
ctx.NotFound("GetMilestoneByID", err)

0 commit comments

Comments
 (0)
Please sign in to comment.