View Issue Details

IDProjectCategoryView StatusLast Update
0011913mantisbtapi soappublic2010-12-17 04:37
Reporternerville Assigned Torombert  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.1 
Target Version1.2.3Fixed in Version1.2.3 
Summary0011913: [patch] Update project description, status, name of a specific project using SOAP API
Description

Please find as attachment a patch to add ability to update a project description of a specific project using SOAP API.

Currently, the SOAP API in 1.2.1 is not providing such functions.

My patch (git format) include PHPUnit tests.

TagsNo tags attached.
Attached Files
api.soap.feature.update.project.description.git.patch (8,536 bytes)   
From ed2f1070afbdead7b9b4dde3eb67eba8fd7b4106 Mon Sep 17 00:00:00 2001
From: Franck Villaume <franck.villaume@capgemini.com>
Date: Tue, 11 May 2010 15:50:28 +0200
Subject: [PATCH] SOAP API feature : add update project description of a specific project

---
 api/soap/mantisconnect.php  |   16 +++++++
 api/soap/mc_project_api.php |   78 ++++++++++++++++++++++++++++++++
 tests/soap/AllTests.php     |    2 +
 tests/soap/ProjectTest.php  |  103 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 199 insertions(+), 0 deletions(-)
 create mode 100644 tests/soap/ProjectTest.php

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index da61187..9b2a248 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -995,6 +995,22 @@ $l_oServer->register( 'mc_project_delete',
 	'Add a new project to the tracker (must have admin privileges)'
 );
 
