dewrich closed pull request #2005: [Issue 1996] - reduces priv level of 
updating ds request status to Portal role and f…
URL: https://github.com/apache/incubator-trafficcontrol/pull/2005
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/traffic_ops_golang/routes.go 
b/traffic_ops/traffic_ops_golang/routes.go
index ff59cc351..00a33b118 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -107,7 +107,7 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
                {1.3, http.MethodPost, `deliveryservice_requests/?$`, 
api.CreateHandler(dsrequest.GetRefType(), d.DB), auth.PrivLevelPortal, 
Authenticated, nil},
                {1.3, http.MethodDelete, `deliveryservice_requests/{id}$`, 
api.DeleteHandler(dsrequest.GetRefType(), d.DB), auth.PrivLevelPortal, 
Authenticated, nil},
                {1.3, http.MethodPut, `deliveryservice_requests/{id}/assign$`, 
api.UpdateHandler(dsrequest.GetAssignRefType(), d.DB), 
auth.PrivLevelOperations, Authenticated, nil},
-               {1.3, http.MethodPut, `deliveryservice_requests/{id}/status$`, 
api.UpdateHandler(dsrequest.GetStatusRefType(), d.DB), 
auth.PrivLevelOperations, Authenticated, nil},
+               {1.3, http.MethodPut, `deliveryservice_requests/{id}/status$`, 
api.UpdateHandler(dsrequest.GetStatusRefType(), d.DB), auth.PrivLevelPortal, 
Authenticated, nil},
 
                {1.3, http.MethodGet, `deliveryservices/{xmlID}/urisignkeys$`, 
getURIsignkeysHandler(d.DB, d.Config), auth.PrivLevelAdmin, Authenticated, nil},
                {1.3, http.MethodPost, `deliveryservices/{xmlID}/urisignkeys$`, 
saveDeliveryServiceURIKeysHandler(d.DB, d.Config), auth.PrivLevelAdmin, 
Authenticated, nil},
diff --git a/traffic_portal/app/src/common/api/DeliveryServiceService.js 
b/traffic_portal/app/src/common/api/DeliveryServiceService.js
index 631272b7e..344518f5f 100644
--- a/traffic_portal/app/src/common/api/DeliveryServiceService.js
+++ b/traffic_portal/app/src/common/api/DeliveryServiceService.js
@@ -28,46 +28,51 @@ var DeliveryServiceService = function(Restangular, $http, 
$q, locationUtils, htt
     };
 
     this.createDeliveryService = function(ds) {
-        return Restangular.service('deliveryservices').post(ds)
+        var request = $q.defer();
+
+        $http.post(ENV.api['root'] + "deliveryservices", ds)
             .then(
                 function(response) {
-                    messageModel.setMessages([ { level: 'success', text: 
'Delivery Service [ ' + ds.xmlId + ' ] created' } ], true);
-                    locationUtils.navigateToPath('/delivery-services/' + 
response.id + '?type=' + response.type);
+                    request.resolve(response);
                 },
                 function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
+                    request.reject(fault);
                 }
             );
+
+        return request.promise;
     };
 
-    this.updateDeliveryService = function(ds, delay) {
+    this.updateDeliveryService = function(ds) {
         var request = $q.defer();
 
         $http.put(ENV.api['root'] + "deliveryservices/" + ds.id, ds)
             .then(
                 function(response) {
-                    var response2 = response.data.response[0];
-                    messageModel.setMessages([ { level: 'success', text: 
'Delivery Service [ ' + ds.xmlId + ' ] updated' } ], delay);
-                    locationUtils.navigateToPath('/delivery-services/' + 
response2.id + '?type=' + response2.type);
+                    request.resolve(response);
                 },
                 function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
+                    request.reject(fault);
                 }
             );
 
         return request.promise;
     };
 
