/** * Add a note to an existing issue. * * @param string $p_username The name of the user trying to add a note to an issue. * @param string $p_password The password of the user. * @param integer $p_issue_id The id of the issue to add the note to. * @param stdClass $p_note The note to add. * @return integer The id of the added note. */ function mc_issue_note_add($p_username, $p_password, $p_issue_id, stdClass $p_note) { global $g_project_override; $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if ((int) $p_issue_id < 1) { return SoapObjectsFactory::newSoapFault('Client', 'Invalid issue id \'' . $p_issue_id . '\''); } if (!bug_exists($p_issue_id)) { return SoapObjectsFactory::newSoapFault('Client', 'Issue \'' . $p_issue_id . '\' does not exist.'); } $p_note = SoapObjectsFactory::unwrapObject($p_note); if (!isset($p_note['text']) || is_blank($p_note['text'])) { return SoapObjectsFactory::newSoapFault('Client', 'Issue note text must not be blank.'); } $t_project_id = bug_get_field($p_issue_id, 'project_id'); $g_project_override = $t_project_id; if (!mci_has_readwrite_access($t_user_id, $t_project_id)) { return mci_soap_fault_access_denied($t_user_id); } if (!access_has_bug_level(config_get('add_bugnote_threshold'), $p_issue_id, $t_user_id)) { return mci_soap_fault_access_denied($t_user_id, 'You do not have access rights to add notes to this issue'); } if (bug_is_readonly($p_issue_id)) { return mci_soap_fault_access_denied($t_user_id, 'Issue \'' . $p_issue_id . '\' is readonly'); } if (isset($p_note['view_state'])) { $t_view_state = $p_note['view_state']; } else { $t_view_state = array('id' => config_get('default_bug_view_status')); } # TODO: #17777: Add test case for mc_issue_add() and mc_issue_note_add() reporter override if (isset($p_note['reporter'])) { $t_reporter_id = mci_get_user_id($p_note['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'); if (!access_has_project_level($t_specify_reporter_access_level, $t_project_id, $t_user_id)) { return mci_soap_fault_access_denied($t_user_id, "Active user does not have access level required to specify a different issue note reporter"); } } } else { $t_reporter_id = $t_user_id; } $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state); $t_note_type = isset($p_note['note_type']) ? (int) $p_note['note_type'] : BUGNOTE; $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); }
/** * Add a note to an existing issue. * * @param string $p_username The name of the user trying to add a note to an issue. * @param string $p_password The password of the user. * @param integer $p_issue_id The id of the issue to add the note to. * @param IssueNoteData $p_note The note to add. * @return integer The id of the added note. */ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, $p_note ) { $t_user_id = mci_check_login( $p_username, $p_password ); if( $t_user_id === false ) { return mci_soap_fault_login_failed(); } if( (integer) $p_issue_id < 1 ) { return new soap_fault( 'Client', '', "Invalid issue id '$p_issue_id'" ); } if( !bug_exists( $p_issue_id ) ) { return new soap_fault( 'Client', '', "Issue '$p_issue_id' does not exist." ); } if ( !isset( $p_note['text'] ) || is_blank( $p_note['text'] ) ) { return new soap_fault( 'Client', '', "Issue note text must not be blank." ); } $t_project_id = bug_get_field( $p_issue_id, 'project_id' ); if( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) { return mci_soap_fault_access_denied( $t_user_id ); } if( !access_has_bug_level( config_get( 'add_bugnote_threshold' ), $p_issue_id, $t_user_id ) ) { return mci_soap_fault_access_denied( $t_user_id, "You do not have access rights to add notes to this issue" ); } if( bug_is_readonly( $p_issue_id ) ) { return mci_soap_fault_access_denied( $t_user_id, "Issue '$p_issue_id' is readonly" ); } if( isset( $p_note['view_state'] ) ) { $t_view_state = $p_note['view_state']; } else { $t_view_state = array( 'id' => config_get( 'default_bug_view_status' ), ); } $t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state ); $note_type = isset ( $p_note['note_type'] ) ? (int) $p_note['note_type'] : BUGNOTE; $note_attr = isset ( $p_note['note_type'] ) ? $p_note['note_attr'] : ''; 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, $note_type, $note_attr, $t_user_id ); }