mhoppa commented on a change in pull request #4406: Only allow changing of
types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r391828763
##########
File path: traffic_ops/traffic_ops_golang/types/types.go
##########
@@ -95,9 +98,48 @@ func (typ *TOType) Validate() error {
}
func (tp *TOType) Read() ([]interface{}, error, error, int) { return
api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int) { return
api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int) { return
api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int) { return
api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+ if !tp.AllowMutation() {
+ return nil, errors.New("can not update type"),
http.StatusBadRequest
+ }
+ return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+ if tp.UseInTable == nil {
+ if tp.ID != nil {
+ query := `SELECT use_in_table from type where id=$1`
+ err := tp.ReqInfo.Tx.Tx.QueryRow(query,
tp.ID).Scan(&tp.UseInTable)
+ if err != nil {
+ return api.ParseDBError(err)
+ }
+ } else {
+ return nil, errors.New("no type with that key found"),
http.StatusNotFound
Review comment:
I think the returns on all these errors (here and in the update/create
methods) are backwards I think it is `userErr,sysErr,statusCode` I believe you
have it as `sysErr,userErr,statusCode`
I am not getting any relevant errors back the API when I cause a failure
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services