Skip to content

Commit

Permalink
Support adding issue notes
Browse files Browse the repository at this point in the history
Support adding a note while specifying text, reporter, and view state.

Fixes #23143
  • Loading branch information
vboctor committed Aug 5, 2017
1 parent ca19157 commit 39219bd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 44 deletions.
42 changes: 42 additions & 0 deletions api/rest/restcore/issues_rest.php
Expand Up @@ -33,6 +33,10 @@
$g_app->delete( '/', 'rest_issue_delete' );
$g_app->delete( '/{id}', 'rest_issue_delete' );
$g_app->delete( '/{id}/', 'rest_issue_delete' );

# Notes
$g_app->post( '/{id}/notes/', 'rest_issue_note_add' );
$g_app->post( '/{id}/notes', 'rest_issue_note_add' );
});

/**
Expand Down Expand Up @@ -131,3 +135,41 @@ function rest_issue_delete( \Slim\Http\Request $p_request, \Slim\Http\Response $
return $p_response->withStatus( HTTP_STATUS_NO_CONTENT );
}

function rest_issue_note_add( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_note_info = $p_request->getParsedBody();

$t_issue_id = isset( $p_args['id'] ) ? $p_args['id'] : $p_request->getParam( 'id' );

$t_note = new stdClass();
$t_note->text = isset( $t_note_info['text'] ) ? $t_note_info['text'] : '';

if( isset( $t_note_info['view_state'] ) ) {
$t_note->view_state = $t_note_info['view_state'];
}

if( isset( $t_note_info['reporter'] ) ) {
$t_note->reporter = $t_note_info['reporter'];
}

# TODO: support time tracking notes
# TODO: support reminder notes
# TODO: support note attachments

$t_result = mc_issue_note_add( /* username */ '', /* password */ '', $t_issue_id, $t_note );
if( ApiObjectFactory::isFault( $t_result ) ) {
return $p_response->withStatus( $t_result->status_code, $t_result->fault_string );
}

$t_note_id = $t_result;

$t_issue = mc_issue_get( /* username */ '', /* password */ '', $t_issue_id );
foreach( $t_issue['notes'] as $t_current_note ) {
if( $t_current_note['id'] == $t_note_id ) {
$t_note = $t_current_note;
break;
}
}

return $p_response->withStatus( HTTP_STATUS_CREATED, "Issue Note Created with id $t_issue_id" )->
withJson( array( 'note' => $t_note, 'issue' => $t_issue ) );
}
104 changes: 60 additions & 44 deletions api/soap/mc_issue_api.php
Expand Up @@ -340,62 +340,74 @@ function mci_issue_get_relationships( $p_issue_id, $p_user_id ) {
}

