From 16dc6c1a7475b507f53255b249ce682090baaf2a Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Sun, 24 Apr 2016 14:41:21 -0700 Subject: [PATCH] Logging for mention email notifications --- core/bug_api.php | 10 ++++++++-- core/bugnote_api.php | 9 ++++++--- core/email_api.php | 35 ++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/core/bug_api.php b/core/bug_api.php index 65f6c7983d..ee13553a22 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -565,11 +565,13 @@ function create() { $t_all_mentioned_user_ids = array_merge( $t_all_mentioned_user_ids, $t_mentioned_user_ids ); } - $t_all_mentioned_user_ids = access_has_bug_level_filter( + $t_filtered_mentioned_user_ids = access_has_bug_level_filter( config_get( 'view_bug_threshold' ), $this->id, $t_all_mentioned_user_ids ); + $t_removed_mentions_user_ids = array_diff( $t_all_mentioned_user_ids, $t_filtered_mentioned_user_ids ); + if( !empty( $t_all_mentioned_user_ids ) ) { $t_mention_text = $this->description . "\n\n"; @@ -583,7 +585,11 @@ function create() { $t_mention_text .= $this->additional_information . "\n\n"; } - mention_process_user_mentions( $this->id, $t_all_mentioned_user_ids, $t_mention_text ); + mention_process_user_mentions( + $this->id, + $t_filtered_mentioned_user_ids, + $t_mention_text, + $t_removed_mentions_user_ids ); } return $this->id; diff --git a/core/bugnote_api.php b/core/bugnote_api.php index 048105a7ed..6308ac6a9e 100644 --- a/core/bugnote_api.php +++ b/core/bugnote_api.php @@ -263,15 +263,18 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_ # Process the mentions that have access to the issue note $t_mentioned_user_ids = mention_get_users( $t_bugnote_text ); - $t_mentioned_user_ids = access_has_bugnote_level_filter( + $t_filtered_mentioned_user_ids = access_has_bugnote_level_filter( config_get( 'view_bug_threshold' ), $t_bugnote_id, $t_mentioned_user_ids ); + $t_removed_mentions_user_ids = array_diff( $t_mentioned_user_ids, $t_filtered_mentioned_user_ids ); + mention_process_user_mentions( $p_bug_id, - $t_mentioned_user_ids, - $p_bugnote_text ); + $t_filtered_mentioned_user_ids, + $p_bugnote_text, + $t_removed_mentions_user_ids ); # Event integration event_signal( 'EVENT_BUGNOTE_ADD', array( $p_bug_id, $t_bugnote_id ) ); diff --git a/core/email_api.php b/core/email_api.php index 5bd3880065..bff937a0d3 100644 --- a/core/email_api.php +++ b/core/email_api.php @@ -1305,21 +1305,17 @@ function email_bug_reminder( $p_recipients, $p_bug_id, $p_message ) { * or an issue note. * * @param integer $p_bug_id Issue for which the reminder is sent. - * @param integer|array $p_recipients User id or list of user ids array. + * @param array $p_mention_user_ids User id or list of user ids array. * @param string $p_message Optional message to add to the e-mail. + * @param array $p_removed_mention_user_ids The users that were removed due to lack of access. * @return array List of users ids to whom the reminder e-mail was actually sent */ -function email_user_mention( $p_bug_id, $p_recipients, $p_message = '' ) { +function email_user_mention( $p_bug_id, $p_mention_user_ids, $p_message, $p_removed_mention_user_ids = array() ) { if( OFF == config_get( 'enable_email_notification' ) ) { + log_event( LOG_EMAIL_VERBOSE, 'email notifications disabled.' ); return array(); } - if( !is_array( $p_recipients ) ) { - $p_recipients = array( - $p_recipients, - ); - } - $t_project_id = bug_get_field( $p_bug_id, 'project_id' ); $t_sender_id = auth_get_current_user_id(); $t_sender = user_get_name( $t_sender_id ); @@ -1330,25 +1326,30 @@ function email_user_mention( $p_bug_id, $p_recipients, $p_message = '' ) { $t_user_id = auth_get_current_user_id(); $t_users_processed = array(); + foreach( $p_removed_mention_user_ids as $t_remove_mention_user_id ) { + log_event( LOG_EMAIL_VERBOSE, 'skipped mention email for U' . $t_mention_user_id . ' (no access to issue or note).' ); + } + $t_result = array(); - foreach( $p_recipients as $t_recipient ) { + foreach( $p_mention_user_ids as $t_mention_user_id ) { # Don't trigger mention emails for self mentions - if( $t_recipient == $t_user_id ) { + if( $t_mention_user_id == $t_user_id ) { + log_event( LOG_EMAIL_VERBOSE, 'skipped mention email for U' . $t_mention_user_id . ' (self-mention).' ); continue; } # Don't process a user more than once - if( isset( $t_users_processed[$t_recipient] ) ) { + if( isset( $t_users_processed[$t_mention_user_id] ) ) { continue; } - $t_users_processed[$t_recipient] = true; + $t_users_processed[$t_mention_user_id] = true; - lang_push( user_pref_get_language( $t_recipient, $t_project_id ) ); + lang_push( user_pref_get_language( $t_mention_user_id, $t_project_id ) ); - $t_email = user_get_email( $t_recipient ); + $t_email = user_get_email( $t_mention_user_id ); - if( access_has_project_level( config_get( 'show_user_email_threshold' ), $t_project_id, $t_recipient ) ) { + if( access_has_project_level( config_get( 'show_user_email_threshold' ), $t_project_id, $t_mention_user_id ) ) { $t_sender_email = ' <' . user_get_email( $t_sender_id ) . '>'; } else { $t_sender_email = ''; @@ -1359,10 +1360,10 @@ function email_user_mention( $p_bug_id, $p_recipients, $p_message = '' ) { $t_id = email_store( $t_email, $t_subject, $t_contents ); if( $t_id !== null ) { - $t_result[] = $t_recipient; + $t_result[] = $t_mention_user_id; } - log_event( LOG_EMAIL_VERBOSE, 'queued mention email ' . $t_id . ' for U' . $t_recipient ); + log_event( LOG_EMAIL_VERBOSE, 'queued mention email ' . $t_id . ' for U' . $t_mention_user_id ); lang_pop(); }