View Issue Details

IDProjectCategoryView StatusLast Update
0013000mantisbtapi soappublic2013-04-06 08:22
Reporternerville Assigned Torombert  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.2.5 
Target Version1.2.6Fixed in Version1.2.6 
Summary0013000: Add soap feature : update a note of a specific issue
Description

Currently, soap api offers only : add or delete note for a issue.
This patch adds the ability to update a specific note.

TagsNo 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

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

rombert

rombert

2011-05-17 17:02

reporter   ~0028792

Thanks for the patch! Can you please remove the unrelated whitespace changes from it?

nerville

nerville

2011-05-18 09:31

reporter   ~0028797

hi, I clean up my patch. Please use feature_api_soap-update_a_note_for_a_specific_issue as patch.

rombert

rombert

2011-05-18 15:45

reporter   ~0028799

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.

nerville

nerville

2011-05-24 09:29

reporter   ~0028830

hi, I followed your advice. Please find a new patch.

rombert

rombert

2011-05-24 15:59

reporter   ~0028833

I've applied your patch and ran the test. I got an error:

1) IssueNoteTest::testAddThenUpdateThenDeleteNote
SoapFault: Error Type: SYSTEM NOTICE,
Error Description:
Undefined index: id,
Stack Trace:
UnknownFile L? mc_issue_note_update(<string>'administrator', <string>'root', <integer>6504, <integer>2014, <Array> { ['text'] => 'some new note' })
nusoap.php L4087 call_user_func_array(<string>'mc_issue_note_update', <Array> { [0] => 'administrator', [1] => 'root', [2] => 6504, [3] => 2014, [4] => <Array> { ['text'] => 'some new note' } })
nusoap.php L3718 invoke_method()
mantisconnect.php L1541 service(<string>'<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://futureware.biz/mantisconnect" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:mc_issue_note_update><username xsi:type="xsd:string">administrator</username><password xsi:type="xsd:string">root</password><issue_id xsi:type="xsd:integer">6504</issue_id><issue_note_id xsi:type="xsd:integer">2014</issue_note_id><note xsi:type="ns1:IssueNoteData"><text xsi:type="xsd:string">some new note</text></note></ns1:mc_issue_note_update></SOAP-ENV:Body></SOAP-ENV:Envelope>
')

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'] ?

nerville

nerville

2011-06-07 09:09

reporter   ~0028936

Hi,

I'm really sorry. My mistake.
the right comparison is :
$issueWithNote->note[0]->text vs. $issueWithNewNote->note[0]->text
The first is the initial text. The second is the new updated text.
You cannot use $noteDataNew['text'] because it's a local value, not a updated note.

Please find a updated patch.

rombert

rombert

2011-06-07 17:05

reporter   ~0028939

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.

nerville

nerville

2011-06-22 05:58

reporter   ~0029049

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 ?

rombert

rombert

2011-06-22 08:28

reporter   ~0029051

Nope, I just wanted to get your confirmation. I'll merge this soon to master and master-1.2.x .

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036436

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 7cedb86b

2011-05-24 09:27

nerville

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

nerville

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