+### mc_project_update
+$l_oServer->register( 'mc_project_update',
+        array(
+                'username' => 'xsd:string',
+                'password' => 'xsd:string',
+                'project_id' => 'xsd:integer',
+                'project' => 'tns:ProjectData'
+        ),
+        array(
+                'return' => 'xsd:integer'
+        ),
+        $t_namespace,
+        false, false, false,
+        'Update a specific project to the tracker (must have admin privileges)'
+);
+
 ### mc_project_get_issues
 $l_oServer->register( 'mc_project_get_issues',
 	array(
diff --git a/api/soap/mc_project_api.php b/api/soap/mc_project_api.php
index 11586d2..ba3867e 100644
--- a/api/soap/mc_project_api.php
+++ b/api/soap/mc_project_api.php
@@ -726,6 +726,84 @@ function mc_project_add( $p_username, $p_password, $p_project ) {
 }
 
 /**
+ * Update a project
+ *
+ * @param string $p_username  The name of the user
+ * @param string $p_password  The password of the user
+ * @param integer $p_project_id A project's id
+ * @param Array $p_project A new ProjectData structure
+ * @return bool returns true or false depending on the success of the update action
+ */
+function mc_project_update( $p_username, $p_password, $p_project_id, $p_project ) {
+        $t_user_id = mci_check_login( $p_username, $p_password );
+        if( $t_user_id === false ) {
+                return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect' );
+        }
+
+        if( !mci_has_administrator_access( $t_user_id, $p_project_id ) ) {
+                return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access' );
+        }
+
+        if ( !isset( $p_project['name'] ) ) {
+                return new soap_fault( 'Client', '', 'Missing Field', 'Required Field Missing' );
+        } else {
+                $t_name = $p_project['name'];
+        }
+
+        if ( !isset( $p_project['description'] ) ) {
+                $t_description = project_get_field( $p_project_id, 'description' );
+        } else {
+                $t_description = $p_project['description'];
+        }
+
+        if ( !isset( $p_project['status'] ) ) {
+                $t_status = array( 'name' => 'development' ); // development
+        } else {
+                $t_status = $p_project['status'];
+        }
+
+        if ( !isset( $p_project['view_state'] ) ) {
+                $t_view_state = array( 'id' => VS_PUBLIC );
+        } else {
+                $t_view_state = $p_project['view_state'];
+        }
+
+        if ( !isset( $p_project['file_path'] ) ) {
+                $t_file_path = '';
+        } else {
+                $t_file_path = $p_project['file_path'];
+        }
+
+        if ( !isset( $p_project['enabled'] ) ) {
+                $t_enabled = true;
+        } else {
+                $t_enabled = $p_project['enabled'];
+        }
+
+        if ( !isset( $p_project['inherit_global'] ) ) {
+                $t_inherit_global = true;
+        } else {
+                $t_inherit_global = $p_project['inherit_global'];
+        }
+
+        if( !project_exists( $p_project_id ) ) {
+                return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
+        }
+
+        // check to make sure project doesn't already exist
+        if ( $t_name != project_get_name( $p_project_id ) ) {
+                if( !project_is_name_unique( $t_name ) ) {
+                        return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' );
+                }
+        }
+
+        $t_project_status = mci_get_project_status_id( $t_status );
+        $t_project_view_state = mci_get_project_view_state_id( $t_view_state );
+
+        return project_update( $p_project_id, $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global );
+}
+
+/**
  * Delete a project.
  *
  * @param string $p_username  The name of the user trying to access the versions.
diff --git a/tests/soap/AllTests.php b/tests/soap/AllTests.php
index c248675..7cebd00 100644
--- a/tests/soap/AllTests.php
+++ b/tests/soap/AllTests.php
@@ -34,6 +34,7 @@ require_once 'FilterTest.php';
 require_once 'AttachmentTest.php';
 require_once 'LoginTest.php';
 require_once 'CategoryTest.php';
+require_once 'ProjectTest.php';
 
 /**
  * @package    Tests
@@ -65,6 +66,7 @@ class Soap_AllTests extends PHPUnit_Framework_TestSuite
         $suite->addTestSuite('AttachmentTest');
         $suite->addTestSuite('LoginTest');
         $suite->addTestSuite('CategoryTest');
+        $suite->addTestSuite('ProjectTest');
 
         return $suite;
     }
diff --git a/tests/soap/ProjectTest.php b/tests/soap/ProjectTest.php
new file mode 100644
index 0000000..af59cd7
--- /dev/null
+++ b/tests/soap/ProjectTest.php
@@ -0,0 +1,103 @@
+<?php
+# MantisBT - a php based bugtracking system
+
+# MantisBT is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# MantisBT is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package Tests
+ * @subpackage UnitTests
+ * @copyright Copyright (C) 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
+ * @link http://www.mantisbt.org
+ */
+
+require_once 'SoapBase.php';
+
+/**
+ * Test fixture for project webservice methods.
+ */
+class ProjectTest extends SoapBase {
+
+	private $projectIdToDelete = array();	
+
+	/**
+	 * A test case that tests the following:
+	 * 1. Create a project.
+	 * 2. Rename the project.
+	 * 3. Delete the project.
+	 */
+	public function testAddRenameDeleteProject() {
+		$projectName = $this->getOriginalNameProject();
+		$projectNewName = $this->getNewNameProject();
+
+		$projectDataStructure = array();
+		$projectDataStructure['name'] = $projectName;
+        	$projectDataStructure['status'] = "development";
+		$projectDataStructure['view_state'] = 10;
+
+		$projectId = $this->client->mc_project_add(
+			$this->userName,
+			$this->password,
+			$projectDataStructure);
+
+		$this->projectIdToDelete[] = $projectId;
+			
+		$projectArray = mc_project_as_array_by_id(
+			$this->userName,
+			$this->password,
+			$projectId);
+
+		$this->assertContains($projectName, $projectArray);
+		
+		$projectDataStructure['name'] = $projectNewName;
+
+		$return_bool = $this->client->mc_project_update(
+			$this->userName,
+			$this->password,
+			$projectId,
+			$projectDataStructure);
+
+		$projectArray = mc_project_as_array_by_id(
+			$this->userName,
+			$this->password,
+			$projectId);
+
+		$this->assertContains($projectNewName, $projectArray);
+
+		$return_bool = $this->client->mc_project_delete (
+			$this->userName,
+			$this->password,
+			$projectId);
+	}
+
+	protected function tearDown() {
+
+		parent::tearDown();
+
+		foreach ( $this->projectIdToDelete as $projectId )  {
+			$this->client->mc_project_delete(
+				$this->userName,
+				$this->password,
+				$projectId);
+		}
+	}
+    
+	private function getOriginalNameProject() {
+ 		return 'my_project_name';
+	}
+    
+	private function getNewNameProject() {
+ 		return 'my_new_project_name';
+	}
+ 
+}
-- 
1.6.4.4

Activities

dhx

dhx

2010-05-11 10:06

reporter   ~0025467

Robert, is this suitable for 1.2.2? I would assume so as we seem to be happy adding plugin hooks upon request so that people can develop better plugins against the 1.2.x branch.

rombert

rombert

2010-05-11 13:44

reporter   ~0025475

This is suitable for 1.2.2 as it is an addition, and breaks no existing behaviour . I'll review the patch but since we already have a successful submission from nerville I expect no problems.

rombert

rombert

2010-05-17 18:12

reporter   ~0025524

Some comments, regarding implementation only:

  1. Why does the method return the project id? It's passed in as a parameter anyway.
  2. Please move the unique name check higher up in the method.
  3. Are you sure it's a good idea to reset values to defaults if not provided? I would suggest either reading the existing data from the database and updating only when a value is passed in or simply requiring all the fields to be filled in.
nerville

nerville

2010-05-21 11:44

reporter   ~0025578

Hi,
Nice catch.
I will submit a new patch as soon as possible... I'm in vacation :-)

rombert

rombert

2010-05-21 11:45

reporter   ~0025579

Sure thing, enjoy your vacation :-)

nerville

nerville

2010-06-03 05:04

reporter   ~0025671

Please dont use the patch2 file....... it's a mistake.

nerville

nerville

2010-06-03 05:08

reporter   ~0025672

Back from vacation, I updated my patch following your advice.

Answer to 1: returns value is bool as project_update returns bool
Answer to 2: done
Answer to 3: done

The right patch is the patch3 file.
Sorry for the wrong previous upload.

nerville

nerville

2010-07-21 11:41

reporter   ~0026113

Any update on this topic ?

rombert

rombert

2010-07-21 16:54

reporter   ~0026114

Sorry, I know it's been a long time since you posted the patch, but I'm out of time right now. I hope to take a look at it during the next month.

rombert

rombert

2010-08-16 17:19

reporter   ~0026339

Looks good, but when I run the unit tests I get

PHP Fatal error:  Call to undefined function mc_project_as_array_by_id() in /home/robert/public_html/mantisbt/tests/soap/ProjectTest.php on line 55

I suggest you stay away from 'internal' methods and use your own to-array conversion, if needed.

nerville

nerville

2010-08-17 03:29

reporter   ~0026342

Hi,
my mistake.
Small fix include in patch4 :


tests/soap/ProjectTest.php | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/soap/ProjectTest.php b/tests/soap/ProjectTest.php
index c7447de..1b4f00c 100644
--- a/tests/soap/ProjectTest.php
+++ b/tests/soap/ProjectTest.php
@@ -52,7 +52,7 @@ class ProjectTest extends SoapBase {

            $this->projectIdToDelete[] = $projectId;
  • $projectArray = mc_project_as_array_by_id(

  • $projectArray = $this->client->mc_project_as_array_by_id(
    $this->userName,
    $this->password,
    $projectId);
    @@ -67,7 +67,7 @@ class ProjectTest extends SoapBase {
    $projectId,
    $projectDataStructure);

  • $projectArray = mc_project_as_array_by_id(

  • $projectArray = $this->client->mc_project_as_array_by_id(
    $this->userName,
    $this->password,
    $projectId);
    @@ -101,4 +101,3 @@ class ProjectTest extends SoapBase {
    }

    }

rombert

rombert

2010-08-17 18:00

reporter   ~0026345

Now I get

<code>There was 1 error:

1) ProjectTest::testAddRenameDeleteProject
SoapFault: Function ("mc_project_as_array_by_id") is not a valid method for this service

/home/robert/public_html/mantisbt/tests/soap/ProjectTest.php:58</code>

If there's anything I can assist you with in running the SOAP tests cases, please let me know.

nerville

nerville

2010-08-18 12:05

reporter   ~0026352

Ok I got the error.
The main problem here is that I didn't add in my patch the mc_project_as_array_by_id function.

This function is based on mci_project_as_array_by_id

Please find new attachment.
Any advice on this specific topic is welcome.

rombert

rombert

2010-08-18 17:53

reporter   ~0026363

Rather than adding a new SOAP function just for a unit test, couldn't you invoke mc_projects_get_user_accessible and filter the result by the already known project id?

nerville

nerville

2010-08-23 05:36

reporter   ~0026411

I followed your advice.
Hope it works. I'm running into troubles to use soap extension here.

rombert

rombert

2010-09-08 17:45

reporter   ~0026635

Thanks!

Finally got around to applying this. Some fixes where needed for the tests, but otherwise we're fine.

If you need help running the soap tests - as I think coding in the blind is quite hard - please read http://www.mantisforge.org/dev/manual/master/en/developers.html#DEV.CONTRIB.TEST and ask on the mailing list for the clarifications. I'd be happy to assist you with setting up a testing environment, as I welcome your contributions to the SOAP API.

Related Changesets

MantisBT: master 25e8a533

2010-06-03 04:59

nerville

Committer: rombert


Details Diff
Update project description, status, name of a specific project using SOAP API

Fixes 0011913

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
Affected Issues
0011913
mod - tests/soap/AllTests.php Diff File
add - tests/soap/ProjectTest.php Diff File
mod - api/soap/mantisconnect.php Diff File
mod - api/soap/mc_project_api.php Diff File

MantisBT: master-1.2.x da9a8eff

2010-06-03 04:59

nerville

Committer: rombert


Details Diff
Update project description, status, name of a specific project using SOAP API

Fixes 0011913

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
Affected Issues
0011913
mod - api/soap/mc_project_api.php Diff File
add - tests/soap/ProjectTest.php Diff File
mod - api/soap/mantisconnect.php Diff File
mod - tests/soap/AllTests.php Diff File