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_r387687163
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ 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)
 
 Review comment:
   I havent tested it but did the Delete used to return a 404 if the given id 
didnt exist? I think in this new logic it would return "can not delete type" -> 
404 

----------------------------------------------------------------
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

Reply via email to