Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function checkAuthRequiredForSpecificSituations($parts): bool
($parts[0] == 'shipment' && $parts[1] == 'containers' && $parts[2] == 'history' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) ||

# Allow shipping service to update dewar status
($parts[0] == 'shipment' && $parts[1] == 'dewars' && ($parts[2] == 'confirmdispatch' || $parts[2] == 'confirmpickup'))
($parts[0] == 'shipment' && $parts[1] == 'dewars' && $parts[2] == 'confirm')
)
{
$need_auth = false;
Expand Down
51 changes: 37 additions & 14 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class Shipment extends Page
'PROPOSALTYPE' => '\w+',
'pickup_confirmation_code' => '\w+',
'status' => '\w+',
'journey_type' => '\w+',

'manifest' => '\d',
'currentuser' => '\d',
Expand Down Expand Up @@ -210,8 +211,7 @@ class Shipment extends Page

array('/dewars/transfer', 'post', '_transfer_dewar'),
array('/dewars/dispatch', 'post', '_dispatch_dewar'),
array('/dewars/confirmdispatch/did/:did/token/:TOKEN', 'post', '_outgoing_shipment_confirmation'),
array('/dewars/confirmpickup/sid/:sid/token/:TOKEN', 'post', '_incoming_shipment_confirmation'),
array('/dewars/confirm/did/:did/token/:TOKEN', 'post', '_shipment_confirmation'),

array('/dewars/tracking(/:DEWARID)', 'get', '_get_dewar_tracking'),

Expand Down Expand Up @@ -1109,7 +1109,7 @@ function _dispatch_dewar_shipment_request($dewar)
array($token, $external_id)
);

$callback_url = "/api/shipment/dewars/confirmdispatch/did/{$external_id}/token/{$token}";
$callback_url = "/api/shipment/dewars/confirm/did/{$external_id}/token/{$token}";
$external_shipping_id = $this->_create_dewars_shipment_request($dewars, $proposal, $session_number, $external_id, $shipping_id, $callback_url);

$this->db->pq(
Expand Down Expand Up @@ -1403,15 +1403,43 @@ function _dispatch_dewar()
}
}

function _outgoing_shipment_confirmation()
function _shipment_confirmation()
{
if (!$this->has_arg('journey_type'))
$this->_error('No journey type specified');
if (!$this->has_arg('did'))
$this->_error('No dewar specified');
if (!$this->has_arg('TOKEN'))
$this->_error('No token specified');
if (!$this->has_arg('status'))
$this->_error('No status specified');

$dew = $this->db->pq(
"SELECT d.shippingid,
json_unquote(json_extract(d.extra, '$.token')) as token
FROM dewar d
WHERE d.dewarid=:1",
array($this->arg('did'))
);
if (!sizeof($dew))
$this->_error('No such dewar');
else
$dew = $dew[0];

if (!$this->has_arg('TOKEN') || $this->arg('TOKEN') !== $dew['TOKEN']) {
$this->_error('Incorrect token');
}

if ($this->arg('journey_type') === 'TO_FACILITY') {
$this->set_arg('sid', $dew['SHIPPINGID']);
$this->_incoming_shipment_confirmation();
} else if ($this->arg('journey_type') === 'FROM_FACILITY') {
$this->_outgoing_shipment_confirmation();
} else {
$this->_error('Invalid journey type');
}
}

function _outgoing_shipment_confirmation()
{
if ($this->arg('status') === 'CREATED') {
$this->_cancel_dispatch_dewar_confirmation();
} else if ($this->arg('status') === 'BOOKED' || $this->arg('status') === 'PENDING') {
Expand Down Expand Up @@ -1563,13 +1591,6 @@ function _cancel_dispatch_dewar_confirmation()

function _incoming_shipment_confirmation()
{
if (!$this->has_arg('sid'))
$this->_error('No shipment specified');
if (!$this->has_arg('TOKEN'))
$this->_error('No token specified');
if (!$this->has_arg('status'))
$this->_error('No status specified');

if ($this->arg('status') === 'CREATED') {
$this->_cancel_pickup_dewar_confirmation();
} else if ($this->arg('status') === 'BOOKED' || $this->arg('status') === 'PENDING') {
Expand Down Expand Up @@ -3514,14 +3535,16 @@ function _create_shipment_shipment_request($shipment, array $dewars): int
{

$shipping_id = (int) $shipment['SHIPPINGID'];
// Any dewar id is ok for callback as it will be converted back to a shipping id
$dewar_id = (int) $dewars[0]['DEWARID'];

$token = Utils::generateRandomMd5(7);
$this->db->pq(
"UPDATE dewar SET extra = JSON_SET(IFNULL(extra, '{}'), '$.token', :1 ) WHERE shippingid=:2",
array($token, $shipping_id)
);

$callback_url = "/api/shipment/dewars/confirmpickup/sid/{$shipping_id}/token/{$token}";
$callback_url = "/api/shipment/dewars/confirm/did/{$dewar_id}/token/{$token}";

$external_shipping_id = $this->_create_dewars_shipment_request(
$dewars,
Expand Down
Loading