-    this.deleteDeliveryService = function(ds, delay) {
-        return Restangular.one("deliveryservices", ds.id).remove()
+    this.deleteDeliveryService = function(ds) {
+        var deferred = $q.defer();
+
+        $http.delete(ENV.api['root'] + "deliveryservices/" + ds.id)
             .then(
-                function() {
-                    messageModel.setMessages([ { level: 'success', text: 
'Delivery service [ ' + ds.xmlId + ' ] deleted' } ], delay);
+                function(response) {
+                    deferred.resolve(response);
                 },
                 function(fault) {
-                    messageModel.setMessages(fault.data.alerts, true);
+                    deferred.reject(fault);
                 }
             );
+
+        return deferred.promise;
     };
 
     this.getServerDeliveryServices = function(serverId) {
diff --git 
a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
 
b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
index 3fd448da8..cc9e7f3ab 100644
--- 
a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
+++ 
b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-var FormEditDeliveryServiceController = function(deliveryService, type, types, 
$scope, $state, $controller, $uibModal, locationUtils, deliveryServiceService, 
deliveryServiceRequestService) {
+var FormEditDeliveryServiceController = function(deliveryService, type, types, 
$scope, $state, $controller, $uibModal, $anchorScroll, locationUtils, 
deliveryServiceService, deliveryServiceRequestService, messageModel) {
 
        // extends the FormDeliveryServiceController to inherit common methods
        angular.extend(this, $controller('FormDeliveryServiceController', { 
deliveryService: deliveryService, dsCurrent: deliveryService, type: type, 
types: types, $scope: $scope }));
@@ -91,10 +91,17 @@ var FormEditDeliveryServiceController = 
function(deliveryService, type, types, $
                                // do nothing
                        });
                } else {
-                       
deliveryServiceService.updateDeliveryService(deliveryService, false).
-                               then(function() {
-                                       $state.reload(); // reloads all the 
resolves for the view
-                               });
+                       
deliveryServiceService.updateDeliveryService(deliveryService).
+                               then(
+                                       function() {
+                                               $state.reload(); // reloads all 
the resolves for the view
+                                               messageModel.setMessages([ { 
level: 'success', text: 'Delivery Service [ ' + deliveryService.xmlId + ' ] 
updated' } ], false);
+                                       },
+                                       function(fault) {
+                                               $anchorScroll(); // scrolls 
window to top
+                                               
messageModel.setMessages(fault.data.alerts, false);
+                                       }
+                               );
                }
        };
 
@@ -117,10 +124,17 @@ var FormEditDeliveryServiceController = 
function(deliveryService, type, types, $
                                }
                        });
                        modalInstance.result.then(function() {
-                               
deliveryServiceService.deleteDeliveryService(deliveryService, true)
-                                       .then(function() {
-                                               
locationUtils.navigateToPath('/delivery-services');
-                                       });
+                               
deliveryServiceService.deleteDeliveryService(deliveryService)
+                                       .then(
+                                               function() {
+                                                       
messageModel.setMessages([ { level: 'success', text: 'Delivery service [ ' + 
deliveryService.xmlId + ' ] deleted' } ], true);
+                                                       
locationUtils.navigateToPath('/delivery-services');
+                                               },
+                                               function(fault) {
+                                                       $anchorScroll(); // 
scrolls window to top
+                                                       
messageModel.setMessages(fault.data.alerts, false);
+                                               }
+                                       );
                        }, function () {
                                // do nothing
                        });
@@ -130,5 +144,5 @@ var FormEditDeliveryServiceController = 
function(deliveryService, type, types, $
 
 };
 
-FormEditDeliveryServiceController.$inject = ['deliveryService', 'type', 
'types', '$scope', '$state', '$controller', '$uibModal', 'locationUtils', 
'deliveryServiceService', 'deliveryServiceRequestService'];
+FormEditDeliveryServiceController.$inject = ['deliveryService', 'type', 
'types', '$scope', '$state', '$controller', '$uibModal', '$anchorScroll', 
'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 
'messageModel'];
 module.exports = FormEditDeliveryServiceController;
diff --git 
a/traffic_portal/app/src/common/modules/form/deliveryService/new/FormNewDeliveryServiceController.js
 
b/traffic_portal/app/src/common/modules/form/deliveryService/new/FormNewDeliveryServiceController.js
index a1f5ad01d..4de616119 100644
--- 
a/traffic_portal/app/src/common/modules/form/deliveryService/new/FormNewDeliveryServiceController.js
+++ 
b/traffic_portal/app/src/common/modules/form/deliveryService/new/FormNewDeliveryServiceController.js
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-var FormNewDeliveryServiceController = function(deliveryService, type, types, 
$scope, $controller, $uibModal, deliveryServiceService, 
deliveryServiceRequestService) {
+var FormNewDeliveryServiceController = function(deliveryService, type, types, 
$scope, $controller, $uibModal, $anchorScroll, locationUtils, 
deliveryServiceService, deliveryServiceRequestService, messageModel) {
 
        // extends the FormDeliveryServiceController to inherit common methods
        angular.extend(this, $controller('FormDeliveryServiceController', { 
deliveryService: deliveryService, dsCurrent: deliveryService, type: type, 
types: types, $scope: $scope }));
@@ -63,11 +63,21 @@ var FormNewDeliveryServiceController = 
function(deliveryService, type, types, $s
                                // do nothing
                        });
                } else {
-                       
deliveryServiceService.createDeliveryService(deliveryService);
+                       
deliveryServiceService.createDeliveryService(deliveryService).
+                               then(
+                                       function(result) {
+                                               messageModel.setMessages([ { 
level: 'success', text: 'Delivery Service [ ' + deliveryService.xmlId + ' ] 
created' } ], true);
+                                               
locationUtils.navigateToPath('/delivery-services/' + result.data.response[0].id 
+ '?type=' + result.data.response[0].type);
+                                       },
+                                       function(fault) {
+                                               $anchorScroll(); // scrolls 
window to top
+                                               
messageModel.setMessages(fault.data.alerts, false);
+                                       }
+                       );
                }
        };
 
 };
 
-FormNewDeliveryServiceController.$inject = ['deliveryService', 'type', 
'types', '$scope', '$controller', '$uibModal', 'deliveryServiceService', 
'deliveryServiceRequestService'];
+FormNewDeliveryServiceController.$inject = ['deliveryService', 'type', 
'types', '$scope', '$controller', '$uibModal', '$anchorScroll', 
'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 
'messageModel'];
 module.exports = FormNewDeliveryServiceController;
diff --git 
a/traffic_portal/app/src/common/modules/table/deliveryServiceRequests/TableDeliveryServiceRequestsController.js
 
b/traffic_portal/app/src/common/modules/table/deliveryServiceRequests/TableDeliveryServiceRequestsController.js
index bcdb97068..9bdb96199 100644
--- 
a/traffic_portal/app/src/common/modules/table/deliveryServiceRequests/TableDeliveryServiceRequestsController.js
+++ 
b/traffic_portal/app/src/common/modules/table/deliveryServiceRequests/TableDeliveryServiceRequestsController.js
@@ -163,6 +163,13 @@ var TableDeliveryServicesRequestsController = 
function(dsRequests, $scope, $stat
 
        $scope.rejectRequest = function(request, $event) {
                $event.stopPropagation(); // this kills the click event so it 
doesn't trigger anything else
+
+               if (request.assigneeId != userModel.user.id) {
+                       messageModel.setMessages([ { level: 'error', text: 
'Only the assignee can mark a delivery service request as rejected' } ], false);
+                       $anchorScroll(); // scrolls window to top
+                       return;
+               }
+
                var params = {
                        title: 'Reject Delivery Service Request',
                        message: 'Are you sure you want to reject this delivery 
service request?'
@@ -178,12 +185,8 @@ var TableDeliveryServicesRequestsController = 
function(dsRequests, $scope, $stat
                        }
                });
                modalInstance.result.then(function() {
-                       var promises = [];
-                       
promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(request.id,
 userModel.user.id));
-                       
promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(request.id,
 'rejected'));
-
-                       $q.all(promises)
-                               .then(
+                       
deliveryServiceRequestService.updateDeliveryServiceRequestStatus(request.id, 
'rejected').
+                               then(
                                        function() {
                                                $scope.refresh();
                                        });
@@ -196,7 +199,7 @@ var TableDeliveryServicesRequestsController = 
function(dsRequests, $scope, $stat
                $event.stopPropagation(); // this kills the click event so it 
doesn't trigger anything else
 
                if (request.assigneeId != userModel.user.id) {
-                       messageModel.setMessages([ { level: 'error', text: 
'Only the Assignee can mark a delivery service request as complete' } ], false);
+                       messageModel.setMessages([ { level: 'error', text: 
'Only the assignee can mark a delivery service request as complete' } ], false);
                        $anchorScroll(); // scrolls window to top
                        return;
                }
diff --git 
a/traffic_portal/app/src/modules/private/deliveryServiceRequests/edit/FormEditDeliveryServiceRequestController.js
 
b/traffic_portal/app/src/modules/private/deliveryServiceRequests/edit/FormEditDeliveryServiceRequestController.js
index a978d0619..18de2448c 100644
--- 
a/traffic_portal/app/src/modules/private/deliveryServiceRequests/edit/FormEditDeliveryServiceRequestController.js
+++ 
b/traffic_portal/app/src/modules/private/deliveryServiceRequests/edit/FormEditDeliveryServiceRequestController.js
@@ -103,7 +103,7 @@ var FormEditDeliveryServiceRequestController = 
function(deliveryServiceRequest,
                                        break;
                                case $scope.COMPLETE:
                                        if (dsRequest.assigneeId != 
userModel.user.id) {
-                                               messageModel.setMessages([ { 
level: 'error', text: 'Only the Assignee can mark a delivery service request as 
complete' } ], false);
+                                               messageModel.setMessages([ { 
level: 'error', text: 'Only the assignee can mark a delivery service request as 
complete' } ], false);
                                                $anchorScroll(); // scrolls 
window to top
                                                return;
                                        }
@@ -117,8 +117,19 @@ var FormEditDeliveryServiceRequestController = 
function(deliveryServiceRequest,
                });
        };
 
-       $scope.fulfillRequest = function(ds) {
+       var updateDeliveryServiceRequest = function() {
                var promises = [];
+               // update the ds request if the ds request actually changed
+               if ($scope.deliveryServiceForm.$dirty) {
+                       
promises.push(deliveryServiceRequestService.updateDeliveryServiceRequest(dsRequest.id,
 dsRequest));
+               }
+               // make sure the ds request is assigned to the user that is 
fulfilling the request
+               
promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(dsRequest.id,
 userModel.user.id));
+               // set the status to 'pending'
+               
promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(dsRequest.id,
 'pending'));
+       };
+
+       $scope.fulfillRequest = function(ds) {
                var params = {
                        title: 'Delivery Service ' + $scope.changeType + ': ' + 
ds.xmlId,
                        message: 'Are you sure you want to fulfill this 
delivery service request and ' + $scope.changeType + ' the ' + ds.xmlId + ' 
delivery service'
@@ -135,26 +146,33 @@ var FormEditDeliveryServiceRequestController = 
function(deliveryServiceRequest,
                        }
                });
                modalInstance.result.then(function() {
-                       // update the ds request if the ds request actually 
changed
-                       if ($scope.deliveryServiceForm.$dirty) {
-                               
promises.push(deliveryServiceRequestService.updateDeliveryServiceRequest(dsRequest.id,
 dsRequest));
-                       }
-                       // make sure the ds request is assigned to the user 
that is fulfilling the request
-                       
promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(dsRequest.id,
 userModel.user.id));
-                       // set the status to 'pending'
-                       
promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(dsRequest.id,
 'pending'));
-
                        // create, update or delete the ds per the ds request
                        if ($scope.changeType == 'create') {
                                
deliveryServiceService.createDeliveryService(ds).
-                                       then(function() {
-                                               $q.all(promises); // after a 
successful create, update the ds request, assignee and status
-                                       });
+                                       then(
+                                               function(result) {
+                                                       
updateDeliveryServiceRequest(); // after a successful create, update the ds 
request, assignee and status
+                                                       
messageModel.setMessages([ { level: 'success', text: 'Delivery Service [ ' + 
ds.xmlId + ' ] created' } ], true);
+                                                       
locationUtils.navigateToPath('/delivery-services/' + result.data.response[0].id 
+ '?type=' + result.data.response[0].type);
+                                               },
+                                               function(fault) {
+                                                       $anchorScroll(); // 
scrolls window to top
+                                                       
messageModel.setMessages(fault.data.alerts, false);
+                                               }
+                               );
                        } else if ($scope.changeType == 'update') {
-                               
deliveryServiceService.updateDeliveryService(ds, true).
-                                       then(function() {
-                                               $q.all(promises); // after a 
successful update, update the ds request, assignee and status
-                                       });
+                               
deliveryServiceService.updateDeliveryService(ds).
+                                       then(
+                                               function(result) {
+                                                       
updateDeliveryServiceRequest(); // after a successful update, update the ds 
request, assignee and status
+                                                       
messageModel.setMessages([ { level: 'success', text: 'Delivery Service [ ' + 
ds.xmlId + ' ] updated' } ], true);
+                                                       
locationUtils.navigateToPath('/delivery-services/' + result.data.response[0].id 
+ '?type=' + result.data.response[0].type);
+                                               },
+                                               function(fault) {
+                                                       $anchorScroll(); // 
scrolls window to top
+                                                       
messageModel.setMessages(fault.data.alerts, false);
+                                               }
+                                       );
                        } else if ($scope.changeType == 'delete') {
                                // and we're going to ask even again if they 
really want to delete but this time they need to enter the ds name to confirm 
the delete
                                params = {
@@ -172,13 +190,18 @@ var FormEditDeliveryServiceRequestController = 
function(deliveryServiceRequest,
                                        }
                                });
                                modalInstance.result.then(function() {
-                                       
deliveryServiceService.deleteDeliveryService(ds, true).
-                                       then(function() {
-                                               $q.all(promises) // after a 
successful delete, update the ds request, assignee and status and navigate to 
ds requests page
-                                                       .then(function() {
+                                       
deliveryServiceService.deleteDeliveryService(ds).
+                                               then(
+                                                       function() {
+                                                               
updateDeliveryServiceRequest(); // after a successful delete, update the ds 
request, assignee and status and navigate to ds requests page
+                                                               
messageModel.setMessages([ { level: 'success', text: 'Delivery service [ ' + 
ds.xmlId + ' ] deleted' } ], true);
                                                                
locationUtils.navigateToPath('/delivery-service-requests');
-                                                       });
-                                       });
+                                                       },
+                                                       function(fault) {
+                                                               
$anchorScroll(); // scrolls window to top
+                                                               
messageModel.setMessages(fault.data.alerts, false);
+                                                       }
+                                               );
                                }, function () {
                                        // do nothing
                                });


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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