View Issue Details

IDProjectCategoryView StatusLast Update
0009936mantisbtapi soappublic2014-02-07 18:24
ReporterlaurentbAssigned Torombert 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
PlatformAllOSAllOS Version
Product Version1.1.2 
Target Version1.2.16Fixed in Version1.2.16 
Summary0009936: add history information
Description

Hi,

I've been using Mantisconnect for some project.
For this particular project, i needed to get history information in
addition of current available issue information.

So i had to develop this feature of php webservice based on latest version
of
mantisconnect/trunk/webservice/mc

services concernes are :

mc_issue_get
mc_project_get_issues
mc_filter_get_issues

Now that is done and it works fine to me, and in view of the fact that
this feature could be useful for users, i was wondering if it could
integrated in a next version.

Anyway, here is the archive of code modifications in attached file.

Because it has been not modified, the archive doesn't contains "nusoap"
directory.

Tagspatch

Relationships

has duplicate 0014833 closed mantisbt MantisConnect - Possibility to add Histories in IssueData 
related to 0014943 confirmed Mylyn Connector Make history available in Mylyn 

Activities

2008-12-04 09:20

 

mc.zip (38,692 bytes)
vboctor

vboctor

2011-12-13 02:31

manager   ~0030562

It would be great if you can provide a patch against 1.2.8 release / latest code in master-1.2.x branch. If you are a user of github, then sending a pull request for your change will even be better.

wmatusiak

wmatusiak

2012-06-07 20:32

reporter  

ticket_0009936.patch (5,235 bytes)
From 6ef67892ba907cffb9d0190e8e4c100401ce4610 Mon Sep 17 00:00:00 2001
From: Wojciech Matusiak <wmatusiak@gmail.com>
Date: Fri, 8 Jun 2012 02:21:03 +0200
Subject: [PATCH] Fixed #0009936: add history information - reapply code on
 1.2.x

---
 api/soap/mantisconnect.php |   33 ++++++++++++++++++++++++++++++-
 api/soap/mc_issue_api.php  |   47 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index 819dced..86ae370 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -241,6 +241,36 @@ $l_oServer->wsdl->addComplexType(
 	'tns:IssueNoteData'
 );
 
