Skip to content

Commit

Permalink
Make mention processing an explicit API action
Browse files Browse the repository at this point in the history
Don't process mentions as part of create API for issues and notes.
However, make it a separate APIs and call it from applicable scenarios.
  • Loading branch information
vboctor committed Apr 28, 2016
1 parent 934f63c commit 3ecab1a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 24 deletions.
11 changes: 10 additions & 1 deletion api/soap/mc_issue_api.php
Expand Up @@ -787,6 +787,8 @@ function mc_issue_add( $p_username, $p_password, stdClass $p_issue ) {

# submit the issue
$t_issue_id = $t_bug_data->create();
$t_bug_data->process_mentions();

log_event( LOG_WEBSERVICE, 'created new issue id \'' . $t_issue_id . '\'' );

$t_set_custom_field_error = mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'], false );
Expand Down Expand Up @@ -821,6 +823,9 @@ function mc_issue_add( $p_username, $p_password, stdClass $p_issue ) {
$t_note_attr,
$t_user_id,
false ); # don't send mail

bugnote_process_mentions( $t_issue_id, $t_note_id, $t_note['text'] );

log_event( LOG_WEBSERVICE, 'bugnote id \'' . $t_note_id . '\' added to issue \'' . $t_issue_id . '\'' );
}
}
Expand Down Expand Up @@ -1239,7 +1244,11 @@ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, stdClass $p_n
$t_note_attr = isset( $p_note['note_type'] ) ? $p_note['note_attr'] : '';

log_event( LOG_WEBSERVICE, 'adding bugnote to issue \'' . $p_issue_id . '\'' );
return bugnote_add( $p_issue_id, $p_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $p_note ), $t_view_state_id == VS_PRIVATE, $t_note_type, $t_note_attr, $t_reporter_id );
$t_bugnote_id = bugnote_add( $p_issue_id, $p_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $p_note ), $t_view_state_id == VS_PRIVATE, $t_note_type, $t_note_attr, $t_reporter_id );

bugnote_process_mentions( $p_issue_id, $t_bugnote_id, $p_note['text'] );

return $t_bugnote_id;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion bug_actiongroup.php
Expand Up @@ -212,7 +212,8 @@

# Add bugnote if supplied
if( !is_blank( $f_bug_notetext ) ) {
bugnote_add( $t_bug_id, $f_bug_notetext, null, $f_bug_noteprivate );
$t_bugnote_id = bugnote_add( $t_bug_id, $f_bug_notetext, null, $f_bug_noteprivate );
bugnote_process_mentions( $t_bug_id, $t_bugnote_id, $f_bug_notetext );
# No need to call email_generic(), bugnote_add() does it
} else {
email_bug_updated( $t_bug_id );
Expand Down
3 changes: 2 additions & 1 deletion bug_actiongroup_add_note_inc.php
Expand Up @@ -150,6 +150,7 @@ function action_add_note_validate( $p_bug_id ) {
function action_add_note_process( $p_bug_id ) {
$f_bugnote_text = gpc_get_string( 'bugnote_text' );
$f_view_state = gpc_get_int( 'view_state' );
bugnote_add( $p_bug_id, $f_bugnote_text, '0:00', $f_view_state != VS_PUBLIC );
$t_bugnote_id = bugnote_add( $p_bug_id, $f_bugnote_text, '0:00', $f_view_state != VS_PUBLIC );
bugnote_process_mentions( $p_bug_id, $t_bugnote_id, $f_bugnote_text );
return null;
}
3 changes: 3 additions & 0 deletions bug_reminder.php
Expand Up @@ -108,7 +108,10 @@
}
$t_attr .= $t_recipient;
}

bugnote_add( $f_bug_id, $f_body, 0, config_get( 'default_reminder_view_status' ) == VS_PRIVATE, REMINDER, $t_attr, null, false );

# Note: we won't trigger mentions here since reminders are triggered.
}

form_security_purge( 'bug_reminder' );
Expand Down
4 changes: 3 additions & 1 deletion bug_report.php
Expand Up @@ -196,9 +196,9 @@
$t_bug_data->handler_id = auth_get_current_user_id();
}


# Create the bug
$t_bug_id = $t_bug_data->create();
$t_bug_data->process_mentions();

# Mark the added issue as visited so that it appears on the last visited list.
last_visited_issue( $t_bug_id );
Expand Down Expand Up @@ -271,6 +271,8 @@
0,
0,
false );

# Note: we won't trigger mentions in the clone scenario.
}
}

Expand Down
3 changes: 2 additions & 1 deletion bug_update.php
Expand Up @@ -402,7 +402,8 @@

# Add a bug note if there is one.
if( $t_bug_note->note || helper_duration_to_minutes( $t_bug_note->time_tracking ) > 0 ) {
bugnote_add( $f_bug_id, $t_bug_note->note, $t_bug_note->time_tracking, $t_bug_note->view_state == VS_PRIVATE, 0, '', null, false );
$t_bugnote_id = bugnote_add( $f_bug_id, $t_bug_note->note, $t_bug_note->time_tracking, $t_bug_note->view_state == VS_PRIVATE, 0, '', null, false );
bugnote_process_mentions( $f_bug_id, $t_bugnote_id, $t_bug_note->note );
}

# Add a duplicate relationship if requested.
Expand Down
3 changes: 3 additions & 0 deletions bugnote_add.php
Expand Up @@ -94,6 +94,9 @@
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

# Process the mentions in the added note
bugnote_process_mentions( $t_bug->id, $t_bugnote_id, $f_bugnote_text );

