From 88f9f06dc639b5867215926ae596d6e34c6ab8af Mon Sep 17 00:00:00 2001 From: Baraka Kinywa Date: Tue, 3 Sep 2024 17:55:51 +0200 Subject: [PATCH 1/2] [FIX]Compose page: clicking on Send button can't send email --- modules/contacts/site.js | 25 +++++++++++++++++++++++++ modules/smtp/site.js | 33 +++++---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/modules/contacts/site.js b/modules/contacts/site.js index fd3018cbef..6111af3647 100644 --- a/modules/contacts/site.js +++ b/modules/contacts/site.js @@ -239,6 +239,31 @@ var contact_import_pagination = function() { }); }; +var check_cc_exist_in_contacts_list = function(e) { + if (typeof list_emails !== "undefined") { + var compose_cc = $(".compose_cc").val().trim(); + var list_cc = null; + var list_cc_not_exist_in_my_contact = []; + if (compose_cc.length > 0) { + list_cc = compose_cc.split(","); + var list_html = "
    "; + list_cc.forEach(cc => { + cc = cc.trim().split(" "); + if (! list_emails.includes(cc.slice(-1)[0])) { + list_cc_not_exist_in_my_contact.push(cc.slice(-1)[0]) + list_html += `
  1. ${cc.slice(-1)[0]}
  2. `; + } + }); + list_html += "
"; + + if (list_cc_not_exist_in_my_contact) { + return list_html; + } + } + } + return ""; +}; + if (hm_page_name() == 'contacts') { $('.delete_contact').on("click", function() { delete_contact($(this).data('id'), $(this).data('source'), $(this).data('type')); diff --git a/modules/smtp/site.js b/modules/smtp/site.js index 066bb1f938..6744c530c9 100644 --- a/modules/smtp/site.js +++ b/modules/smtp/site.js @@ -419,29 +419,6 @@ var force_send_message = function() { } } -var check_cc_exist_in_contacts_list = function(e) { - var compose_cc = $(".compose_cc").val().trim(); - var list_cc = null; - var list_cc_not_exist_in_my_contact = []; - if (compose_cc.length > 0) { - list_cc = compose_cc.split(","); - var list_html = "
    "; - list_cc.forEach(cc => { - cc = cc.trim().split(" "); - if (! list_emails.includes(cc.slice(-1)[0])) { - list_cc_not_exist_in_my_contact.push(cc.slice(-1)[0]) - list_html += `
  1. ${cc.slice(-1)[0]}
  2. `; - } - }); - list_html += "
"; - - if (list_cc_not_exist_in_my_contact) { - return list_html; - } - } - return ""; -}; - $(function () { if (!hm_is_logged()) { return; @@ -510,16 +487,16 @@ $(function () { modalContentHeadline = "Your subject and body are empty!"; } - // if contact_cc not exist in contact list for user - var checkInList = ""; - if (list_emails) { - checkInList = check_cc_exist_in_contacts_list(e); + if (typeof check_cc_exist_in_contacts_list === 'function') { + var checkInList = check_cc_exist_in_contacts_list(e); + + // if contact_cc not exist in contact list for user if (checkInList) { modalContentHeadline = "Adress mail not exist in your contact liste"; showBtnSendAnywayDontWarnFuture = false; } + } - // If the user has disabled the warning, we should send the message if (Boolean(Hm_Utils.get_from_local_storage(dontWanValueInStorage))) { From 8d785e86c9e9c550e42523aa9930efde98f54fee Mon Sep 17 00:00:00 2001 From: Steven Ngesera Date: Wed, 11 Sep 2024 23:21:10 +0300 Subject: [PATCH 2/2] Refact check_cc_exist_in_contacts_list feature --- modules/contacts/site.js | 2 +- modules/core/functions.php | 1 - modules/core/handler_modules.php | 15 ++------------- modules/core/output_modules.php | 3 +++ modules/smtp/site.js | 7 +++---- tests/phpunit/modules/core/functions.php | 2 +- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/modules/contacts/site.js b/modules/contacts/site.js index 6111af3647..b2d7a64708 100644 --- a/modules/contacts/site.js +++ b/modules/contacts/site.js @@ -239,7 +239,7 @@ var contact_import_pagination = function() { }); }; -var check_cc_exist_in_contacts_list = function(e) { +var check_cc_exist_in_contacts_list = function() { if (typeof list_emails !== "undefined") { var compose_cc = $(".compose_cc").val().trim(); var list_cc = null; diff --git a/modules/core/functions.php b/modules/core/functions.php index 00d0813eaf..9ade1c45e6 100644 --- a/modules/core/functions.php +++ b/modules/core/functions.php @@ -428,7 +428,6 @@ function setup_base_page($name, $source=false, $use_layout=true) { add_output($name, 'header_start', false, $source); add_output($name, 'header_css', false, $source); add_output($name, 'header_content', false, $source); - add_handler($name, 'default_timezone', false, $source); add_output($name, 'js_data', false, $source); add_output($name, 'js_search_data', true, $source); add_output($name, 'header_end', false, $source); diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index c0e4aa2031..4a5544ea0c 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -569,19 +569,6 @@ public function process() { } } -/** - * Setup the current language - * @subpackage core/handler - */ -class Hm_Handler_default_timezone extends Hm_Handler_Module { - /** - * output the default timezone - */ - public function process() { - $this->out('default_timezone', $this->user_config->get('default_setting_timezone', 'UTC')); - } -} - /** * Setup the date * @subpackage core/handler @@ -668,6 +655,8 @@ public function process() { $this->out('data_sources', array(), false); $this->out('encrypt_ajax_requests', $this->config->get('encrypt_ajax_requests', false)); $this->out('encrypt_local_storage', $this->config->get('encrypt_local_storage', false)); + $this->out('default_timezone', $this->user_config->get('default_setting_timezone', 'UTC')); + $this->out('enabled_modules', $this->config->get_modules()); if (!crypt_state($this->config)) { $this->out('single_server_mode', true); } diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index e763fe52b2..1717b11189 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -636,6 +636,9 @@ protected function output() { ' return key;'. '};'; $res .= 'window.hm_default_timezone = "'.$this->get('default_timezone','UTC').'";'; + $res .= 'var hm_module_is_supported = function(module) {'. + ' return '.json_encode($this->get('enabled_modules', array())).'.indexOf(module) !== -1;'. + '};'; $res .= ''; return $res; } diff --git a/modules/smtp/site.js b/modules/smtp/site.js index 6744c530c9..69c98c5cc4 100644 --- a/modules/smtp/site.js +++ b/modules/smtp/site.js @@ -487,12 +487,11 @@ $(function () { modalContentHeadline = "Your subject and body are empty!"; } - if (typeof check_cc_exist_in_contacts_list === 'function') { - var checkInList = check_cc_exist_in_contacts_list(e); - + if (hm_module_is_supported('contacts')) { + var checkInList = check_cc_exist_in_contacts_list(); // if contact_cc not exist in contact list for user if (checkInList) { - modalContentHeadline = "Adress mail not exist in your contact liste"; + modalContentHeadline = "Adress mail not exist in your contact list"; showBtnSendAnywayDontWarnFuture = false; } diff --git a/tests/phpunit/modules/core/functions.php b/tests/phpunit/modules/core/functions.php index 52c03a3d05..d0f7b383b7 100644 --- a/tests/phpunit/modules/core/functions.php +++ b/tests/phpunit/modules/core/functions.php @@ -170,7 +170,7 @@ public function test_setup_base_page() { $len = count($res['foo']); $res2 = Hm_Output_Modules::dump(); $len2 = count($res2['foo']); - $this->assertEquals(13, $len); + $this->assertEquals(12, $len); $this->assertEquals(19, $len2); } /**