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

LIMS-1570: Remove unused app file #874

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
12 changes: 0 additions & 12 deletions api/config_sample.php
Original file line number Diff line number Diff line change
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
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
58 changes: 1 addition & 57 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,7 @@ function auth($require_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 +741,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
50 changes: 0 additions & 50 deletions api/tests/Controllers/AssignControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ protected function setUp(): void
$this->assignController->shouldReceive('_setup_routes')->times(1)->andReturn(Mockery::self());
$this->assignController->__construct($this->slimStub, $this->dbStub, $this->user, $this->dataLayerStub);

global $ip2bl;
$ip2bl = array(103 => 'i03');

global $bl_puck_names;
$bl_puck_names = array(
'i03' => "BL03I-MO-ROBOT-01:PUCK_%'02d_NAME",
Expand Down Expand Up @@ -146,53 +143,6 @@ public function testDeactivateDewarReturnsOneWhenDewarFound(): void
$this->assertEquals(1, $response->getBody());
}

public function testGetBeamlineVisitsWithInvalidNoConfigReturnsNothing(): void
{
$response = $this->setUpCommonResponse();
$_SERVER['REMOTE_ADDR'] = '';

$this->assignController->getBeamlineVisits();
$this->assertEquals('[]', $response->getBody());
}

public function testGetBeamlineVisitsWithValidConfigReturnsNothing(): void
{
$response = $this->setUpCommonResponse();
$_SERVER['REMOTE_ADDR'] = 'www.diamond.103.com';
$this->dbStub->expects($this->exactly(1))->method('pq')->with("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('i03'))->willReturn(array());
$this->dbStub->expects($this->exactly(1))->method('paginate')->with("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('i03', 0, 1))->willReturn(array());

$this->assignController->getBeamlineVisits();
$this->assertEquals('[]', $response->getBody());
}

public function testGetBeamlineVisitsWithValidConfigAndVisitReturnsData(): void
{
$visitId = 123;
$response = $this->setUpCommonResponse();
$_SERVER['REMOTE_ADDR'] = 'www.diamond.103.com';
$result = ['VISIT' => $visitId, 'BL' => 'test03'];
$this->dbStub->expects($this->exactly(1))->method('pq')->with("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('i03'))->willReturn(array($result));
$this->dbStub->expects($this->exactly(1))->method('paginate')->with("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('i03', 0, 1))->willReturn(array());

$this->assignController->getBeamlineVisits($visitId);
$this->assertEquals('{"VISIT":123,"BL":"test03"}', $response->getBody());
}

public function testGetBeamlineVisitsWithValidConfigAndInvalidVisitReturnsError(): void
{
$visitId = 123;
$_SERVER['REMOTE_ADDR'] = 'www.diamond.103.com';
$result = ['VISIT' => 1230, 'BL' => 'test03'];
$this->dbStub->expects($this->exactly(1))->method('pq')->with("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('i03'))->willReturn(array($result));
$this->dbStub->expects($this->exactly(1))->method('paginate')->with("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('i03', 0, 1))->willReturn(array());

$this->slimStub->shouldReceive('halt')->times(1)->with(400, '{"status":400,"message":"No such visit"}')->andThrow(new \Exception);
$this->expectException(\Exception::class);

$this->assignController->getBeamlineVisits($visitId);
}

public function testGetPuckNamesWithoutPropThrowsError(): void
{
$this->slimStub->shouldReceive('halt')->times(1)->with(400, '{"status":400,"message":"No proposal specified"}')->andThrow(new \Exception);
Expand Down
Loading
Loading