Skip to content

Commit

Permalink
allow the user to skip delivery service requests if they have the app…
Browse files Browse the repository at this point in the history
…ropriate role as defined in traffic_portal_properties.json
  • Loading branch information
mitchell852 authored and dangogh committed May 18, 2018
1 parent 0b0e0f9 commit 20709b9
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 297 deletions.
4 changes: 2 additions & 2 deletions lib/go-tc/deliveryservice_requests.go
Expand Up @@ -184,8 +184,8 @@ func (r RequestStatus) ValidTransition(to RequestStatus) error {
return nil
}
case RequestStatusComplete:
// only pending can be completed. Completed can never change.
if r == RequestStatusPending {
// only submitted or pending requests can be completed
if r == RequestStatusSubmitted || r == RequestStatusPending {
return nil
}
}
Expand Down
6 changes: 4 additions & 2 deletions traffic_ops/app/lib/API/User.pm
Expand Up @@ -536,7 +536,7 @@ sub current {
my @data;
my $current_username = $self->current_user()->{username};
if ( &is_ldap($self) ) {
my $role = $self->db->resultset('Role')->search( { name => "read-only" } )->get_column('id')->single;
my $role = $self->db->resultset('Role')->search( { name => "read-only" } )->single;

push(
@data, {
Expand All @@ -545,7 +545,8 @@ sub current {
"tenantId" => undef,
"tenant" => undef,
"publicSshKey" => "",
"role" => $role,
"role" => $role->id,
"roleName" => $role->name,
"uid" => "0",
"gid" => "0",
"company" => "",
Expand Down Expand Up @@ -574,6 +575,7 @@ sub current {
"username" => $row->username,
"publicSshKey" => $row->public_ssh_key,
"role" => $row->role->id,
"roleName" => $row->role->name,
"uid" => $row->uid,
"gid" => $row->gid,
"company" => $row->company,
Expand Down
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

var FormEditDeliveryServiceController = function(deliveryService, type, types, $scope, $state, $controller, $uibModal, $anchorScroll, locationUtils, deliveryServiceService, deliveryServiceRequestService, messageModel) {
var FormEditDeliveryServiceController = function(deliveryService, type, types, $scope, $state, $controller, $uibModal, $anchorScroll, locationUtils, deliveryServiceService, deliveryServiceRequestService, messageModel, propertiesModel, userModel) {

// extends the FormDeliveryServiceController to inherit common methods
angular.extend(this, $controller('FormDeliveryServiceController', { deliveryService: deliveryService, dsCurrent: deliveryService, type: type, types: types, $scope: $scope }));
Expand All @@ -36,38 +36,120 @@ var FormEditDeliveryServiceController = function(deliveryService, type, types, $
return params;
},
statuses: function() {
return [
{ id: $scope.DRAFT, name: 'Save as Draft' },
{ id: $scope.SUBMITTED, name: 'Submit for Review and Deployment' }
var statuses = [
{ id: $scope.DRAFT, name: 'Save Request as Draft' },
{ id: $scope.SUBMITTED, name: 'Submit Request for Review and Deployment' }
];
if (userModel.user.roleName == propertiesModel.properties.dsRequests.roleNeededToSkip) {
statuses.push({ id: $scope.COMPLETE, name: 'Fulfill Request Immediately' });
}
return statuses;
}
}
});
modalInstance.result.then(function(options) {
var status = 'draft';
if (options.status.id == $scope.SUBMITTED || options.status.id == $scope.COMPLETE) {
status = 'submitted';
};

var dsRequest = {
changeType: 'delete',
status: (options.status.id == $scope.SUBMITTED) ? 'submitted' : 'draft',
status: status,
deliveryService: deliveryService
};
deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
then(
function(response) {
var comment = {
deliveryServiceRequestId: response.id,
value: options.comment
};
deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
then(
function() {

// 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) {
// 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);
}
);



} else {
deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
then(
function(response) {
var comment = {
deliveryServiceRequestId: response.id,
value: options.comment
};
deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
then(
function() {
messageModel.setMessages([ { level: 'success', text: 'Created request to ' + dsRequest.changeType + ' the ' + dsRequest.deliveryService.xmlId + ' delivery service' } ], true);
locationUtils.navigateToPath('/delivery-service-requests');
}
);
}
);
}
}, function () {
// do nothing
});
};

var createDeliveryServiceUpdateRequest = function(dsRequest, dsRequestComment, autoFulfilled) {
deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
then(
function(response) {
var comment = {
deliveryServiceRequestId: response.id,
value: dsRequestComment
};
var promises = [];

deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
then(
function() {
if (!autoFulfilled) {
messageModel.setMessages([ { level: 'success', text: 'Created request to ' + dsRequest.changeType + ' the ' + dsRequest.deliveryService.xmlId + ' delivery service' } ], true);
locationUtils.navigateToPath('/delivery-service-requests');
}
);
}
);

if (autoFulfilled) {
// 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'));
}
);
}, function () {
// do nothing
});
}
);
};

$scope.deliveryServiceName = angular.copy(deliveryService.xmlId);
Expand All @@ -80,6 +162,7 @@ var FormEditDeliveryServiceController = function(deliveryService, type, types, $
};

$scope.save = function(deliveryService) {
// if ds requests are enabled in traffic_portal_properties.json, we'll create a ds request, else just update the ds
if ($scope.dsRequestsEnabled) {
var params = {
title: "Delivery Service Update Request",
Expand All @@ -94,35 +177,46 @@ var FormEditDeliveryServiceController = function(deliveryService, type, types, $
return params;
},
statuses: function() {
return [
{ id: $scope.DRAFT, name: 'Save as Draft' },
{ id: $scope.SUBMITTED, name: 'Submit for Review and Deployment' }
var statuses = [
{ id: $scope.DRAFT, name: 'Save Request as Draft' },
{ id: $scope.SUBMITTED, name: 'Submit Request for Review and Deployment' }
];
if (userModel.user.roleName == propertiesModel.properties.dsRequests.roleNeededToSkip) {
statuses.push({ id: $scope.COMPLETE, name: 'Fulfill Request Immediately' });
}
return statuses;
}
}
});
modalInstance.result.then(function(options) {
var status = 'draft';
if (options.status.id == $scope.SUBMITTED || options.status.id == $scope.COMPLETE) {
status = 'submitted';
};
var dsRequest = {
changeType: 'update',
status: (options.status.id == $scope.SUBMITTED) ? 'submitted' : 'draft',
status: status,
deliveryService: deliveryService
};
deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
then(
function(response) {
var comment = {
deliveryServiceRequestId: response.id,
value: options.comment
};
deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
then(
function() {
messageModel.setMessages([ { level: 'success', text: 'Created request to ' + dsRequest.changeType + ' the ' + dsRequest.deliveryService.xmlId + ' delivery service' } ], true);
locationUtils.navigateToPath('/delivery-service-requests');
}
);
}
);
// 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) {
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);
}
);
} else {
createDeliveryServiceUpdateRequest(dsRequest, options.comment, false);
}

}, function () {
// do nothing
});
Expand All @@ -142,24 +236,24 @@ var FormEditDeliveryServiceController = function(deliveryService, type, types, $
};

