From 60044799d59451978abcc2a9b0c1e58dbb9c9218 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Wed, 18 May 2011 15:26:56 +0200 Subject: [PATCH] new feature soap api: update a existing note for a specific issue --- api/soap/mantisconnect.php | 18 +++++++++++++ api/soap/mc_issue_api.php | 58 ++++++++++++++++++++++++++++++++++++++++++ tests/soap/IssueNoteTest.php | 36 +++++++++++++++++++++---- 3 files changed, 106 insertions(+), 6 deletions(-) diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index c0d37df..4516d5c 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -894,6 +894,24 @@ $l_oServer->register( 'mc_issue_note_delete', 'Delete the note with the specified id.' ); +### mc_issue_note_update +$l_oServer->register( 'mc_issue_note_update', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'issue_id' => 'xsd:integer', + 'issue_note_id' => 'xsd:integer', + 'note' => 'tns:IssueNoteData', + 'type_update' => 'tns:string' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Update an existing note of a specific issue.' +); + ### mc_issue_relationship_add $l_oServer->register( 'mc_issue_relationship_add', array( diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php index dd2bd96..6b91193 100644 --- a/api/soap/mc_issue_api.php +++ b/api/soap/mc_issue_api.php @@ -980,6 +980,64 @@ function mc_issue_note_delete( $p_username, $p_password, $p_issue_note_id ) { } /** + * Update a note + * + * @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 update the note to. + * @param integer $p_note_id The id of the note to update. + * @param IssueNoteData $p_note The note to update. + * @return integer The id of the added note. + */ +function mc_issue_note_update( $p_username, $p_password, $p_issue_id, $p_issue_note_id, $p_note, $p_type_update ) { + $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 note id '$p_issue_note_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." ); + } + + if( !bugnote_exists( $p_issue_note_id ) ) { + return new soap_fault( 'Server', '', "Issue note '$p_issue_note_id' does not exist." ); + } + + $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']) && $p_type_update == "state") { + $t_view_state = $p_note['view_state']; + $t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state ); + bugnote_date_update($p_note['id']); + return bugnote_set_view_state($p_note['id'],$t_view_state_id); + }else{ + bugnote_date_update($p_note['id']); + return bugnote_set_text($p_note['id'], $p_note['text']); + } +} + + + +/** * Submit a new relationship. * * @param string $p_username The name of the user trying to add a note to an issue. diff --git a/tests/soap/IssueNoteTest.php b/tests/soap/IssueNoteTest.php index 9aa3eb2..cdbcb59 100644 --- a/tests/soap/IssueNoteTest.php +++ b/tests/soap/IssueNoteTest.php @@ -148,13 +148,15 @@ class IssueNoteTest extends SoapBase { * 2. Add a note to the issue. * 3. Get the issue. * 4. Verify that the issue has one note. - * 5. Delete the note. - * 6. Get the issue. - * 7. Verify that the issue has no notes. - * 8. Delete the issue. + * 5. Update this note + * 6. Verify that the note has been updated + * 7. Delete the note. + * 8. Get the issue. + * 9. Verify that the issue has no notes. + * 10. Delete the issue. */ - public function testAddThenDeleteNote() { - $issueToAdd = $this->getIssueToAdd( 'IssueNoteTest.testAddThenDeleteNote' ); + public function testAddThenUpdateThenDeleteNote() { + $issueToAdd = $this->getIssueToAdd( 'IssueNoteTest.testAddThenUpdateThenDeleteNote' ); $issueId = $this->client->mc_issue_add( $this->userName, @@ -184,6 +186,28 @@ class IssueNoteTest extends SoapBase { $issueId); $this->assertEquals( 1, count( $issueWithNote->notes ) ); + + $noteDataNew = array( + 'text' => "some new note", + ); + + $this->client->mc_issue_note_update( + $this->userName, + $this->password, + $issueId, + $issueNoteId, + $noteDataNew, + 'text'); + + $issueWithNewNote = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + $this->assertEquals( 1, count( $issueWithNote->notes ) ); + + $this->assertNotEquals( $issueWithNote->note[$issueWithNote]->text, $issueWithNewNote->note[$issueWithNewNote]->text ); + $this->client->mc_issue_note_delete( $this->userName, -- 1.7.3.4