/**
* Get all visible notes for a specific issue
*
* @param integer $p_issue_id The id of the issue to retrieve the notes for.
* @return array that represents an SOAP IssueNoteData structure
* Convert a note row into an array.
* @param $p_bugnote_row The note row object.
* @return array The note array.
*/
function mci_issue_get_notes( $p_issue_id ) {
function mci_issue_note_data_as_array( $p_bugnote_row ) {
$t_user_id = auth_get_current_user_id();
$t_lang = mci_get_user_lang( $t_user_id );
$t_user_bugnote_order = 'ASC'; # always get the notes in ascending order for consistency to the calling application.
$t_has_time_tracking_access = access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id );

$t_result = array();
foreach( bugnote_get_all_visible_bugnotes( $p_issue_id, $t_user_bugnote_order, 0 ) as $t_value ) {
$t_bugnote = array();
$t_bugnote['id'] = (int)$t_value->id;
$t_bugnote['reporter'] = mci_account_get_array_by_id( $t_value->reporter_id );
$t_bugnote['text'] = mci_sanitize_xml_string( $t_value->note );
$t_bugnote['view_state'] = mci_enum_get_array_by_id( $t_value->view_state, 'view_state', $t_lang );
$t_bugnote['time_tracking'] = $t_has_time_tracking_access ? $t_value->time_tracking : 0;
$t_has_time_tracking_access = access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_bugnote_row->bug_id );

$t_created_at = ApiObjectFactory::datetimeString( $t_value->date_submitted );
$t_modified_at = ApiObjectFactory::datetimeString( $t_value->last_modified );
$t_bugnote = array();
$t_bugnote['id'] = (int)$p_bugnote_row->id;
$t_bugnote['reporter'] = mci_account_get_array_by_id( $p_bugnote_row->reporter_id );
$t_bugnote['text'] = mci_sanitize_xml_string( $p_bugnote_row->note );
$t_bugnote['view_state'] = mci_enum_get_array_by_id( $p_bugnote_row->view_state, 'view_state', $t_lang );
$t_bugnote['time_tracking'] = $t_has_time_tracking_access ? $p_bugnote_row->time_tracking : 0;

if( ApiObjectFactory::$soap ) {
$t_bugnote['note_type'] = $t_value->note_type;
$t_bugnote['note_attr'] = $t_value->note_attr;
$t_created_at = ApiObjectFactory::datetimeString( $p_bugnote_row->date_submitted );
$t_modified_at = ApiObjectFactory::datetimeString( $p_bugnote_row->last_modified );

$t_bugnote['date_submitted'] = $t_created_at;
$t_bugnote['last_modified'] = $t_modified_at;
} else {
switch( $t_value->note_type ) {
case BUGNOTE:
$t_type = 'note';
break;
case REMINDER:
$t_type = 'reminder';
break;
case TIME_TRACKING:
$t_type = $t_has_time_tracking_access ? 'timelog' : 'note';
break;
}
if( ApiObjectFactory::$soap ) {
$t_bugnote['note_type'] = $p_bugnote_row->note_type;
$t_bugnote['note_attr'] = $p_bugnote_row->note_attr;

$t_bugnote['type'] = $t_type;
$t_bugnote['date_submitted'] = $t_created_at;
$t_bugnote['last_modified'] = $t_modified_at;
} else {
switch( $p_bugnote_row->note_type ) {
case REMINDER:
$t_type = 'reminder';
break;
case TIME_TRACKING:
$t_type = $t_has_time_tracking_access ? 'timelog' : 'note';
break;
case BUGNOTE:
default:
$t_type = 'note';
break;
}

if( !is_blank( $t_value->note_attr ) ) {
$t_bugnote['attr'] = $t_value->note_attr;
}
$t_bugnote['type'] = $t_type;

if( isset( $t_bugnote['time_tracking'] ) && ( $t_bugnote['time_tracking'] == 0 || $t_type != 'timelog' ) ) {
unset( $t_bugnote['time_tracking'] );
}
if( !is_blank( $p_bugnote_row->note_attr ) ) {
$t_bugnote['attr'] = $p_bugnote_row->note_attr;
}

$t_bugnote['created_at'] = ApiObjectFactory::datetimeString( $t_created_at );
$t_bugnote['updated_at'] = ApiObjectFactory::datetimeString( $t_modified_at );
if( isset( $t_bugnote['time_tracking'] ) && ( $t_bugnote['time_tracking'] == 0 || $t_type != 'timelog' ) ) {
unset( $t_bugnote['time_tracking'] );
}

$t_bugnote['created_at'] = ApiObjectFactory::datetimeString( $t_created_at );
$t_bugnote['updated_at'] = ApiObjectFactory::datetimeString( $t_modified_at );
}

return $t_bugnote;
}

/**
* Get all visible notes for a specific issue
*
* @param integer $p_issue_id The id of the issue to retrieve the notes for.
* @return array that represents an SOAP IssueNoteData structure
*/
function mci_issue_get_notes( $p_issue_id ) {
$t_user_bugnote_order = 'ASC'; # always get the notes in ascending order for consistency to the calling application.

$t_result = array();
foreach( bugnote_get_all_visible_bugnotes( $p_issue_id, $t_user_bugnote_order, 0 ) as $t_value ) {
$t_bugnote = mci_issue_note_data_as_array( $t_value );
$t_result[] = $t_bugnote;
}

Expand Down Expand Up @@ -1251,6 +1263,10 @@ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, stdClass $p_n
if( isset( $p_note['reporter'] ) ) {
$t_reporter_id = mci_get_user_id( $p_note['reporter'] );

if( !$t_reporter_id ) {
return ApiObjectFactory::faultBadRequest( 'Invalid reporter.' );
}

if( $t_reporter_id != $t_user_id ) {
# Make sure that active user has access level required to specify a different reporter.
$t_specify_reporter_access_level = config_get( 'webservice_specify_reporter_on_add_access_level_threshold' );
Expand Down

0 comments on commit 39219bd

Please sign in to comment.