Skip to content

Commit

Permalink
Merge branch 'prerelease' into improvement/LIMS-77/link-lab-contact-t…
Browse files Browse the repository at this point in the history
…o-fedids
  • Loading branch information
ndg63276 authored Sep 12, 2023
2 parents bfa8044 + e533e07 commit 62db444
Show file tree
Hide file tree
Showing 83 changed files with 17,097 additions and 346 deletions.
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**NOTE**: (PR title should be of the form ticket:short description, e.g. TICKET-123: Add more templates)

**JIRA ticket**: [TICKET-123](https://link.to.jira)

**Summary**:

A brief description of what this pull request aims to achieve

**Changes**:
- List changes made in this pull request

**To test**:
- List actions that should be taken to test that functionality works as expected
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,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
20 changes: 4 additions & 16 deletions api/assets/emails/dewar-transfer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

Dear local contact: <?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?>,

Your user: <?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case and put the dewar for the visit <?php echo $data['VISIT'] ?> on the rack outside the beamline: "to be Stored at Diamond" by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>.

Local contact for next visit: <?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?>


Dear EHC,

Please collect the dewar from visit <?php echo $data['VISIT'] ?> <?php if($data['FACILITYCODE']): ?>(Dewar Code: <?php echo $data['FACILITYCODE'] ?>)<?php endif; ?> currently stored on the rack outside <?php echo $data['LOCATION'] ?> and transfer it to the <?php echo $data['NEXTLOCATION'] ?> rack in the MX storage room
The dewar should be ready for internal transfer by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>

Your user: <?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> from visit <?php echo $data['VISIT'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case.

Information for the transfer:

Expand Down Expand Up @@ -42,14 +33,11 @@
Current dewar location
<?php echo $data['LOCATION'] ?>

New Location in storage room
<?php echo $data['NEXTLOCATION'] ?>

Pickup date:
<?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>

Local contact email (in case of problems finding the dewar):
<?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?>

Local contact for next visit:
<?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?>

Comments:
<?php echo $data['COMMENTS'] ?>
21 changes: 4 additions & 17 deletions api/assets/emails/html/dewar-transfer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ <h1 style="font-size: 16px; font-weight: normal; border-bottom: 1px solid #000;

<div class="inset" style="margin: 1%; padding: 1%; margin-bottom: 2%; border-radius: 5px; background: #82d180">
<h2>Local Contact: <?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?></h2>
<p><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case and put the dewar for the visit <?php echo $data['VISIT'] ?> on the rack outside the beamline: "to be Stored at Diamond" by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></p>
<p>Local contact for next visit: <?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?></p>
<p><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> from visit <?php echo $data['VISIT'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case.</p>
</div>

<div class="inset" style="margin: 1%; padding: 1%; margin-bottom: 2%; border-radius: 5px; background: #82d180">
<h2>EHCs</h2>
<p>Please collect the dewar from visit <?php echo $data['VISIT'] ?> <?php if($data['FACILITYCODE']): ?>(Dewar Code: <?php echo $data['FACILITYCODE'] ?>)<?php endif; ?> currently stored on the rack outside <?php echo $data['LOCATION'] ?> and transfer it to the <?php echo $data['NEXTLOCATION'] ?> rack in the MX storage room</p>
<p>The dewar should be ready for internal transfer by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></p>
</div>

<table class="details" style="background: #f4f4f4; margin: 1%">
<tbody>
<?php if ($data['FACILITYCODE']): ?>
Expand Down Expand Up @@ -40,11 +33,10 @@ <h2>EHCs</h2>
<td><?php echo $data['NEXTVISIT'] ?></td>
</tr>
<tr>
<td style="padding: 1.5%; font-weight: bold">New Location</td>
<td><?php echo $data['NEXTLOCATION'] ?></td>
<td style="padding: 1.5%; font-weight: bold">New Local Contact</td>
<td><?php echo $data['NEXTLOCALCONTACT'] ?></td>
</tr>


<tr>
<td style="padding: 1.5%; font-weight: bold">Full Name</td>
<td><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?></td>
Expand All @@ -61,12 +53,7 @@ <h2>EHCs</h2>
<td style="padding: 1.5%; font-weight: bold">Lab / Company Name</td>
<td><?php echo $data['LABNAME'] ?></td>
</tr>

<tr>
<td style="padding: 1.5%; font-weight: bold">Pickup Date</td>
<td><?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></td>
</tr>


<tr>
<td style="padding: 1.5%; font-weight: bold">Comments</td>
<td><?php echo nl2br($data['COMMENTS']) ?></td>
Expand Down
6 changes: 6 additions & 0 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
$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
Expand Down Expand Up @@ -242,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
12 changes: 10 additions & 2 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function setupApplication($mode): Slim
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,
Expand All @@ -87,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 @@ -102,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
29 changes: 20 additions & 9 deletions api/src/Authentication/Type/OIDC.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ function __construct() {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

$newProviderConfig = json_decode($response);
$newProviderConfig->b64ClientCreds = base64_encode(
$oidc_client_id . ":" . $oidc_client_secret
);

if($newProviderConfig == null) {
if(!$newProviderConfig
|| !isset($newProviderConfig->userinfo_endpoint)
|| !isset($newProviderConfig->authorization_endpoint)
|| !isset($newProviderConfig->token_endpoint)) {
error_log("OIDC Authentication provider replied with invalid JSON body");
return;
}
$newProviderConfig->b64ClientCreds = base64_encode(
$oidc_client_id . ":" . $oidc_client_secret
);

$this->providerConfig = $newProviderConfig;
}
Expand All @@ -43,9 +45,12 @@ private function getUser($token)
$response = curl_exec($ch);
curl_close($ch);

$fedid = json_decode($response)->id;
$response_json = json_decode($response);
if (!$response_json || !isset($response_json->id)) {
return false;
}

return $fedid;
return $response_json->id;
}

function authenticate($login, $password)
Expand Down Expand Up @@ -92,8 +97,14 @@ function authenticateByCode($code)
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->providerConfig->b64ClientCreds));
$response = curl_exec($ch);
curl_close($ch);

$token = json_decode($response)->access_token;

$response_json = json_decode($response);
if (!$response_json || !isset($response_json->access_token)) {
error_log("Invalid authentication attempt, provider returned invalid response");
return false;
}

$token = $response_json->access_token;

if(!$token) {
error_log("Invalid authentication attempt, provider returned no access token");
Expand Down
11 changes: 11 additions & 0 deletions api/src/Database/DatabaseConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DatabaseConnectionFactory
public function get($databaseType)
{
global $isb;
global $summarydbconfig;

if (!$databaseType) {
error_log('Database type variable, dbtype, is not specified in config.php - defaulting to MySql.');
Expand All @@ -24,6 +25,16 @@ public function get($databaseType)
$conn = new \mysqli($host, $isb['user'], $isb['pass'], $dbn, $port);
$conn->set_charset("utf8mb4");
}
elseif ($databaseType == 'PureMySQL') {
$port = array_key_exists('port', $summarydbconfig) ? $summarydbconfig['port'] : null;
if (!$port) {
$port = ini_get("mysqli.default_port");
}
list($host, $dbn) = explode('/', $summarydbconfig['db']);
$conn = new \mysqli($host, $summarydbconfig['user'], $summarydbconfig['pass'], $dbn, $port);
$conn->set_charset("utf8mb4");
}


if ($conn == null) {
Utils::returnError("Database Configuration Error", "Database connection for type '$databaseType' does not exist.");
Expand Down
28 changes: 16 additions & 12 deletions api/src/Database/DatabaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DatabaseFactory
// Value is class name in SynchWeb\Database\Type namespace.
// Key is lower case representation of class name.
public $database_types = array(
'mysql' => 'MySQL'
'mysql' => ["dbClassName" =>'MySQL', "dataConnectionName" => 'MySQL'],
'summary' => ["dbClassName" =>'PureMySQL', "dataConnectionName" => 'PureMySQL']
);

function __construct($databaseConnectionFactory)
Expand All @@ -19,25 +20,28 @@ function __construct($databaseConnectionFactory)

private $databaseConnectionFactory;

public function get()
{
// Global variable is named $dbtype in config.php.
public function get($databaseType = null)
{
global $dbtype;
$database_type = $dbtype;

if ( $databaseType == null) {
// Global variable is named $dbtype in config.php.
$databaseType = $dbtype;
}

if (!$database_type) {
if (!$databaseType) {
error_log('Database type variable, dbtype, is not specified in config.php - defaulting to MySql.');
$database_type = 'MySQL';
$databaseType = 'MySQL';
}

// Determine fully-qualified class name of database class corresponding to $database_type.
if (key_exists(strtolower($database_type), $this->database_types)) {
$dbClassName = $this->database_types[strtolower($database_type)];
if (key_exists(strtolower($databaseType), $this->database_types)) {
$selectedDBConfig = $this->database_types[strtolower($databaseType)];

$full_class_name = 'SynchWeb\\Database\\Type\\' . $dbClassName;
$full_class_name = 'SynchWeb\\Database\\Type\\' . $selectedDBConfig["dbClassName"];

if (class_exists($full_class_name)) {
$conn = $this->databaseConnectionFactory->get($dbClassName);
$conn = $this->databaseConnectionFactory->get($selectedDBConfig["dataConnectionName"]);
return new $full_class_name($conn);
}
else {
Expand All @@ -46,7 +50,7 @@ public function get()

}
else {
error_log("Database type '$database_type' not configured.");
error_log("Database type '$databaseType' not configured.");
}
return null;
}
Expand Down
32 changes: 31 additions & 1 deletion api/src/Database/DatabaseQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class DatabaseQueryBuilder
private $query_bound_values = [];
/** @var ?string where clause column name */
private $where_columnName = Null;
/** @var ?mixed where vlause value */
/** @var ?mixed where clause value */
private $where_value = Null;
/** @var array join clauses*/
private $join_clauses = [];

/**
* @var DatabaseParent database parent to use
*/
Expand Down Expand Up @@ -104,6 +107,33 @@ public function insert($expectedTable)
return $this->db->id();
}


/**
* Add while join clauses with no processing except to remove duplicates
* ONLY USED WITH getJoins at the moment
*
* @param string $join_clause The join clause to add, e.g. JOIN table t ON t.id = s.id
* @return DatabaseQueryBuilder the builder
*/
public function joinClause($join_clause)
{
if (!in_array($join_clause, $this->join_clauses))
array_push($this->join_clauses, $join_clause);
return $this;
}

/**
* Pull back the join clauses ready to be added to a SQL statement
*
* This is a half-way house into adding join caluses to this builder
*
* @return string The join caluses as one long string
*/
public function getJoins()
{
return implode(" ", $this->join_clauses);
}

private function bindArrayAsList($values): string
{
$bound_list_sql = "";
Expand Down
1 change: 1 addition & 0 deletions api/src/Database/Type/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class MySQL extends DatabaseParent {
// Xray Centring
'XrayCentring',
'XrayCentringResult',
'XrayCentring',

'BeamCalendar',
'SpaceGroup',
Expand Down
Loading

0 comments on commit 62db444

Please sign in to comment.