Skip to content

Commit

Permalink
Notification on fuzzy match (CO-1679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 31, 2019
1 parent 38c4048 commit f303cad
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
* You can add custom transports (or override existing transports) by adding the
* appropriate file to src/Mailer/Transport. Transports should be named
* 'YourTransport.php', where 'Your' is the name of the transport.
*/
*
* Note for COmanage we read in local/Config/email.php instead
*
'EmailTransport' => [
'default' => [
'className' => 'Mail',
Expand All @@ -227,7 +229,7 @@
* duplication across your application and makes maintenance and development
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information.
*/
*
'Email' => [
'default' => [
'transport' => 'default',
Expand All @@ -236,6 +238,7 @@
//'headerCharset' => 'utf-8',
],
],
*/

/**
* Connection information used by the ORM to connect
Expand Down
1 change: 1 addition & 0 deletions app/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
// Read site specific configurations from the COmanage Match local directory
Configure::config('default', new PhpConfig(LOCAL . 'Config' . DS));
Configure::load('database', 'default');
Configure::load('email', 'default');
} catch (\Exception $e) {
exit($e->getMessage() . "\n");
}
Expand Down
54 changes: 54 additions & 0 deletions app/config/email.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
return [
/**
* Email configuration.
*
* By defining transports separately from delivery profiles you can easily
* re-use transport configuration across multiple profiles.
*
* You can specify multiple configurations for production, development and
* testing.
*
* Each transport needs a `className`. Valid options are as follows:
*
* Mail - Send using PHP mail function
* Smtp - Send using SMTP
* Debug - Do not send the email, just return the result
*
* You can add custom transports (or override existing transports) by adding the
* appropriate file to src/Mailer/Transport. Transports should be named
* 'YourTransport.php', where 'Your' is the name of the transport.
*/
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => null,
'password' => null,
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],

/**
* Email delivery profiles
*
* Delivery profiles allow you to predefine various properties about email
* messages from your application and give the settings a name. This saves
* duplication across your application and makes maintenance and development
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information.
*/
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
];
3 changes: 2 additions & 1 deletion app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
"id": {},
"matchgrid_id": {},
"label": { "type": "string", "size": 80 },
"resolution_mode": { "type": "string", "size": 2 }
"resolution_mode": { "type": "string", "size": 2 },
"notification_email": { "type": "string", "size": 80 }
},
"indexes": {
"systems_of_record_i1": {
Expand Down
32 changes: 32 additions & 0 deletions app/src/Controller/TierApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

namespace App\Controller;

use Cake\Mailer\Email;
use Cake\ORM\TableRegistry;
use Cake\Log\Log;
use Cake\Routing\Router;

use \App\Lib\Enum\ConfidenceModeEnum;
use \App\Lib\Enum\ResolutionModeEnum;
Expand Down Expand Up @@ -302,6 +304,36 @@ protected function doMatchRequest(bool $searchOnly=false) {
$matchRequest = $MatchService->insertPending($sor, $sorid, $AttributeManager);

$result['matchRequest'] = $matchRequest;

// Do we have an SoR-specific or Matchgrid-wide notification address?
$notify = null;

if(!empty($sorobj->notification_email)) {
$notify = $sorobj->notification_email;
} else {
$MatchgridSettings = TableRegistry::get('MatchgridSettings');

$notify = $MatchgridSettings->getNotificationEmail($matchgridId);
}

if($notify) {
// We currently just do everything here, but maybe this moves to
// somewhere in Lib at some point?
$url = "/matchgrids/reconcile/" . $this->cur_mg->id . "?rowid=" . $matchRequest;

$email = new Email('default');
$email->setViewVars([
'vv_matchgrid_id' => $this->cur_mg->id,
'vv_pending_url' => Router::url($url, true)
]);
$email->viewBuilder()->setTemplate('potential_match');
$email->setEmailFormat('text');
$email->setTo($notify);
$email->send();

Log::write('debug', $sor . "/" . $sorid . " Potential match requiring resolution, notification sent to " . $notify);
}
} else {
// Interactive SOR, or searchOnly (which can't return a 202)
$statusCode = 300;
Expand Down
12 changes: 12 additions & 0 deletions app/src/Model/Table/SystemsOfRecordTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public function validationDefault(Validator $validator) {
);
$validator->notEmpty('resolution_mode');

$validator->add(
'notification_email',
'length',
[ 'rule' => [ 'maxLength', 80 ] ]
);
$validator->add(
'notification_email',
'content',
[ 'rule' => 'email' ]
);
$validator->allowEmpty('notification_email');

return $validator;
}
}
29 changes: 28 additions & 1 deletion app/src/Template/SystemsOfRecord/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,35 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

use \App\Lib\Enum\ResolutionModeEnum;
?>
<script type="text/javascript">
// JS specific to these fields

function fields_update_gadgets() {
// Hide or show gadgets according to current state

var method = document.getElementById('resolution-mode').value;

if(method == '<?= ResolutionModeEnum::External ?>') {
$("#notification-email").closest('li').show('fade');
} else {
$("#notification-email").closest('li').hide('fade');
}
}

function js_local_onload() {
fields_update_gadgets();
}
</script>
<?php
// This view does not support read-only
if($action == 'add' || $action == 'edit') {
print $this->Field->control('label');
print $this->Field->control('resolution_mode', ['empty' => true]);

print $this->Field->control('resolution_mode',
['empty' => true,
'onChange' => 'fields_update_gadgets();']);

print $this->Field->control('notification_email', [], true);
}

0 comments on commit f303cad

Please sign in to comment.