Permalink
Browse files

Update project description, status, name of a specific project using …

…SOAP API

Fixes #11913

Signed-off-by: Robert Munteanu <robert.munteanu@gmail.com>
  • Loading branch information...
1 parent 34cdf3b commit 25e8a5333aa673827e541f1ffbf8a20435e49234 Franck Villaume committed with rombert Jun 3, 2010
Showing with 200 additions and 0 deletions.
  1. +16 −0 api/soap/mantisconnect.php
  2. +79 −0 api/soap/mc_project_api.php
  3. +2 −0 tests/soap/AllTests.php
  4. +103 −0 tests/soap/ProjectTest.php
View
@@ -1001,6 +1001,22 @@
'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:boolean'
+ ),
+ $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(
@@ -653,6 +653,7 @@ function mci_project_as_array_by_id( $p_project_id ) {
}
### MantisConnect Administrative Webservices ###
+
/**
* Add a new project.
*
@@ -726,6 +727,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( !project_exists( $p_project_id ) ) {
+ return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
+ }
+
+ if ( !isset( $p_project['name'] ) ) {
+ return new soap_fault( 'Client', '', 'Missing Field', 'Required Field Missing' );
+ } else {
+ $t_name = $p_project['name'];
+ }
+
+ // 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' );
+ }
+ }
+
+ 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 = project_get_field( $p_project_id, 'status' );
+ } else {
+ $t_status = $p_project['status'];
+ }
+
+ if ( !isset( $p_project['view_state'] ) ) {
+ $t_view_state = project_get_field( $p_project_id, 'view_state' );
+ } else {
+ $t_view_state = $p_project['view_state'];
+ }
+
+ if ( !isset( $p_project['file_path'] ) ) {
+ $t_file_path = project_get_field( $p_project_id, 'file_path' );
+ } else {
+ $t_file_path = $p_project['file_path'];
+ }
+
+ if ( !isset( $p_project['enabled'] ) ) {
+ $t_enabled = project_get_field( $p_project_id, 'enabled' );
+ } else {
+ $t_enabled = $p_project['enabled'];
+ }
+
+ if ( !isset( $p_project['inherit_global'] ) ) {
+ $t_inherit_global = project_get_field( $p_project_id, 'inherit_global' );
+ } else {
+ $t_inherit_global = $p_project['inherit_global'];
+ }
+
+ $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.
View
@@ -35,6 +35,7 @@
require_once 'LoginTest.php';
require_once 'CategoryTest.php';
require_once 'CompressionTest.php';
+require_once 'ProjectTest.php';
/**
* @package Tests
@@ -67,6 +68,7 @@ public static function suite()
$suite->addTestSuite('LoginTest');
$suite->addTestSuite('CategoryTest');
$suite->addTestSuite('CompressionTest');
+ $suite->addTestSuite('ProjectTest');
return $suite;
}
View
@@ -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.
+ */
+ 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;
+
+ $projectsArray = $this->client->mc_projects_get_user_accessible(
+ $this->userName,
+ $this->password);
+
+ foreach ( $projectsArray as $project ) {
+ if ( $project->id == $projectId ) {
+ $this->assertEquals($projectName, $project->name);
+ }
+ }
+
+ $projectDataStructure['name'] = $projectNewName;
+
+ $return_bool = $this->client->mc_project_update(
+ $this->userName,
+ $this->password,
+ $projectId,
+ $projectDataStructure);
+
+ $projectsArray = $this->client->mc_projects_get_user_accessible(
+ $this->userName,
+ $this->password);
+
+ foreach ( $projectsArray as $project ) {
+ if ( $project->id == $projectId ) {
+ $this->assertEquals($projectNewName, $project->name);
+ }
+ }
+ }
+
+ 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';
+ }
+
+}

0 comments on commit 25e8a53

Please sign in to comment.