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_r394594577
##########
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.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 errors.New("no type with that key found"), nil,
http.StatusNotFound
+ }
+ if !tp.AllowMutation() {
+ return nil, errors.New(fmt.Sprintf("can not delete type")),
http.StatusBadRequest
+ }
+ return api.GenericDelete(tp)
+}
+
+func (tp *TOType) Create() (error, error, int) {
+ if !tp.AllowMutation() {
+ return nil, errors.New("can not create type"),
http.StatusBadRequest
Review comment:
the userErr goes first
----------------------------------------------------------------
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