From bdceaf6236efeff3d87d7bd179b1179da214a2ae Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 23 Feb 2021 06:43:46 -0800 Subject: [PATCH] afform - Display status warning if email-tokens are enabled without authx --- ext/afform/core/Civi/Afform/StatusChecks.php | 67 ++++++++++++++++++++ ext/afform/core/afform.php | 9 ++- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 ext/afform/core/Civi/Afform/StatusChecks.php diff --git a/ext/afform/core/Civi/Afform/StatusChecks.php b/ext/afform/core/Civi/Afform/StatusChecks.php new file mode 100644 index 0000000000..c1a7d7c2ae --- /dev/null +++ b/ext/afform/core/Civi/Afform/StatusChecks.php @@ -0,0 +1,67 @@ +getMapper()->isActiveModule('authx'); + $tokenFormCount = count(Tokens::getTokenForms()); + if (!$hasAuthx) { + if ($tokenFormCount) { + $e->messages[] = new \CRM_Utils_Check_Message( + 'afform_token_authx', + E::ts('Email token support has been configured for %2 form(s), which requires extended authentication services. Please enable "AuthX" in Manage Extensions.', [ + 1 => \CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'), + 2 => $tokenFormCount, + ]), + E::ts('AuthX Required'), + \Psr\Log\LogLevel::ERROR, + 'fa-chain-broken' + ); + } + else { + $e->messages[] = new \CRM_Utils_Check_Message( + 'afform_token_authx', + E::ts('To generate authenticated email links for custom forms, enable extended authentication services (AuthX) in Manage Extensions.', [ + 1 => \CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'), + ]), + E::ts('AuthX Suggested'), + \Psr\Log\LogLevel::INFO, + 'fa-lightbulb-o' + ); + } + } + + if ($hasAuthx && $tokenFormCount > 0 && !in_array('jwt', \Civi::settings()->get('authx_auto_cred'))) { + $e->messages[] = new \CRM_Utils_Check_Message( + 'afform_token_authx', + E::ts('Email token support has been configured for %1 form(s). This requires JWT authentication, authx_auto_cred does not include JWT. ', [ + 1 => $tokenFormCount, + ]), + E::ts('AuthX Configuration'), + \Psr\Log\LogLevel::ERROR, + 'fa-chain-broken' + ); + + } + } + +} diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 717249af6c..be6cf09f0c 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -54,11 +54,14 @@ function afform_civicrm_config(&$config) { $dispatcher->addListener(Submit::EVENT_NAME, [Submit::class, 'processGenericEntity'], -1000); $dispatcher->addListener('hook_civicrm_angularModules', ['\Civi\Afform\AngularDependencyMapper', 'autoReq'], -1000); $dispatcher->addListener('hook_civicrm_alterAngular', ['\Civi\Afform\AfformMetadataInjector', 'preprocess']); + $dispatcher->addListener('hook_civicrm_check', ['\Civi\Afform\StatusChecks', 'hook_civicrm_check']); // Register support for email tokens - $dispatcher->addListener('hook_civicrm_alterMailContent', ['\Civi\Afform\Tokens', 'applyCkeditorWorkaround']); - $dispatcher->addListener('hook_civicrm_tokens', ['\Civi\Afform\Tokens', 'hook_civicrm_tokens']); - $dispatcher->addListener('hook_civicrm_tokenValues', ['\Civi\Afform\Tokens', 'hook_civicrm_tokenValues']); + if (CRM_Extension_System::singleton()->getMapper()->isActiveModule('authx')) { + $dispatcher->addListener('hook_civicrm_alterMailContent', ['\Civi\Afform\Tokens', 'applyCkeditorWorkaround']); + $dispatcher->addListener('hook_civicrm_tokens', ['\Civi\Afform\Tokens', 'hook_civicrm_tokens']); + $dispatcher->addListener('hook_civicrm_tokenValues', ['\Civi\Afform\Tokens', 'hook_civicrm_tokenValues']); + } } /** -- 2.25.1