Skip to content

Commit 9bb6435

Browse files
committed
Improve PUT /deliveryservice_request_comments id
1 parent 692e86a commit 9bb6435

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3535
- [#7918](https://github.com/apache/trafficcontrol/pull/7918) *Traffic Portal* Fixed topology link under DS-Servers tables page
3636
- [#7846](https://github.com/apache/trafficcontrol/pull/7846) *Traffic Portal* Increase State character limit
3737
- [#8010](https://github.com/apache/trafficcontrol/pull/8010) *Traffic Stats* Omit NPM dev dependencies from Traffic Stats RPM
38+
- [#8071](https://github.com/apache/trafficcontrol/pull/8071) *Traffic Ops* Improve validation for the `id` field of the `PUT /deliveryservice_request_comments` endpoint.
3839

3940
### Removed
4041
- [#7832](https://github.com/apache/trafficcontrol/pull/7832) *t3c* Removed Perl dependency

traffic_ops/traffic_ops_golang/deliveryservice/request/comment/comments.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func Get(w http.ResponseWriter, r *http.Request) {
264264
// Validate is used to ensure that the DeliveryServiceRequestCommentV5 struct passed in to the function is valid.
265265
func Validate(dsrc tc.DeliveryServiceRequestCommentV5) error {
266266
errs := validation.Errors{
267+
"id": validation.Validate(dsrc.ID, validation.NotNil),
267268
"deliveryServiceRequestId": validation.Validate(dsrc.DeliveryServiceRequestID, validation.NotNil),
268269
"value": validation.Validate(dsrc.Value, validation.NotNil),
269270
}
@@ -286,14 +287,21 @@ func Update(w http.ResponseWriter, r *http.Request) {
286287
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
287288
return
288289
}
290+
idParam := inf.Params["id"]
291+
id, parseErr := strconv.Atoi(idParam)
292+
if parseErr != nil {
293+
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
294+
return
295+
}
296+
deliveryServiceRequestComment.ID = id
289297

290298
if err := Validate(deliveryServiceRequestComment); err != nil {
291299
api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
292300
return
293301
}
294302

295303
var current tc.DeliveryServiceRequestCommentV5
296-
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + inf.Params["id"]).StructScan(&current)
304+
err := inf.Tx.QueryRowx(selectQuery() + `WHERE dsrc.id=` + strconv.Itoa(deliveryServiceRequestComment.ID)).StructScan(&current)
297305
if err != nil {
298306
api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning deliveryservice_request_comment: "+err.Error()))
299307
return
@@ -305,13 +313,6 @@ func Update(w http.ResponseWriter, r *http.Request) {
305313
return
306314
}
307315
deliveryServiceRequestComment.AuthorID = current.AuthorID
308-
idParam := inf.Params["id"]
309-
id, parseErr := strconv.Atoi(idParam)
310-
if parseErr != nil {
311-
api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("id must be an integer"), nil)
312-
return
313-
}
314-
deliveryServiceRequestComment.ID = id
315316
userErr, sysErr, sc := api.CheckIfUnModified(r.Header, inf.Tx, id, "deliveryservice_request_comment")
316317
if userErr != nil || sysErr != nil {
317318
api.HandleErr(w, r, tx, sc, userErr, sysErr)

0 commit comments

Comments
 (0)