Navigation Menu

Skip to content

Commit

Permalink
Logging for mention email notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Apr 28, 2016
1 parent 1aee17b commit 16dc6c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
10 changes: 8 additions & 2 deletions core/bug_api.php
Expand Up @@ -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";

Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions core/bugnote_api.php
Expand Up @@ -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 ) );
Expand Down
35 changes: 18 additions & 17 deletions core/email_api.php
Expand Up @@ -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 );
Expand All @@ -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 = '';
Expand All @@ -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();
}
Expand Down

0 comments on commit 16dc6c1

Please sign in to comment.