From bd2301065b99ddeb32846b132e6735875e2d9b95 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Tue, 24 May 2011 15:27:18 +0200 Subject: [PATCH 2/2] SOAP API: update a specific note for a specific issue Fixes #13000: Add soap feature : update a note of a specific issue Signed-off-by: Robert Munteanu --- api/soap/mantisconnect.php | 15 +++++++++++ api/soap/mc_issue_api.php | 56 ++++++++++++++++++++++++++++++++++++++++++ tests/soap/IssueNoteTest.php | 33 ++++++++++++++++++++---- 3 files changed, 98 insertions(+), 6 deletions(-) diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index c0d37df..71afdc0 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -894,6 +894,21 @@ $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', + 'note' => 'tns:IssueNoteData' + ), + array( + 'return' => 'xsd:boolean' + ), + $t_namespace, + false, false, false, + 'Update a specific 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..489bc0b 100644 --- a/api/soap/mc_issue_api.php +++ b/api/soap/mc_issue_api.php @@ -980,6 +980,62 @@ 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 IssueNoteData $p_note The note to update. + * @return true on success, false on failure + */ +function mc_issue_note_update( $p_username, $p_password, $p_note ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + + if( $t_user_id === false ) { + return mci_soap_fault_login_failed(); + } + + if ( !isset( $p_note['id'] ) || is_blank( $p_note['id'] ) ) { + return new soap_fault( 'Client', '', "Issue id must not be blank." ); + } + + if ( !isset( $p_note['text'] ) || is_blank( $p_note['text'] ) ) { + return new soap_fault( 'Client', '', "Issue note text must not be blank." ); + } + + $t_issue_note_id = $p_note['id']; + + if( !bugnote_exists( $t_issue_note_id ) ) { + return new soap_fault( 'Server', '', "Issue note '$t_issue_note_id' does not exist." ); + } + + $t_issue_id = bugnote_get_field( $t_issue_note_id, 'bug_id' ); + + $t_project_id = bug_get_field( $t_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' ), $t_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( $t_issue_id ) ) { + return mci_soap_fault_access_denied( $t_user_id, "Issue ' . $t_issue_id . ' is readonly" ); + } + + if( isset( $p_note['view_state'] )) { + $t_view_state = $p_note['view_state']; + $t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state ); + bugnote_set_view_state( $t_issue_note_id, $t_view_state_id ); + } + + bugnote_set_text( $t_issue_note_id, $p_note['text'] ); + + return bugnote_date_update( $t_issue_note_id ); +} + +/** * 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..5333416 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, @@ -185,6 +187,25 @@ class IssueNoteTest extends SoapBase { $this->assertEquals( 1, count( $issueWithNote->notes ) ); + $noteDataNew = array( + 'id' => $issueNoteId, + 'text' => "some new note" + ); + + $this->client->mc_issue_note_update( + $this->userName, + $this->password, + $noteDataNew); + + $issueWithNewNote = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + $this->assertEquals( 1, count( $issueWithNote->notes ) ); + + $this->assertEquals( $noteDataNew['text'], $issueWithNewNote->notes[0]->text ); + $this->client->mc_issue_note_delete( $this->userName, $this->password, -- 1.7.3.4