View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0013000 | mantisbt | api soap | public | 2011-05-16 11:33 | 2013-04-06 08:22 |
Reporter | nerville | Assigned To | rombert | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.2.5 | ||||
Target Version | 1.2.6 | Fixed in Version | 1.2.6 | ||
Summary | 0013000: Add soap feature : update a note of a specific issue | ||||
Description | Currently, soap api offers only : add or delete note for a issue. | ||||
Tags | No tags attached. | ||||
Attached Files | 0002-SOAP-API-update-a-specific-note-for-a-specific-issue.patch (5,607 bytes)
From bd2301065b99ddeb32846b132e6735875e2d9b95 Mon Sep 17 00:00:00 2001 From: Franck Villaume <franck.villaume@capgemini.com> 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 <robert.munteanu@gmail.com> --- 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 | ||||
Thanks for the patch! Can you please remove the unrelated whitespace changes from it? |
|
hi, I clean up my patch. Please use feature_api_soap-update_a_note_for_a_specific_issue as patch. |
|
Thanks. I think that the 'type_update' parameter to the newly added function specifies what sort of update to perform. That is not in line with the rest of the SOAP API, so I'd prefer if the parameter would be dropped and the note updated based on the incoming data. |
|
hi, I followed your advice. Please find a new patch. |
|
I've applied your patch and ran the test. I got an error: 1) IssueNoteTest::testAddThenUpdateThenDeleteNote Also, I'm not sure what the $this->assertNotEquals( $issueWithNote->note[$issueWithNote]->text, $issueWithNewNote->note[$issueWithNewNote]->text );line tries to achieve. Shouldn't you compare $issueWithNote->notes[0]->text with $noteDataNew['text'] ? |
|
Hi, I'm really sorry. My mistake. Please find a updated patch. |
|
This patch needed a bit more polish, so I'm posting my changes here as well. Hopefully they will still fit your use case. The main change is that there is no need to pass the issue id and issue note id as parameters. All the data is instead passed to through the note field. The issue id was not needed to start with. I also get the feel that you were unable to run the unit tests, as they still errored out. Please have a look at http://docs.mantisbt.org/master/en/developers.html#DEV.CONTRIB.TEST and let me know if you need more information about how to run the tests yourself. It's way more effective this way. |
|
Hi, I'm fine with your modifications. thank you for helping and I'm very sorry about the tests suite. Next time, I'll try to do a better job. Do you expect something from me for merging this patch in master-1.2.x or is it ok ? |
|
Nope, I just wanted to get your confirmation. I'll merge this soon to master and master-1.2.x . |
|
Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch |
|
MantisBT: master 7cedb86b 2011-05-24 09:27 Committer: rombert Details Diff |
SOAP API: update a specific note for a specific issue Fixes 0013000: Add soap feature : update a note of a specific issue Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com> |
Affected Issues 0013000 |
|
mod - api/soap/mc_issue_api.php | Diff File | ||
mod - tests/soap/IssueNoteTest.php | Diff File | ||
mod - api/soap/mantisconnect.php | Diff File | ||
MantisBT: master-1.2.x 56bc9319 2011-05-24 09:27 Committer: rombert Details Diff |
SOAP API: update a specific note for a specific issue Fixes 0013000: Add soap feature : update a note of a specific issue Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com> |
Affected Issues 0013000 |
|
mod - tests/soap/IssueNoteTest.php | Diff File | ||
mod - api/soap/mantisconnect.php | Diff File | ||
mod - api/soap/mc_issue_api.php | Diff File |