# Handle the reassign on feedback feature. Note that this feature generally
# won't work very well with custom workflows as it makes a lot of assumptions
# that may not be true. It assumes you don't have any statuses in the workflow
Expand Down
23 changes: 17 additions & 6 deletions core/bug_api.php
Expand Up @@ -546,6 +546,15 @@ function create() {
history_log_event_direct( $this->id, 'status', $t_original_status, $t_status );
history_log_event_direct( $this->id, 'handler_id', 0, $this->handler_id );

return $this->id;
}

/**
* Process mentions in the current issue, for example, after the issue is created.
* @return void
* @access public
*/
function process_mentions() {
# Now that the issue is added process the @ mentions
$t_all_mentioned_user_ids = array();

Expand Down Expand Up @@ -591,8 +600,6 @@ function create() {
$t_mention_text,
$t_removed_mentions_user_ids );
}

return $this->id;
}

/**
Expand Down Expand Up @@ -1713,7 +1720,8 @@ function bug_assign( $p_bug_id, $p_user_id, $p_bugnote_text = '', $p_bugnote_pri
history_log_event_direct( $p_bug_id, 'handler_id', $h_handler_id, $p_user_id );

# Add bugnote if supplied ignore false return
bugnote_add( $p_bug_id, $p_bugnote_text, 0, $p_bugnote_private, 0, '', null, false );
$t_bugnote_id = bugnote_add( $p_bug_id, $p_bugnote_text, 0, $p_bugnote_private, 0, '', null, false );
bugnote_process_mentions( $p_bug_id, $t_bugnote_id, $p_bugnote_text );

# updated the last_updated date
bug_update_date( $p_bug_id );
Expand Down Expand Up @@ -1742,7 +1750,8 @@ function bug_close( $p_bug_id, $p_bugnote_text = '', $p_bugnote_private = false,
# Add bugnote if supplied ignore a false return
# Moved bugnote_add before bug_set_field calls in case time_tracking_no_note is off.
# Error condition stopped execution but status had already been changed
bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
$t_bugnote_id = bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
bugnote_process_mentions( $p_bug_id, $t_bugnote_id, $p_bugnote_text );

bug_set_field( $p_bug_id, 'status', config_get( 'bug_closed_status_threshold' ) );

Expand Down Expand Up @@ -1772,7 +1781,8 @@ function bug_resolve( $p_bug_id, $p_resolution, $p_fixed_in_version = '', $p_bug
# Add bugnote if supplied
# Moved bugnote_add before bug_set_field calls in case time_tracking_no_note is off.
# Error condition stopped execution but status had already been changed
bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
$t_bugnote_id = bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
bugnote_process_mentions( $p_bug_id, $t_bugnote_id, $p_bugnote_text );

$t_duplicate = !is_blank( $p_duplicate_id ) && ( $p_duplicate_id != 0 );
if( $t_duplicate ) {
Expand Down Expand Up @@ -1857,7 +1867,8 @@ function bug_reopen( $p_bug_id, $p_bugnote_text = '', $p_time_tracking = '0:00',
# Add bugnote if supplied
# Moved bugnote_add before bug_set_field calls in case time_tracking_no_note is off.
# Error condition stopped execution but status had already been changed
bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
$t_bugnote_id = bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking, $p_bugnote_private, 0, '', null, false );
bugnote_process_mentions( $p_bug_id, $t_bugnote_id, $p_bugnote_text );

bug_set_field( $p_bug_id, 'status', config_get( 'bug_reopen_status' ) );
bug_set_field( $p_bug_id, 'resolution', config_get( 'bug_reopen_resolution' ) );
Expand Down
37 changes: 24 additions & 13 deletions core/bugnote_api.php
Expand Up @@ -259,30 +259,41 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_
history_log_event_special( $p_bug_id, BUGNOTE_ADDED, bugnote_format_id( $t_bugnote_id ) );
}

# Event integration
event_signal( 'EVENT_BUGNOTE_ADD', array( $p_bug_id, $t_bugnote_id ) );

# only send email if the text is not blank, otherwise, it is just recording of time without a comment.
if( true == $p_send_email && !is_blank( $t_bugnote_text ) ) {
email_bugnote_add( $p_bug_id );
}

return $t_bugnote_id;
}

/**
* Process mentions in bugnote, typically after its added.
*
* @param int $p_bug_id The bug id
* @param int $p_bugnote_id The bugnote id
* @param string $p_bugnote_text The bugnote text
* @return void
* @access public
*/
function bugnote_process_mentions( $p_bug_id, $p_bugnote_id, $p_bugnote_text ) {
# Process the mentions that have access to the issue note
$t_mentioned_user_ids = mention_get_users( $t_bugnote_text );
$t_mentioned_user_ids = mention_get_users( $p_bugnote_text );
$t_filtered_mentioned_user_ids = access_has_bugnote_level_filter(
config_get( 'view_bug_threshold' ),
$t_bugnote_id,
$p_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_filtered_mentioned_user_ids,
$t_bugnote_text,
$p_bugnote_text,
$t_removed_mentions_user_ids );

# Event integration
event_signal( 'EVENT_BUGNOTE_ADD', array( $p_bug_id, $t_bugnote_id ) );

# only send email if the text is not blank, otherwise, it is just recording of time without a comment.
if( true == $p_send_email && !is_blank( $t_bugnote_text ) ) {
email_bugnote_add( $p_bug_id );
}

return $t_bugnote_id;
}

/**
Expand Down

0 comments on commit 3ecab1a

Please sign in to comment.