+### HistoryData
+$l_oServer->wsdl->addComplexType(
+	'HistoryData',
+	'complexType',
+	'struct',
+	'all',
+	'',
+	array(
+		'date_modified'		=>	array( 'name' => 'date_modified',	'type' => 'xsd:dateTime'),
+		'username'			=>	array( 'name' => 'username',		'type' => 'xsd:string'),
+		'field'				=>	array( 'name' => 'field',			'type' => 'xsd:string'),
+		'change'			=>	array( 'name' => 'change',			'type' => 'xsd:string'),
+	)
+);
+
+### HistoryDataArray
+$l_oServer->wsdl->addComplexType(
+	'HistoryDataArray',
+	'complexType',
+	'array',
+	'',
+	'SOAP-ENC:Array',
+	array(),
+	array(array(
+		'ref'				=> 'SOAP-ENC:arrayType',
+		'wsdl:arrayType'	=> 'tns:HistoryData[]'
+	)),
+	'tns:HistoryData'
+);
+
 ### IssueData
 $l_oServer->wsdl->addComplexType(
 	'IssueData',
@@ -290,7 +320,8 @@ $l_oServer->wsdl->addComplexType(
 		'due_date'					=>  array( 'name' => 'due_date',				'type' => 'xsd:dateTime', 	'minOccurs' => '0' ),
 	    'monitors'					=>  array( 'name' => 'monitors',                'type' => 'tns:AccountDataArray', 'minOccurs' => '0'),
 	    'sticky'    				=>  array( 'name' => 'sticky',                  'type' => 'xsd:boolean', 'minOccurs' => '0'),
-	    'tags'						=>  array( 'name' => 'tags',                	'type' => 'tns:ObjectRefArray', 'minOccurs' => '0')
+	    'tags'						=>  array( 'name' => 'tags',                	'type' => 'tns:ObjectRefArray', 'minOccurs' => '0'),
+		'histories'					=>	array( 'name' => 'histories', 				'type' => 'tns:HistoryDataArray', 	'minOccurs' => '0' )
 	)
 );
 
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index 251b12d..3b51885 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -112,6 +112,7 @@ function mc_issue_get( $p_username, $p_password, $p_issue_id ) {
 	$t_issue_data['relationships'] = mci_issue_get_relationships( $p_issue_id, $t_user_id );
 	$t_issue_data['notes'] = mci_issue_get_notes( $p_issue_id );
 	$t_issue_data['custom_fields'] = mci_issue_get_custom_fields( $p_issue_id );
+	$t_issue_data['histories'] = mci_issue_get_histories( $p_issue_id );
 	$t_issue_data['monitors'] = mci_account_get_array_by_ids( bug_get_monitors ( $p_issue_id ) );
 	$t_issue_data['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_id , $t_user_id );
 
@@ -1390,6 +1391,7 @@ function mci_issue_data_as_array( $p_issue_data, $p_user_id, $p_lang ) {
 		$t_issue['relationships'] = mci_issue_get_relationships( $p_issue_data->id, $p_user_id );
 		$t_issue['notes'] = mci_issue_get_notes( $p_issue_data->id );
 		$t_issue['custom_fields'] = mci_issue_get_custom_fields( $p_issue_data->id );
+		$t_issue['histories'] = mci_issue_get_histories( $p_issue_data->id );
 		$t_issue['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_data->id, $p_user_id );
 
 		return $t_issue;
@@ -1447,3 +1449,48 @@ function mci_issue_data_as_header_array( $p_issue_data ) {
 
 		return $t_issue;
 }
+
+
+/**
+ * Get the histories of an issue.
+ *
+ * @param integer $p_issue_id  The id of the issue to retrieve the histories for
+ * @return Array that represents an HistoryData structure
+ */
+function mci_issue_get_histories( $p_issue_id ) {
+	$t_history_rows = mci_history_get_events_array( $p_issue_id );
+	$t_result = array();
+
+	foreach( $t_history_rows as $t_history_row ) {
+		$t_history = array();
+		$t_history['date_modified'] = timestamp_to_iso8601( $t_history_row['date'] );
+		$t_history['username'] = user_get_name($t_history_row['userid']);
+		$t_history['field'] = $t_history_row['note'];
+		$t_history['change'] = $t_history_row['change'];
+		$t_result[] = $t_history;
+	}
+
+	return $t_result;
+}
+
+# --------------------
+# Retrieves the history events for the specified bug id and returns it in an array
+# The array is indexed from 0 to N-1.  The second dimension is: 'date', 'username',
+# 'note', 'change'.
+function mci_history_get_events_array( $p_bug_id, $p_user_id = null ) {
+	$t_normal_date_format = config_get( 'normal_date_format' );
+
+	$raw_history = history_get_raw_events_array( $p_bug_id, $p_user_id );
+	$raw_history_count = count( $raw_history );
+	$history = array();
+
+	for ( $i=0; $i < $raw_history_count; $i++ ) {
+		$history[$i]		= history_localize_item( $raw_history[$i]['field'], $raw_history[$i]['type'], $raw_history[$i]['old_value'], $raw_history[$i]['new_value'] );
+		# get Date with db_unixtimestamp format
+		$history[$i]['date']	= $raw_history[$i]['date'];
+		$history[$i]['userid']	= $raw_history[$i]['userid'];
+		$history[$i]['username'] = $raw_history[$i]['username'];
+	}
+
+	return ( $history );
+}
-- 
1.7.9.5

ticket_0009936.patch (5,235 bytes)
wmatusiak

wmatusiak

2012-06-07 20:33

reporter   ~0032043

Last edited: 2012-06-07 20:41

View 2 revisions

Hello
Code in zip is based on very old version ;(
I diff it with 3ed7f3c, with is first soap api version, and then reapply over 1.2.x.
Add some code format tweak and resolve code incompatibilities.
I attached formated patch.

This should also work with 1.3 but not test it.

vboctor

vboctor

2012-06-09 23:20

manager   ~0032056

I had a quick look, here are some comments:

  1. The history array should contain old value and new value, rather than change.

  2. For user, we may want to use mci_account_get_array_by_id() to be consistent with other places where we reference a user.

  3. The entry name in the array should not be "histories", maybe "history", "history_entries", "audit_log". I prefer the "audit_log" or "history".

  4. There are no unit tests.

  5. I wonder if we should be localizing the entries or not. We should check other areas.

  6. You seem to have two methods that retrieve the history + transform it. Maybe they should be combined into one method.
vboctor

vboctor

2012-06-09 23:21

manager   ~0032057

btw, thanks for the contribution.

rombert

rombert

2012-06-10 06:04

developer   ~0032058

This looks good overall, thanks.

I have one design comment - we should move this history information to a different soap call. Adding it to the existing one can greatly increase the data transfer required when querying for issues , which I think is not what we want.

I suggest that we make a separate API call: mc_issue_get_history ( username, password, issue_id ) or whatever fits your use case.

A nitpick - you're calling config_get( 'normal_date_format' ) but not using it at all.

wmatusiak

wmatusiak

2012-06-10 16:08

reporter   ~0032064

I only get code from zip and reapply it on never version.
I not change anything from original code provided by laurentb.
Your comments looks good.

I think I'd find some time to implement it and provide better patch ;)

rombert

rombert

2012-06-11 06:24

developer   ~0032066

(In reply to comment 0009936:0032064)

I think I'd find some time to implement it and provide better patch ;)

That would be great! If you need help in development please ask in this ticket or subscribe to https://lists.sourceforge.net/lists/listinfo/mantisbt-soap-dev - whichever feels most comfortable to you.

winston

winston

2012-12-03 08:00

reporter  

mantis_history_SOAP.patch (5,251 bytes)
diff --git a/api/soap/mantisconnect.wsdl b/api/soap/mantisconnect.wsdl
index 1e3faac..7d5f2ce 100644
--- a/api/soap/mantisconnect.wsdl
+++ b/api/soap/mantisconnect.wsdl
@@ -164,6 +164,24 @@
    </xsd:restriction>
   </xsd:complexContent>
  </xsd:complexType>
+ <xsd:complexType name="HistoryData">
+  <xsd:all>
+   <xsd:element name="date" type="xsd:integer" minOccurs="0"/>
+   <xsd:element name="userid" type="xsd:integer" minOccurs="0"/>
+   <xsd:element name="username" type="xsd:string" minOccurs="0"/>
+   <xsd:element name="field" type="xsd:string" minOccurs="0"/>
+   <xsd:element name="type" type="xsd:integer" minOccurs="0"/>
+   <xsd:element name="old_value" type="xsd:integer" minOccurs="0"/>
+   <xsd:element name="new_value" type="xsd:integer" minOccurs="0"/>
+  </xsd:all>
+ </xsd:complexType>
+ <xsd:complexType name="HistoryDataArray">
+  <xsd:complexContent>
+   <xsd:restriction base="SOAP-ENC:Array">
+    <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:HistoryData[]"/>
+   </xsd:restriction>
+  </xsd:complexContent>
+ </xsd:complexType>
  <xsd:complexType name="IssueHeaderData">
   <xsd:all>
    <xsd:element name="id" type="xsd:integer"/>
@@ -435,6 +453,12 @@
   <part name="issue_id" type="xsd:integer" /></message>
 <message name="mc_issue_getResponse">
   <part name="return" type="tns:IssueData" /></message>
+<message name="mc_issue_get_historyRequest">
+  <part name="username" type="xsd:string" />
+  <part name="password" type="xsd:string" />
+  <part name="issue_id" type="xsd:integer" /></message>
+<message name="mc_issue_get_historyResponse">
+  <part name="return" type="tns:HistoryDataArray" /></message>
 <message name="mc_issue_get_biggest_idRequest">
   <part name="username" type="xsd:string" />
   <part name="password" type="xsd:string" />
@@ -843,6 +867,11 @@
     <input message="tns:mc_issue_getRequest"/>
     <output message="tns:mc_issue_getResponse"/>
   </operation>
+  <operation name="mc_issue_get_history">
+    <documentation>Get the history of the issue with the specified id.</documentation>
+    <input message="tns:mc_issue_get_historyRequest"/>
+    <output message="tns:mc_issue_get_historyResponse"/>
+  </operation>
   <operation name="mc_issue_get_biggest_id">
     <documentation>Get the latest submitted issue in the specified project.</documentation>
     <input message="tns:mc_issue_get_biggest_idRequest"/>
@@ -1171,6 +1200,11 @@
     <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
     <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
   </operation>
+  <operation name="mc_issue_get_history">
+    <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_issue_get_history" style="rpc"/>
+    <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
+    <output><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
+  </operation>
   <operation name="mc_issue_get_biggest_id">
     <soap:operation soapAction="http://www.mantisbt.org/bugs/api/soap/mantisconnect.php/mc_issue_get_biggest_id" style="rpc"/>
     <input><soap:body use="encoded" namespace="http://futureware.biz/mantisconnect" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index 410705a..a3e7693 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -45,7 +45,7 @@
  * @return Array that represents an IssueData structure
  */
 function mc_issue_get( $p_username, $p_password, $p_issue_id ) {
-	
+
 	$t_user_id = mci_check_login( $p_username, $p_password );
 	if( $t_user_id === false ) {
 		return mci_soap_fault_login_failed();
@@ -120,6 +120,42 @@
 }
 
 /**
+* Get history details about an issue.
+*
+* @param string $p_username  The name of the user trying to access the issue.
+* @param string $p_password  The password of the user.
+* @param integer $p_issue_id  The id of the issue to retrieve.
+* @return Array that represents a HistoryDataArray structure
+*/
+function mc_issue_get_history( $p_username, $p_password, $p_issue_id ) {
+
+	$t_user_id = mci_check_login( $p_username, $p_password );
+	if( $t_user_id === false ) {
+		return mci_soap_fault_login_failed();
+	}
+
+	$t_lang = mci_get_user_lang( $t_user_id );
+
+	if( !bug_exists( $p_issue_id ) ) {
+		return SoapObjectsFactory::newSoapFault('Client', 'Issue does not exist');
+	}
+
+	$t_project_id = bug_get_field( $p_issue_id, 'project_id' );
+	if( !mci_has_readonly_access( $t_user_id, $t_project_id ) ) {
+		return mci_soap_fault_access_denied( $t_user_id );
+	}
+
+	if( !access_has_bug_level( VIEWER, $p_issue_id, $t_user_id ) ){
+		return mci_soap_fault_access_denied( $t_user_id );
+	}
+
+	$t_bug_history = history_get_raw_events_array($p_issue_id, $t_user_id);
+
+	return $t_bug_history;
+
+}
+
+/**
  * Returns the category name, possibly null if no category is assigned
  *
  * @param int $p_category_id
winston

winston

2012-12-03 08:03

reporter   ~0034450

Last edited: 2012-12-03 08:04

View 2 revisions

Hi

I was looking for the same functionality. Please have a look at the attached patch (mantis_history_SOAP.patch) based on the "latest code in master-1.2.x branch" (commit id: deb45ecd7701e77439f7c10806f1a15c728def8a). It creates a new API function called mc_issue_get_history( username, password, issue_id ).

rombert

rombert

2012-12-15 19:02

developer   ~0034546

(In reply to comment 0009936:0034450)

Hi

I was looking for the same functionality. Please have a look at the attached
patch (mantis_history_SOAP.patch) based on the "latest code in master-1.2.x
branch" (commit id: deb45ecd7701e77439f7c10806f1a15c728def8a). It creates a new
API function called mc_issue_get_history( username, password, issue_id ).

Hi and thanks for the patch! I'd like to include this in the next release.

I have a couple of comments

  1. the security checks should include the 'view_history_threshold', see the email_build_visible_bug_data from email_api.php
  2. Could you submit this as a pull request on github, as it makes it easier to merge?

I'll add some soap tests if that's not something you can easily do now once you update your contribution.

winston

winston

2013-04-06 08:46

reporter   ~0036527

Last edited: 2013-04-19 11:35

View 2 revisions

Hi

I added the requested security check and created the pull request with the title "New function added to retrieve bug history via API." [1]

[1] http://www.mantisbt.org/bugs/view.php?id=9936

EDIT: dregad added link to PR

mangtas

mangtas

2013-04-11 03:25

reporter   ~0036570

Hi

I added the requested security check and created the pull request with the title >"New function added to retrieve bug history via API."

Hi, how can I get your latest patch? what's a pull request? where can i find it?

atrol

atrol

2013-04-11 03:54

developer   ~0036571

mangtas, have a look at https://github.com/mantisbt/mantisbt/pulls

Related Changesets

MantisBT: master-1.2.x f65336ce

2013-04-06 08:27:40

winston


Committer: rombert Details Diff
New function added to retrieve bug history via API.

Fixes 0009936: add history information

Signed-off-by: Laszlo Kovacs <winston01@freemail.hu>
Signed-off-by: Robert Munteanu <robert@lmn.ro>
mod - api/soap/mantisconnect.wsdl Diff File
mod - api/soap/mc_issue_api.php Diff File

MantisBT: master 4308b1f0

2013-04-06 08:27:40

winston


Committer: rombert Details Diff
New function added to retrieve bug history via API.

Fixes 0009936: add history information

Signed-off-by: Laszlo Kovacs <winston01@freemail.hu>
Signed-off-by: Robert Munteanu <robert@lmn.ro>
mod - api/soap/mantisconnect.wsdl Diff File
mod - api/soap/mc_issue_api.php Diff File

Issue History

Date Modified Username Field Change
2008-12-04 09:20 laurentb New Issue
2008-12-04 09:20 laurentb File Added: mc.zip
2009-10-06 03:40 vboctor Tag Attached: patch
2009-10-08 02:20 vboctor Status new => acknowledged
2011-12-13 02:31 vboctor Note Added: 0030562
2012-03-06 06:55 rombert Target Version => 1.3.0-beta.1
2012-06-07 20:32 wmatusiak File Added: ticket_0009936.patch
2012-06-07 20:33 wmatusiak Note Added: 0032043
2012-06-07 20:41 wmatusiak Note Edited: 0032043 View Revisions
2012-06-09 23:20 vboctor Note Added: 0032056
2012-06-09 23:21 vboctor Note Added: 0032057
2012-06-10 06:04 rombert Note Added: 0032058
2012-06-10 16:08 wmatusiak Note Added: 0032064
2012-06-11 06:24 rombert Note Added: 0032066
2012-10-16 09:30 rombert Relationship added has duplicate 0014833
2012-12-03 08:00 winston File Added: mantis_history_SOAP.patch
2012-12-03 08:03 winston Note Added: 0034450
2012-12-03 08:04 winston Note Edited: 0034450 View Revisions
2012-12-15 19:02 rombert Note Added: 0034546
2012-12-15 19:02 rombert Assigned To => rombert
2012-12-15 19:02 rombert Status acknowledged => assigned
2012-12-15 19:02 rombert Description Updated View Revisions
2013-04-06 08:46 winston Note Added: 0036527
2013-04-11 03:25 mangtas Note Added: 0036570
2013-04-11 03:54 atrol Note Added: 0036571
2013-04-19 11:35 dregad Note Edited: 0036527 View Revisions
2013-04-20 08:41 rombert Target Version 1.3.0-beta.1 => 1.2.16
2013-04-21 15:24 rombert Relationship added related to 0014943
2013-06-30 15:51 rombert Changeset attached => MantisBT master-1.2.x f65336ce
2013-06-30 15:51 rombert Status assigned => resolved
2013-06-30 15:51 rombert Resolution open => fixed
2013-06-30 15:51 rombert Fixed in Version => 1.2.16
2013-06-30 15:51 rombert Changeset attached => MantisBT master 4308b1f0
2014-02-07 18:24 dregad Status resolved => closed