From aa3a19fd60af78a33595663b780f318280293162 Mon Sep 17 00:00:00 2001 From: Alex Luckerman Date: Mon, 15 Jul 2019 11:51:04 -0600 Subject: [PATCH 1/4] Prevent DS changes while other requests are open --- .../edit/FormEditDeliveryServiceController.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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 9f6f3407c4..0fb852b6cd 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 @@ -22,6 +22,21 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, // extends the FormDeliveryServiceController to inherit common methods angular.extend(this, $controller('FormDeliveryServiceController', { deliveryService: deliveryService, dsCurrent: deliveryService, origin: origin, type: type, types: types, $scope: $scope })); + var confirmNoOutstandingRequests = function(deliveryService) { + deliveryServiceRequestService.getDeliveryServiceRequests() + .then( + function(dsRequests) { + // search all requests for those that are not completed and share the same deliveryservice id + angular.forEach(dsRequests, function(value) { + if (value.status != 'complete' && value.deliveryService.id == deliveryService.id) { + return false; + } + }); + return true; + } + ); + }; + var createDeliveryServiceDeleteRequest = function(deliveryService) { var params = { title: "Delivery Service Delete Request", @@ -61,7 +76,7 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, // if the user chooses to complete/fulfill the delete request immediately, the ds will be deleted and behind the // scenes a delivery service request will be created and marked as complete - if (options.status.id == $scope.COMPLETE) { + if (options.status.id == $scope.COMPLETE && confirmNoOutstandingRequests(deliveryService)) { // first delete the ds deliveryServiceService.deleteDeliveryService(deliveryService) .then( @@ -200,7 +215,7 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, }; // if the user chooses to complete/fulfill the update request immediately, the ds will be updated and behind the // scenes a delivery service request will be created and marked as complete - if (options.status.id == $scope.COMPLETE) { + if (options.status.id == $scope.COMPLETE && confirmNoOutstandingRequests(deliveryService)) { deliveryServiceService.updateDeliveryService(deliveryService). then( function() { From b4f1b0008aa80f34330b9860ed572c6baad62562 Mon Sep 17 00:00:00 2001 From: Alex Luckerman Date: Mon, 15 Jul 2019 14:39:15 -0600 Subject: [PATCH 2/4] Add sleep to fix DS requests test failing too fast --- .../DeliveryServiceRequests/delivery-service-requests-spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js b/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js index a9fb161e2a..2b4d57c387 100644 --- a/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js +++ b/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js @@ -144,6 +144,7 @@ describe('Traffic Portal Delivery Service Requests', function() { pageData.deleteButton.click(); pageData.confirmWithNameInput.sendKeys(mockVals.xmlId + ' request'); pageData.deletePermanentlyButton.click(); + browser.sleep(250); expect(browser.getCurrentUrl().then(commonFunctions.urlPath)).toEqual(commonFunctions.urlPath(browser.baseUrl)+"#!/delivery-service-requests"); }); }); From 6eaad6e860c37da6a71c2c17690e59767cce7f4e Mon Sep 17 00:00:00 2001 From: Alex Luckerman Date: Thu, 18 Jul 2019 13:52:32 -0600 Subject: [PATCH 3/4] Simplify the check for existing DS requests --- .../edit/FormEditDeliveryServiceController.js | 113 +++++++----------- 1 file changed, 46 insertions(+), 67 deletions(-) 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 0fb852b6cd..468f18f694 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 @@ -22,21 +22,6 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, // extends the FormDeliveryServiceController to inherit common methods angular.extend(this, $controller('FormDeliveryServiceController', { deliveryService: deliveryService, dsCurrent: deliveryService, origin: origin, type: type, types: types, $scope: $scope })); - var confirmNoOutstandingRequests = function(deliveryService) { - deliveryServiceRequestService.getDeliveryServiceRequests() - .then( - function(dsRequests) { - // search all requests for those that are not completed and share the same deliveryservice id - angular.forEach(dsRequests, function(value) { - if (value.status != 'complete' && value.deliveryService.id == deliveryService.id) { - return false; - } - }); - return true; - } - ); - }; - var createDeliveryServiceDeleteRequest = function(deliveryService) { var params = { title: "Delivery Service Delete Request", @@ -76,44 +61,40 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, // if the user chooses to complete/fulfill the delete request immediately, the ds will be deleted and behind the // scenes a delivery service request will be created and marked as complete - if (options.status.id == $scope.COMPLETE && confirmNoOutstandingRequests(deliveryService)) { - // first delete the ds - deliveryServiceService.deleteDeliveryService(deliveryService) - .then( - function() { - // then create the ds request - deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest). - then( - function(response) { - var comment = { - deliveryServiceRequestId: response.id, - value: options.comment - }; - // then create the ds request comment - deliveryServiceRequestService.createDeliveryServiceRequestComment(comment). - then( - function() { - var promises = []; - // assign the ds request - promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(response.id, userModel.user.id)); - // set the status to 'complete' - promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(response.id, 'complete')); - // and finally navigate to the /delivery-services page - 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); - } - ); - - - + if (options.status.id === $scope.COMPLETE) { + // first create the ds request + deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest) + .then(function(response) { + var comment = { + deliveryServiceRequestId: response.id, + value: options.comment + }; + // then create the ds request comment + deliveryServiceRequestService.createDeliveryServiceRequestComment(comment). + then( + function() { + var promises = []; + // assign the ds request + promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(response.id, userModel.user.id)); + // set the status to 'complete' + promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(response.id, 'complete')); + // and finally navigate to the /delivery-services page + messageModel.setMessages([ { level: 'success', text: 'Delivery service [ ' + deliveryService.xmlId + ' ] deleted' } ], true); + locationUtils.navigateToPath('/delivery-services'); + } + // then, if all that works, delete the ds + ).then( + function() { + deliveryServiceService.deleteDeliveryService(deliveryService); + } + ); + } + // handle any failures just once + ).catch(function(fault) { + $anchorScroll(); // scrolls window to top + messageModel.setMessages(fault.data.alerts, false); + } + ); } else { deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest). then( @@ -138,7 +119,7 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, }; var createDeliveryServiceUpdateRequest = function(dsRequest, dsRequestComment, autoFulfilled) { - deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest). + return deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest). then( function(response) { var comment = { @@ -215,19 +196,17 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, }; // if the user chooses to complete/fulfill the update request immediately, the ds will be updated and behind the // scenes a delivery service request will be created and marked as complete - if (options.status.id == $scope.COMPLETE && confirmNoOutstandingRequests(deliveryService)) { - 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); - createDeliveryServiceUpdateRequest(dsRequest, options.comment, true); - }, - function(fault) { - $anchorScroll(); // scrolls window to top - messageModel.setMessages(fault.data.alerts, false); - } - ); + if (options.status.id == $scope.COMPLETE) { + createDeliveryServiceUpdateRequest(dsRequest, options.comment, true).then( + function() { + 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); + }).catch(function(fault) { + $anchorScroll(); // scrolls window to top + messageModel.setMessages(fault.data.alerts, false); + }); } else { createDeliveryServiceUpdateRequest(dsRequest, options.comment, false); } From a224ea59a6c5fb5ff1a6987f707ff97f2ce5ad36 Mon Sep 17 00:00:00 2001 From: Alex Luckerman Date: Mon, 22 Jul 2019 17:55:40 -0600 Subject: [PATCH 4/4] Fix comments describing code logic --- .../edit/FormEditDeliveryServiceController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 468f18f694..e6d297ea38 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 @@ -59,8 +59,8 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, deliveryService: deliveryService }; - // if the user chooses to complete/fulfill the delete request immediately, the ds will be deleted and behind the - // scenes a delivery service request will be created and marked as complete + // if the user chooses to complete/fulfill the delete request immediately, a delivery service request will be made and marked as complete, + // then if that is successful, the DS will be deleted if (options.status.id === $scope.COMPLETE) { // first create the ds request deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest) @@ -194,8 +194,8 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type, status: status, deliveryService: deliveryService }; - // if the user chooses to complete/fulfill the update request immediately, the ds will be updated and behind the - // scenes a delivery service request will be created and marked as complete + // if the user chooses to complete/fulfill the update request immediately, a delivery service request will be made and marked as complete, + // then if that is successful, the DS will be updated if (options.status.id == $scope.COMPLETE) { createDeliveryServiceUpdateRequest(dsRequest, options.comment, true).then( function() {