View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0011913 | mantisbt | api soap | public | 2010-05-11 09:50 | 2010-12-17 04:37 |
| Reporter | nerville | Assigned To | rombert | ||
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 1.2.1 | ||||
| Target Version | 1.2.3 | Fixed in Version | 1.2.3 | ||
| Summary | 0011913: [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. | ||||
| Tags | No 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
| ||||
|
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. |
|
|
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. |
|
|
Some comments, regarding implementation only:
|
|
|
Hi, |
|
|
Sure thing, enjoy your vacation :-) |
|
|
Please dont use the patch2 file....... it's a mistake. |
|
|
Back from vacation, I updated my patch following your advice. Answer to 1: returns value is bool as project_update returns bool The right patch is the patch3 file. |
|
|
Any update on this topic ? |
|
|
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. |
|
|
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. |
|
|
Hi, tests/soap/ProjectTest.php | 5 ++--- diff --git a/tests/soap/ProjectTest.php b/tests/soap/ProjectTest.php
|
|
|
Now I get <code>There was 1 error: 1) ProjectTest::testAddRenameDeleteProject /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. |
|
|
Ok I got the error. This function is based on mci_project_as_array_by_id Please find new attachment. |
|
|
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? |
|
|
I followed your advice. |
|
|
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. |
|
|
MantisBT: master 25e8a533 2010-06-03 04:59 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 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 | ||