Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pre-release/2024-R5.4 with master #892

Merged
merged 5 commits into from
Jan 10, 2025
Merged
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
25 changes: 7 additions & 18 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@
$enabled_container_types = array();

# Zocalo message broker credentials - Set to empty string to disable
$zocalo_server = 'tcp://activemq.server.ac.uk';
$zocalo_username = 'foo';
$zocalo_password = 'bar';

# Primary Zocalo entry point for recipe submission
$zocalo_mx_reprocess_queue = '/queue/zocolo.name';
$rabbitmq_zocalo_host = 'rabbitmq.server.ac.uk';
$rabbitmq_zocalo_port = 5672;
$rabbitmq_zocalo_username = 'foo';
$rabbitmq_zocalo_password = 'bar';
$rabbitmq_zocalo_vhost = 'zocalo';
$rabbitmq_zocalo_routing_key = 'processing_recipe';

# This is used to trigger Zocalo recipes on adding new Protein sequences
# Set to empty string to disable
Expand Down Expand Up @@ -193,18 +193,6 @@
$in_contacts = array('Ind Contact' => '[email protected]'
);


# Beamline Sample Registration Machines
# - Used for touchscreen application (unauthenticated)
$blsr = array('1.2.3.4', # my touchscreen computer
);

# Beamline Sample Registration IP -> Beamline mapping
# - Third part of ip is used to identify beamline
#  x.x.103.x => i03
$ip2bl = array(103 => 'i03',
);

# Barcode readers
# - These clients use the android app (unauthenticated)
$bcr = array('1.2.3.4', # my android device
Expand Down Expand Up @@ -393,4 +381,5 @@
# Dials server values
$dials_rest_url = "";
$dials_rest_jwt = "";
$dials_rest_url_rings = false;
?>
4 changes: 3 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function setupApplication($mode): Slim
$facility_courier_countries, $facility_courier_countries_nde, $facility_courier_countries_link,
$dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types, $ifsummary, $synchweb_version, $redirects,
$shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments;
$shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments,
$dials_rest_url_rings;
$app->contentType('application/json');
$options = $app->container['options'];
$app->response()->body(json_encode(array(
Expand All @@ -95,6 +96,7 @@ function setupApplication($mode): Slim
'synchweb_version' => $synchweb_version,
'shipping_service_app_url' => $use_shipping_service_redirect || $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null,
'shipping_service_app_url_incoming' => $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null,
'dials_rest_url_rings' => $dials_rest_url_rings,
'redirects' => $redirects
)));
});
Expand Down
26 changes: 1 addition & 25 deletions api/src/Controllers/AssignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AssignController extends Page

public static $arg_list = array('visit' => '\w+\d+-\d+', 'cid' => '\d+', 'did' => '\d+', 'pos' => '\d+', 'bl' => '[\w\-]+');

public static $dispatch = array(array('/visits(/:visit)', 'get', 'getBeamlineVisits'),
public static $dispatch = array(
array('/assign', 'get', 'assignContainer'),
array('/unassign', 'get', 'unassignContainer'),
array('/deact', 'get', 'deactivateDewar'),
Expand Down Expand Up @@ -74,30 +74,6 @@ function deactivateDewar()
}
}


# ------------------------------------------------------------------------
# Return visits for beamline
function getBeamlineVisits($visit = null)
{
$visits = $this->blsr_visits();

if ($visit)
{
foreach ($visits as $i => $v)
{
if ($v['VISIT'] == $visit)
{
$this->_output($v);
return;
}
}
$this->_error('No such visit');
}
else
$this->_output($visits);
}


# ------------------------------------------------------------------------
# Puck names from puck scanner
# BL03I-MO-ROBOT-01:PUCK_01_NAME
Expand Down
11 changes: 1 addition & 10 deletions api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function check()