$scope.confirmDelete = function(deliveryService) {
if ($scope.dsRequestsEnabled) {
createDeliveryServiceDeleteRequest(deliveryService);
} else {
var params = {
title: 'Delete Delivery Service: ' + deliveryService.xmlId,
key: deliveryService.xmlId
};
var modalInstance = $uibModal.open({
templateUrl: 'common/modules/dialog/delete/dialog.delete.tpl.html',
controller: 'DialogDeleteController',
size: 'md',
resolve: {
params: function () {
return params;
}
var params = {
title: 'Delete Delivery Service: ' + deliveryService.xmlId,
key: deliveryService.xmlId
};
var modalInstance = $uibModal.open({
templateUrl: 'common/modules/dialog/delete/dialog.delete.tpl.html',
controller: 'DialogDeleteController',
size: 'md',
resolve: {
params: function () {
return params;
}
});
modalInstance.result.then(function() {
}
});
modalInstance.result.then(function() {
if ($scope.dsRequestsEnabled) {
createDeliveryServiceDeleteRequest(deliveryService);
} else {
deliveryServiceService.deleteDeliveryService(deliveryService)
.then(
function() {
Expand All @@ -171,14 +265,13 @@ var FormEditDeliveryServiceController = function(deliveryService, type, types, $
messageModel.setMessages(fault.data.alerts, false);
}
);
}, function () {
// do nothing
});
}

}
}, function () {
// do nothing
});
};

};

FormEditDeliveryServiceController.$inject = ['deliveryService', 'type', 'types', '$scope', '$state', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 'messageModel'];
FormEditDeliveryServiceController.$inject = ['deliveryService', 'type', 'types', '$scope', '$state', '$controller', '$uibModal', '$anchorScroll', 'locationUtils', 'deliveryServiceService', 'deliveryServiceRequestService', 'messageModel', 'propertiesModel', 'userModel'];
module.exports = FormEditDeliveryServiceController;

0 comments on commit 20709b9

Please sign in to comment.