Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/prerelease' into improvement/LIM…
Browse files Browse the repository at this point in the history
…S-276/speed-up-get-all-containers-count

Use the sub sample sub select query from LIMS-452
  • Loading branch information
John Holt authored and John Holt committed Aug 17, 2023
2 parents 990c32c + c53a41f commit 1f3255d
Show file tree
Hide file tree
Showing 139 changed files with 15,491 additions and 9,879 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ on:
push:
branches:
- 'master'
- 'prerelease'
- 'release/**'
- 'pre-release/**'
pull_request:
branches:
- 'master'
- 'prerelease'
- 'release/**'
- 'pre-release/**'

Expand Down Expand Up @@ -54,7 +56,7 @@ jobs:
with:
bootstrap: api/vendor/autoload.php
configuration: api/tests/phpunit.xml
php_extensions: xdebug mysqli
php_extensions: xdebug mysqli zip
args: --coverage-text
php_version: 7.3
version: 9
Expand All @@ -70,11 +72,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: JavaScript build, lint and test
working-directory: ./client
# hack the output from the linting steps to avoid these stopping the builds - we are not going to get
# to a clean output without considerable effort, but it's useful to see the output
run: |
node --version
npm ci
npm run build
npm run test
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ If not using the development VMs you will also need an instance of the
ISPyB database - available
[here](https://github.com/DiamondLightSource/ispyb-database).

If not already installed, you must install the following packages:

```
php php-mysqlnd php-mbstring php-xml php-gd php-fpm php-cli php-xdebug
```

### Check out the code
```sh
$ git clone https://github.com/DiamondLightSource/SynchWeb
Expand Down
7 changes: 5 additions & 2 deletions api/assets/emails/html/dewar-dispatch.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ <h1 style="font-size: 16px; font-weight: normal; border-bottom: 1px solid #000;
<td>
<?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?><br />
<?php echo $data['LABNAME'] ?> <br />
<?php echo nl2br($data['ADDRESS']) ?>
<?php echo nl2br($data['ADDRESS']) ?> <br />
<?php echo $data['CITY'] ?> <br />
<?php echo $data['POSTCODE'] ?> <br />
<?php echo $data['COUNTRY'] ?>
</td>
</tr>
<tr>
Expand All @@ -60,7 +63,7 @@ <h1 style="font-size: 16px; font-weight: normal; border-bottom: 1px solid #000;
<td><?php echo $data['DELIVERYAGENT_AGENTNAME'] ?></td>
</tr>

<?php if (!$data['FACILITYCODE']): ?>
<?php if (!$data['TERMSACCEPTED']): ?>
<tr>
<td style="padding: 1.5%; font-weight: bold">Courier Account No.</td>
<td><?php echo $data['DELIVERYAGENT_AGENTCODE'] ?></td>
Expand Down
2 changes: 1 addition & 1 deletion api/assets/pdf/visit_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<p>Registered Users</p>
<ul>
<?php foreach($users as $u): ?>
<li><?php echo $u['FULLNAME'] ?></li>
<li><?php echo $u['TITLE'] . ' ' . $u['GIVENNAME'] . ' ' . $u['FAMILYNAME'] ?></li>
<?php endforeach; ?>
</ul>

Expand Down
1 change: 0 additions & 1 deletion api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"firebase/php-jwt": "2.2.0",
"jdorn/sql-formatter": "1.2.9",
"mpdf/mpdf": "8.1.2",
"phpxmlrpc/phpxmlrpc": "3.1.2",
"ralouphie/getallheaders": "2.0.5",
"slim/slim": "2.6.2",
"stomp-php/stomp-php": "3.0.6",
Expand Down
25 changes: 24 additions & 1 deletion api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@
$isb = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$dbtype = 'mysql';

# Summary Database credentials
######### DELETE if not using connection.
$summarydbconfig = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$ifsummary = true;

# Encoded JWT key, used to sign and check validaty of jwt tokens
# - Create one of these using /api/authenticate/key
# This can be changed to invalidate all currently active tokens
$jwt_key = '';

# Auth type
# Can be cas, ldap
# Can be cas, ldap, oidc
$authentication_type = 'cas';

# CAS url (if using cas, assume https)
$cas_url = 'cas.server.ac.uk';

# Follow CAS SSO
$cas_sso = true;
$sso_url = "sso.server.ac.uk";

# OIDC (or OAuth2) client ID and secret. Only useful if authentication_type is set to OIDC
$oidc_client_id = "oidcClientId";
$oidc_client_secret = "oidcClientSecret";
# Cookie key used for SSO/cookie based authentication
$cookie_key = "synchweb-auth";

# CAS CA Cert (for SSO)
$cacert = '/etc/certs/ca-bundle.crt';
Expand All @@ -52,6 +64,9 @@
# Timezone
$timezone = 'Europe/London';

# URL to access the PV archiver
$archive_url = '';

# Valid Components
# Denotes that only staff may create proteins, otherwise they must come from replication
# with a valid `externalid`, users may still clone proteins
Expand Down Expand Up @@ -144,6 +159,13 @@
# and for shipment booked,
$shipbooked_email = '[email protected]';

# dewar back in storage (complete)
$dewar_complete_email = '';

# Send a 'visit finished' email when a dewar moves from this beamline to this (regex) location
$dewar_complete_email_locations = array('i03' => '/tray-\w+/',
);

# Industrial Contacts
# - Industrial users get a personalised email with in contact details,
# template in assets/emails/dewar-stores-in-in.html
Expand Down Expand Up @@ -225,6 +247,7 @@

# Shipping service details
$use_shipping_service = null;
$use_shipping_service_incoming_shipments = null;
$shipping_service_url = null;
$shipping_service_links_in_emails = null;

Expand Down
15 changes: 12 additions & 3 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ function setupApplication($mode): Slim
});

$app->get('/options', function () use ($app) {
global $motd, $authentication_type, $cas_url, $cas_sso, $package_description,
global $motd, $authentication_type, $cas_url, $cas_sso, $sso_url, $package_description,
$facility_courier_countries, $facility_courier_countries_nde,
$dhl_enable, $dhl_link, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types;
$valid_components, $enabled_container_types, $ifsummary;
$app->contentType('application/json');
$app->response()->body(json_encode(array(
'motd' => $motd,
'authentication_type' => $authentication_type,
'cas_url' => $cas_url,
'cas_sso' => $cas_sso,
'sso_url' => $sso_url,
'package_description' => $package_description,
'facility_courier_countries' => $facility_courier_countries,
'facility_courier_countries_nde' => $facility_courier_countries_nde,
Expand All @@ -86,7 +87,8 @@ function setupApplication($mode): Slim
'preset_proposal' => $preset_proposal,
'timezone' => $timezone,
'valid_components' => $valid_components,
'enabled_container_types' => $enabled_container_types
'enabled_container_types' => $enabled_container_types,
'ifsummary' => $ifsummary
)));
});
return $app;
Expand All @@ -101,6 +103,13 @@ function setupDependencyInjectionContainer($app)
return $db;
});

$app->container->singleton('dbsummary', function () use ($app): DatabaseParent {
$dbFactory = new DatabaseFactory(new DatabaseConnectionFactory());
$db = $dbFactory->get("summary");
$db->set_app($app);
return $db;
});

$app->container->singleton('authData', function () use ($app) {
return new AuthenticationData($app->container['db']);
});
Expand Down
4 changes: 4 additions & 0 deletions api/src/Authentication/AuthenticationParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ interface AuthenticationInterface
public function authenticate($login, $password);

public function check();

public function authorise();

public function authenticateByCode($code);
}
54 changes: 54 additions & 0 deletions api/src/Authentication/AuthenticationTypeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace SynchWeb\Authentication;

class AuthenticationTypeFactory {

// Array of authentication types and corresponding authentication class names.
// Value is class name in SynchWeb\Authentication\Type namespace.
// Key is lower case representation of class name.
private $authentication_types = array(
'cas' => 'CAS',
'dummy' => 'Dummy',
'ldap' => 'LDAP',
'simple' => 'Simple',
'oidc' => 'OIDC',
'combined' => 'Combined',
);

// Return instance of authentication class corresponding to $authentication_type.
// The value passed by the calling method derives from $authentication_type, a global variable specified in config.php.
public function create($authentication_type)
{
if (!$authentication_type)
{
error_log("Authentication method not specified in config.php.");

$authentication_type = 'cas';
}

// Determine fully-qualified class name of authentication class corresponding to $authentication_type.
$full_class_name = null;

if (key_exists(strtolower($authentication_type), $this->authentication_types))
{
$full_class_name = 'SynchWeb\\Authentication\\Type\\' . $this->authentication_types[$authentication_type];
}
else
{
throw new \Exception("Authentication method '$authentication_type' not configured.");
}

// Return instance of authentication class.
if (class_exists($full_class_name))
{
return new $full_class_name();
}
else
{
throw new \Exception("Authentication class '$full_class_name' does not exist.");
}

throw new \Exception('Authentication not possible due to a configuration error.');
}
}
10 changes: 10 additions & 0 deletions api/src/Authentication/Type/CAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

class CAS extends AuthenticationParent implements AuthenticationInterface
{
function authorise()
{
return false;
}

function authenticateByCode($code)
{
return false;
}

function check()
{
global $cas_url, $cas_sso, $cacert;
Expand Down
39 changes: 39 additions & 0 deletions api/src/Authentication/Type/Combined.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace SynchWeb\Authentication\Type;

use SynchWeb\Authentication\AuthenticationInterface;
use SynchWeb\Authentication\AuthenticationParent;

/**
* Combined OIDC and CAS login to allow current api users to use the authentiate api
* endpoint with username and password
*/
class Combined extends AuthenticationParent implements AuthenticationInterface
{
private $CASAuth;
private $OIDCAuth;

function __construct() {
$this->CASAuth = new CAS();
$this->OIDCAuth = new OIDC();
}


public function authenticate($login, $password)
{
return $this->CASAuth->authenticate($login, $password);
}

public function check() {
return $this->OIDCAuth->check();
}

public function authorise() {
return $this->OIDCAuth->authorise();
}

public function authenticateByCode($code){
return $this->OIDCAuth->authenticateByCode($code);
}
}
10 changes: 10 additions & 0 deletions api/src/Authentication/Type/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

class Dummy extends AuthenticationParent implements AuthenticationInterface
{
function authorise()
{
return false;
}

function authenticateByCode($code)
{
return false;
}

function check()
{
return false;
Expand Down
10 changes: 10 additions & 0 deletions api/src/Authentication/Type/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

class LDAP extends AuthenticationParent implements AuthenticationInterface
{
function authorise()
{
return false;
}

function authenticateByCode($code)
{
return false;
}

function check()
{
return false;
Expand Down
Loading

0 comments on commit 1f3255d

Please sign in to comment.