You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/11/01 18:08:30 UTC

[GitHub] [trafficcontrol] jheitz200 commented on a change in pull request #4059: return 403 when unauthorized user assigns/deletes ds required capability

jheitz200 commented on a change in pull request #4059: return 403 when unauthorized user assigns/deletes ds required capability
URL: https://github.com/apache/trafficcontrol/pull/4059#discussion_r341690403
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices_required_capabilities.go
 ##########
 @@ -219,22 +219,51 @@ func (rc *RequiredCapability) getCapabilities(tenantIDs []int) ([]tc.DeliverySer
 // Delete implements the api.CRUDer interface.
 func (rc *RequiredCapability) Delete() (error, error, int) {
 	authorized, err := rc.isTenantAuthorized()
-	if err != nil {
-		return nil, errors.New("checking tenant: " + err.Error()), http.StatusInternalServerError
-	} else if !authorized {
+	if !authorized {
 		return errors.New("not authorized on this tenant"), nil, http.StatusForbidden
+	} else if err != nil {
+		return nil, fmt.Errorf("checking authorization for existing DS ID: %s" + err.Error()), http.StatusInternalServerError
+	}
+
+	// Check if the Delivery Service is associated with the Required Capability
+	statusCode, err := rc.exists()
+	if err != nil {
+		return err, nil, statusCode
 	}
 
 	return api.GenericDelete(rc)
 }
 
+// exists checks to see if a required capability is assigned to a delivery service
+func (rc *RequiredCapability) exists() (int, error) {
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(rc.APIInfo().Params, rc.ParamColumns())
+	if len(errs) > 0 {
+		return http.StatusBadRequest, util.JoinErrs(errs)
+	}
+	fmt.Printf("\n\nwhere: %+v\norderby: %+v\npag: %+v\nqueryvalues: %+v\n\n", where, orderBy, pagination, queryValues)
 
 Review comment:
   thanks, i complete forgot i wanted to see what that helper function did and use it if possible. looking into this now

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services