diff --git a/app/config/app.php b/app/config/app.php index 306c7b14f..6b7c82a1a 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -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', @@ -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', @@ -236,6 +238,7 @@ //'headerCharset' => 'utf-8', ], ], + */ /** * Connection information used by the ORM to connect diff --git a/app/config/bootstrap.php b/app/config/bootstrap.php index 074573120..667287a40 100644 --- a/app/config/bootstrap.php +++ b/app/config/bootstrap.php @@ -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"); } diff --git a/app/config/email.php.dist b/app/config/email.php.dist new file mode 100644 index 000000000..e8efc989d --- /dev/null +++ b/app/config/email.php.dist @@ -0,0 +1,54 @@ + [ + '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', + ], + ], +]; \ No newline at end of file diff --git a/app/config/schema/schema.json b/app/config/schema/schema.json index 8a46da7f2..e05ca815b 100644 --- a/app/config/schema/schema.json +++ b/app/config/schema/schema.json @@ -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": { diff --git a/app/src/Controller/TierApiController.php b/app/src/Controller/TierApiController.php index 56d9253c9..ea14ea466 100644 --- a/app/src/Controller/TierApiController.php +++ b/app/src/Controller/TierApiController.php @@ -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; @@ -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; diff --git a/app/src/Model/Table/SystemsOfRecordTable.php b/app/src/Model/Table/SystemsOfRecordTable.php index 6aaeb0942..5fbb6347c 100644 --- a/app/src/Model/Table/SystemsOfRecordTable.php +++ b/app/src/Model/Table/SystemsOfRecordTable.php @@ -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; } } \ No newline at end of file diff --git a/app/src/Template/SystemsOfRecord/fields.inc b/app/src/Template/SystemsOfRecord/fields.inc index bb3478042..bc0ab315a 100644 --- a/app/src/Template/SystemsOfRecord/fields.inc +++ b/app/src/Template/SystemsOfRecord/fields.inc @@ -25,8 +25,35 @@ * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ +use \App\Lib\Enum\ResolutionModeEnum; +?> + +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); }