Skip to content

Commit

Permalink
Issue #8612: Expose time tracking on notes using the SOAP API
Browse files Browse the repository at this point in the history
Expose the invidual time spent on each IssueNoteData. Checks are performed
to see if the user has the required access level.

A new utility function mci_get_time_tracking_from_note has been added to
centralise access control checks and conversions.
  • Loading branch information
rombert committed Nov 24, 2009
1 parent fbbc2d0 commit 8b69aa2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion api/soap/mantisconnect.php
Expand Up @@ -211,7 +211,8 @@
'text' => array( 'name' => 'text', 'type' => 'xsd:string', 'minOccurs' => '0'),
'view_state' => array( 'name' => 'view_state', 'type' => 'tns:ObjectRef', 'minOccurs' => '0'),
'date_submitted' => array( 'name' => 'date_submitted', 'type' => 'xsd:dateTime', 'minOccurs' => '0'),
'last_modified' => array( 'name' => 'last_modified', 'type' => 'xsd:dateTime', 'minOccurs' => '0')
'last_modified' => array( 'name' => 'last_modified', 'type' => 'xsd:dateTime', 'minOccurs' => '0'),
'time_tracking' => array( 'name' => 'time_tracking', 'type' => 'xsd:integer', 'minOccurs' => '0')
)
);

Expand Down
19 changes: 19 additions & 0 deletions api/soap/mc_api.php
Expand Up @@ -293,6 +293,25 @@ function mci_category_as_array_by_id( $p_category_id ) {
return $t_result;
}

/**
* Returns time tracking information from a bug note.
*
* @param int $p_issue_id The id of the issue
* @param Array $p_note A note as passed to the soap api methods
*
* @return String the string time entry to be added to the bugnote, in 'HH:mm' format
*/
function mci_get_time_tracking_from_note( $p_issue_id, $p_note) {

if ( !access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id ) )
return '00:00';

if ( !isset( $p_note['time_tracking'] ))
return '00:00';

return db_minutes_to_hhmm($p_note['time_tracking']);
}

/**
* SECURITY NOTE: these globals are initialized here to prevent them
* being spoofed if register_globals is turned on
Expand Down
18 changes: 12 additions & 6 deletions api/soap/mc_issue_api.php
Expand Up @@ -292,7 +292,8 @@ function mci_issue_get_notes( $p_issue_id ) {
$t_lang = mci_get_user_lang( $t_user_id );
$t_project_id = bug_get_field( $p_issue_id, 'project_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();
Expand All @@ -302,6 +303,8 @@ function mci_issue_get_notes( $p_issue_id ) {
$t_bugnote['last_modified'] = timestamp_to_iso8601( $t_value->last_modified );
$t_bugnote['text'] = $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_result[] = $t_bugnote;
}

Expand Down Expand Up @@ -586,7 +589,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
}

$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
bugnote_add( $t_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
bugnote_add( $t_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $t_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
}
}

Expand Down Expand Up @@ -747,7 +750,7 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {

# submit the issue
$t_is_success = $t_bug_data->update( /* update_extended */ true, /* bypass_email */ true );

mci_issue_set_custom_fields( $p_issue_id, $p_issue['custom_fields'], true );

if ( isset( $p_issue['notes'] ) && is_array( $p_issue['notes'] ) ) {
Expand All @@ -765,10 +768,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
bugnote_set_text( $t_bugnote_id, $t_note['text'] );
bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
bugnote_date_update( $t_bugnote_id );
if ( isset( $t_note['time_tracking'] ) )
bugnote_set_time_tracking( $t_bugnote_id, mci_get_time_tracking_from_note( $p_issue_id, $t_note ) );
}
} else {
$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
bugnote_add( $p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );

bugnote_add( $p_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
}
}
}
Expand Down Expand Up @@ -849,9 +855,9 @@ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, $p_note ) {
'id' => config_get( 'default_bug_view_status' ),
);
}

$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
return bugnote_add( $p_issue_id, $p_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_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, BUGNOTE, '', $t_user_id );
}

/**
Expand Down

0 comments on commit 8b69aa2

Please sign in to comment.