Skip to content

Commit

Permalink
Merge pull request #911 from josaphatim/fixed-calling-ajax-requests-w…
Browse files Browse the repository at this point in the history
…hen-not-logged-in

Fixed calling ajax reload folders and unsnooze message functions when not looged in
  • Loading branch information
kroky authored Feb 20, 2024
2 parents d0e947b + c10699a commit a8ebf9b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ public function process() {
if ($this->session->is_active()) {
$this->out('changed_settings', $this->session->get('changed_settings', array()), false);
$this->out('username', $this->session->get('username'));
$this->out('is_logged', true);
}
if ($this->validate_request) {
Hm_Request_Key::load($this->session, $this->request, $this->session->loaded);
Expand Down
1 change: 1 addition & 0 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ class Hm_Output_js_data extends Hm_Output_Module {
protected function output() {
$res = '<script type="text/javascript">'.
'var globals = {};'.
'var hm_is_logged = function () { return '.($this->get('is_logged') ? '1' : '0').'; };'.
'var hm_empty_folder = function() { return "'.$this->trans('So alone').'"; };'.
'var hm_mobile = function() { return '.($this->get('is_mobile') ? '1' : '0').'; };'.
'var hm_debug = function() { return "'.(DEBUG_MODE ? '1' : '0').'"; };'.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ $(function() {
Hm_Timer.fire();

/* load folder list */
if (!reloaded && !Hm_Folders.load_from_local_storage()) {
if (hm_is_logged() && (!reloaded && !Hm_Folders.load_from_local_storage())) {
Hm_Folders.update_folder_list();
}
if (hm_page_name() == 'message_list' || hm_page_name() == 'search') {
Expand Down
6 changes: 4 additions & 2 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,10 @@ $(function() {
imap_setup_snooze();
}

imap_unsnooze_messages();
setInterval(imap_unsnooze_messages, 60000);
if (hm_is_logged()) {
imap_unsnooze_messages();
setInterval(imap_unsnooze_messages, 60000);
}

if ($('.imap_move').length > 0) {
check_select_for_imap();
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/modules/core/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,10 +997,10 @@ public function test_js_data() {
$test = new Output_Test('js_data', 'core');
$test->handler_response = array('disable_delete_prompt' => true);
$res = $test->run();
$this->assertStringStartsWith('<script type="text/javascript">var globals = {};var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return true; };', implode($res->output_response));
$this->assertStringStartsWith('<script type="text/javascript">var globals = {};var hm_is_logged = function () { return 0; };var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return true; };', implode($res->output_response));
$test->handler_response = array();
$res = $test->run();
$this->assertStringStartsWith('<script type="text/javascript">var globals = {};var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return confirm("Are you sure?"); };', implode($res->output_response));
$this->assertStringStartsWith('<script type="text/javascript">var globals = {};var hm_is_logged = function () { return 0; };var hm_empty_folder = function() { return "So alone"; };var hm_mobile = function() { return 0; };var hm_debug = function() { return "0"; };var hm_mailto = function() { return 0; };var hm_page_name = function() { return ""; };var hm_language_direction = function() { return "ltr"; };var hm_list_path = function() { return ""; };var hm_list_parent = function() { return ""; };var hm_msg_uid = function() { return Hm_Utils.get_from_global("msg_uid", ""); };var hm_encrypt_ajax_requests = function() { return ""; };var hm_encrypt_local_storage = function() { return ""; };var hm_web_root_path = function() { return ""; };var hm_flag_image_src = function() { return "<i class=\\"bi bi-star-half\\"></i>"; };var hm_check_dirty_flag = function() { return 0; };var hm_data_sources = function() { return []; };var hm_delete_prompt = function() { return confirm("Are you sure?"); };', implode($res->output_response));
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit a8ebf9b

Please sign in to comment.