private function checkAuthRequiredForSpecificSituations($parts): bool
{
global $blsr, $bcr, $img, $auto;
global $bcr, $img, $auto;

$need_auth = true;
# Work around to allow beamline sample registration without CAS authentication
Expand All @@ -102,10 +102,6 @@ private function checkAuthRequiredForSpecificSituations($parts): bool
# Allow formulatrix machines unauthorised access to inspections, certain IPs only
($parts[0] == 'imaging' && $parts[1] == 'inspection' && in_array($_SERVER["REMOTE_ADDR"], $img)) ||

# For use on the touchscreen computers in the hutch.
# Handles api calls: /assign/visits/<vist> e.g./assign/visits/mx1234-1
($parts[0] == 'assign' && $parts[1] == 'visits' && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||

# Allow barcode reader ips unauthorised access to add history
($parts[0] == 'shipment' && $parts[1] == 'dewars' && $parts[2] == 'history' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) ||

Expand All @@ -129,11 +125,6 @@ private function checkAuthRequiredForSpecificSituations($parts): bool
else if (sizeof($parts) >= 2)
{
if (
# For use on the touchscreen computers in the hutch
# Handles api calls: /assign/assign, /assign/unassign, /assign/deact, /assign/visits
(($parts[0] == 'assign') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||
(($parts[0] == 'shipment' && $parts[1] == 'containers') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||

# Allow barcode reader unauthorised access, same as above, certain IPs only
($parts[0] == 'shipment' && $parts[1] == 'dewars' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) ||

Expand Down
11 changes: 3 additions & 8 deletions api/src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,8 @@ function _update_user()
$person = $this->userData->getUser($this->user->personId, $this->proposalid, $this->arg('PERSONID'));
$person = $person[0];
$this->_output((array) $person);
$laboratory = null;
if ($person['LABORATORYID'])
{
$laboratory = $this->userData->getLaboratory($person['LABORATORYID'])[0];
}

$this->userData->updateLaboratory(
$laboratoryId = $this->userData->updateLaboratory(
$this->arg('PERSONID'),
$this->argOrNull('LABNAME'),
$this->argOrNull('ADDRESS'),
Expand All @@ -290,7 +285,7 @@ function _update_user()
$this->argOrNull('COUNTRY'),
$person['LABORATORYID']
);
$laboratory = $this->userData->getLaboratory($person['LABORATORYID']);
$laboratory = $this->userData->getLaboratory($laboratoryId);
$this->_output((array) $laboratory[0]);
}

Expand Down Expand Up @@ -362,4 +357,4 @@ function _update_permission()
);
$this->_output(array('TYPE' => $this->arg('TYPE'), 'DESCRIPTION' => $desc));
}
}
}
1 change: 1 addition & 0 deletions api/src/Model/Services/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ function updateLaboratory($personId, $labName, $labAddress, $city, $postcode, $c
->whereIdEquals("personid", $personId)
->update("person");
}
return $laboratoryId;
}

function addGroupUser($personId, $gid)
Expand Down
66 changes: 4 additions & 62 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,8 @@ function auth($require_staff)
{
$auth = $this->staff;

// Beamline Sample Registration
}
else if ($this->blsr() && !$this->user->loginId)
{
$auth = false;

if ($this->has_arg('visit'))
{
$blsr_visits = array();
foreach ($this->blsr_visits() as $v)
array_push($blsr_visits, $v['VISIT']);

if (in_array($this->arg('visit'), $blsr_visits))
$auth = True;

}
else
{
$auth = true;
}

// Barcode Scanners
}
// Barcode Scanners
else if ($this->bcr() && !$this->user->loginId)
{
$auth = true;
Expand Down Expand Up @@ -761,42 +740,6 @@ function pro()
}


# ------------------------------------------------------------------------
# Beamline sample registration: Get Beamline from IP
function ip2bl()
{
global $ip2bl;
$parts = explode('.', $_SERVER['REMOTE_ADDR']);

if ($parts && sizeof($parts) > 1 && array_key_exists($parts[2], $ip2bl))
{
return $ip2bl[$parts[2]];
}
}


# Return visit list for blsr;
function blsr_visits()
{
$b = $this->ip2bl();

if (!$b)
return array();

$visits = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE TIMESTAMPDIFF('DAY', s.startdate, CURRENT_TIMESTAMP) < 1 AND TIMESTAMPDIFF('DAY', CURRENT_TIMESTAMP, s.enddate) < 2 AND s.beamlinename LIKE :1 ORDER BY s.startdate", array($b));
$v = $this->db->paginate("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode LIKE 'cm' AND s.beamlinename LIKE :1 AND s.enddate <= CURRENT_TIMESTAMP ORDER BY s.startdate DESC", array($b, 0, 1));
$visits = array_merge($visits, $v);
return $visits;
}

# Beamline Sample Registration Machine
function blsr()
{
global $blsr;

return in_array($_SERVER['REMOTE_ADDR'], $blsr);
}

# Barcode Scanner Machines
function bcr()
{
Expand Down Expand Up @@ -1093,9 +1036,9 @@ function get_visit_processed_dir($dc, $location)

function _submit_zocalo_recipe($recipe, $parameters, $error_code = 500)
{
global $zocalo_mx_reprocess_queue;
global $rabbitmq_zocalo_vhost;

if (isset($zocalo_mx_reprocess_queue))
if (isset($rabbitmq_zocalo_vhost))
{
// Send job to processing queue
$zocalo_message = array(
Expand All @@ -1104,7 +1047,7 @@ function _submit_zocalo_recipe($recipe, $parameters, $error_code = 500)
),
'parameters' => $parameters,
);
$this->_send_zocalo_message($zocalo_mx_reprocess_queue, $zocalo_message, $error_code);
$this->_send_zocalo_message($rabbitmq_zocalo_vhost, $zocalo_message, $error_code);
}
}

Expand All @@ -1130,7 +1073,6 @@ function _send_zocalo_message($rabbitmq_zocalo_vhost, $zocalo_message, $error_co

try
{
error_log("Sending message" . var_export($zocalo_message, true));
$queue = new Queue($rabbitmq_zocalo_host, $rabbitmq_zocalo_port, $rabbitmq_zocalo_username, $rabbitmq_zocalo_password, $rabbitmq_zocalo_vhost);
$queue->send($zocalo_message, $rabbitmq_zocalo_routing_key);
}
Expand Down
8 changes: 6 additions & 2 deletions api/src/Page/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class Image extends Page
'aid' => '\d+',
'visit' => '\w+\d+-\d+',
'thresh' => '\d',
'res' => '\d',
'ice' => '\d',
);

public static $dispatch = array(array('/id/:id(/n/:n)', 'get', '_xtal_image'),
array('/diff/id/:id(/f/:f)(/n/:n)', 'get', '_diffraction_image'),
array('/di/id/:id(/thresh/:thresh)(/n/:n)', 'get', '_diffraction_viewer'),
array('/di/id/:id(/thresh/:thresh)(/res/:res)(/ice/:ice)(/n/:n)', 'get', '_diffraction_viewer'),
array('/cam/bl/:bl(/n/:n)', 'get', '_forward_webcam'),
array('/oav/bl/:bl(/n/:n)', 'get', '_forward_oav'),
array('/fa/fid/:id', 'get', '_fault_attachment'),
Expand Down Expand Up @@ -192,7 +194,7 @@ function _diffraction_viewer() {
}

$im = $info['LOC'] . '/' . $info['FT'];
$out = '/tmp/' . $this->arg('id') . '_' . $n . ($this->has_arg('thresh') ? '_th' : '') . '.jpg';
$out = '/tmp/' . $this->arg('id') . '_' . $n . ($this->has_arg('thresh') ? '_th' : '') . ($this->has_arg('res') ? '_res' : '') . ($this->has_arg('ice') ? '_ice' : '') . '.jpg';
global $dials_rest_url, $dials_rest_jwt;
if (!file_exists($out)) {
if (!empty($dials_rest_url) && !empty($dials_rest_jwt)) {
Expand All @@ -212,6 +214,8 @@ function _diffraction_viewer() {
'colour_scheme' => 'greyscale',
'brightness' => $this->has_arg('thresh') ? 1000 : 10,
'format' => 'png',
'resolution_rings' => array('show' => $this->has_arg('res')),
'ice_rings' => array('show' => $this->has_arg('ice')),
)
));
} else {
Expand Down
10 changes: 4 additions & 6 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ function _update_autocollect_session($sessionId, $uasSessionId, $containerId, $t
$uas = new UAS($auto_user, $auto_pass);
$code = $uas->update_session($uasSessionId, $data);

if ($code == 200) {
// Update ISPyB records
if ($code == 200 || $code == 404) {
// Update ISPyB records, even if UAS says session not found
$this->db->pq("UPDATE container SET sessionid=:1 WHERE containerid=:2", array($sessionId, $containerId));
// For debugging - actually just want to return Success!
$result = array(
Expand All @@ -1216,13 +1216,11 @@ function _update_autocollect_session($sessionId, $uasSessionId, $containerId, $t
);
} else if ($code == 403) {
$this->_error('UAS Error - samples and/or investigators not valid. ISPyB/UAS Session ID: ' . $sessionId . ' / ' . $uasSessionId);
} else if ($code == 404) {
$this->_error('UAS Error - session not found in UAS, Session ID: ' . $sessionId . ' UAS Session ID: ' . $uasSessionId);
} else {
$this->_error('UAS Error - something wrong creating a session for that container ' . $containerId . ', response code was: ' . $code);
$this->_error('UAS Error - something went wrong updating a session for that container ' . $containerId . ', response code was: ' . $code);
}
} else {
error_log("Something wrong - an Auto Collect session exists but with no containers " . $sessionId);
error_log("Something went wrong - an Auto Collect session exists but with no containers " . $sessionId);

$this->_error('No valid containers on the existing Auto Collect Session id:', $sessionId);
}
Expand Down
Loading
Loading