Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b41fe48
Choose a base ref
...
head repository: mantisbt/mantisbt
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 505c060
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 5, 2011

  1. Declare TagData/TagDataArray types

    Affects #13446: Add tags support to soap api
    rombert committed Dec 5, 2011

    Verified

    This commit was signed with the committer’s verified signature.
    anthonyfok Anthony Fok
    Copy the full SHA
    1f2887a View commit details
  2. Implement mc_tag_get_all, mc_tag_add, mc_tag_delete

    Fixes #13446: Add tags support to soap api
    rombert committed Dec 5, 2011
    Copy the full SHA
    505c060 View commit details
Showing with 371 additions and 0 deletions.
  1. +96 −0 api/soap/mantisconnect.php
  2. +1 −0 api/soap/mc_core.php
  3. +117 −0 api/soap/mc_tag_api.php
  4. +2 −0 tests/soap/AllTests.php
  5. +16 −0 tests/soap/SoapBase.php
  6. +139 −0 tests/soap/TagTest.php
96 changes: 96 additions & 0 deletions api/soap/mantisconnect.php
Original file line number Diff line number Diff line change
@@ -553,6 +553,55 @@
'tns:CustomFieldValueForIssueData'
);


### TagData
$l_oServer->wsdl->addComplexType(
'TagData',
'complexType',
'struct',
'all',
'',
array(
'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0' ),
'user_id' => array( 'name' => 'user_id', 'type' => 'tns:AccountData', 'minOccurs' => '0' ),
'name' => array( 'name' => 'name', 'type' => 'xsd:string', 'minOccurs' => '0' ),
'description' => array( 'name' => 'description', 'type' => 'xsd:string', 'minOccurs' => '0' ),
'date_created' => array( 'name' => 'date_created', 'type' => 'xsd:dateTime', 'minOccurs' => '0' ),
'date_updated' => array( 'name' => 'date_updated', 'type' => 'xsd:dateTime', 'minOccurs' => '0' )
)
);

### TagDataArray
$l_oServer->wsdl->addComplexType(
'TagDataArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:TagData[]'
)
),
'tns:TagData'
);

### TagDataSearchResult
$l_oServer->wsdl->addComplexType(
'TagDataSearchResult',
'complexType',
'struct',
'all',
'',
array(
'results' => array( 'name' => 'results', 'type' => 'tns:TagDataArray', 'minOccurs' => '0' ),
'total_results' => array( 'name' => 'total_results', 'type' => 'xsd:integer', 'minOccurs' => '0' )
)
);



###
### PUBLIC METHODS
###
@@ -1462,6 +1511,53 @@
'Get the value for the specified user preference.'
);

###
### PUBLIC METHODS (defined in mc_tag_api.php)
###

$l_oServer->register( 'mc_tag_get_all',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'page_number' => 'xsd:integer',
'per_page' => 'xsd:integer'
),
array(
'return' => 'tns:TagDataSearchResult'
),
$t_namespace,
false, false, false,
'Gets all the tags.'
);

$l_oServer->register( 'mc_tag_add',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'tag' => 'tns:TagData'
),
array(
'return' => 'xsd:integer'
),
$t_namespace,
false, false, false,
'Creates a tag.'
);

$l_oServer->register( 'mc_tag_delete',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'tag_id' => 'xsd:integer'
),
array(
'return' => 'xsd:boolean'
),
$t_namespace,
false, false, false,
'Deletes a tag.'
);

###
### IMPLEMENTATION
###
1 change: 1 addition & 0 deletions api/soap/mc_core.php
Original file line number Diff line number Diff line change
@@ -41,3 +41,4 @@
require_once( $t_current_dir . 'mc_config_api.php' );
require_once( $t_current_dir . 'mc_custom_field_api.php' );
require_once( $t_current_dir . 'mc_user_pref_api.php' );
require_once( $t_current_dir . 'mc_tag_api.php' );
117 changes: 117 additions & 0 deletions api/soap/mc_tag_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?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/>.

/**
* Retrieves all tags, unless the users
*
* @param string $p_username The user's username
* @param string $p_password The user's password
* @param int $p_page_number The page number to return data for
* @param string $p_per_page The number of issues to return per page
* @return array The tag data
*/
function mc_tag_get_all( $p_username, $p_password, $p_page_number, $p_per_page) {
$t_user_id = mci_check_login( $p_username, $p_password );
if ( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

if ( !access_has_global_level( config_get( 'tag_view_threshold' ) ) )
return mci_soap_fault_access_denied( $t_user_id , 'No rights to view tags');

if ( $p_per_page == 0 )
$p_per_page = 1;

$t_results = array();
$t_total_results = tag_count( '' );

foreach ( tag_get_all('', $p_per_page, $p_per_page * ( $p_page_number - 1 ) ) as $t_tag_row ) {
$t_results[] = array (
'id' => $t_tag_row['id'],
'name' => $t_tag_row['name'],
'description' => $t_tag_row['description'],
'user_id' => mci_account_get_array_by_id ( $t_tag_row['user_id'] ),
'date_created' => timestamp_to_iso8601($t_tag_row['date_created'], false),
'date_updated' => timestamp_to_iso8601($t_tag_row['date_updated'], false)

);
}

return array(
'results' => $t_results,
'total_results' => $t_total_results
);
}

/**
* Creates a tag
*
* @param string $p_username The user's username
* @param string $p_password The user's password
* @param array $p_tag The tag to create
* @return soap_fault|integer
*/
function mc_tag_add( $p_username, $p_password, $p_tag ) {

$t_user_id = mci_check_login( $p_username, $p_password );

if ( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

if ( !access_has_global_level( config_get( 'tag_create_threshold' ) ) )
return mci_soap_fault_access_denied( $p_user_id );

$t_valid_matches = array();

$t_tag_name = $p_tag['name'];
$t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : '';

if ( !tag_name_is_valid($t_tag_name, $t_valid_matches))
return new soap_fault('client', '', 'Invalid tag name : "' . $t_tag_name .'"' );

$t_matching_by_name = tag_get_by_name( $t_tag_name);
if ( $t_matching_by_name != false )
return new soap_fault('client', '', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']);

return tag_create($t_tag_name, $t_user_id, $t_tag_description);
}

/**
*
* Deletes a tag
*
* @param string $p_username The user's username
* @param string $p_password The user's password * @param unknown_type $p_tag_id
* @param int $p_tag_id The id of the tag
* @return soap_fault|boolean
*/
function mc_tag_delete( $p_username, $p_password, $p_tag_id ) {

$t_user_id = mci_check_login( $p_username, $p_password );

if ( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

if ( !access_has_global_level( config_get( 'tag_edit_threshold' ) ) )
return mci_soap_fault_access_denied( $p_user_id );

if ( ! tag_exists( $p_tag_id ) )
return new soap_fault('Client', '', 'No tag with id ' . $p_tag_id);

return tag_delete( $p_tag_id );
}
2 changes: 2 additions & 0 deletions tests/soap/AllTests.php
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
require_once 'VersionTest.php';
require_once 'RelationshipTest.php';
require_once 'UserTest.php';
require_once 'TagTest.php';

/**
* @package Tests
@@ -77,6 +78,7 @@ public static function suite()
$suite->addTestSuite('VersionTest');
$suite->addTestSuite('RelationshipTest');
$suite->addTestSuite('UserTest');
$suite->addTestSuite('TagTest');

return $suite;
}
16 changes: 16 additions & 0 deletions tests/soap/SoapBase.php
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ class SoapBase extends PHPUnit_Framework_TestCase {
protected $mantisPath;
private $issueIdsToDelete = array();
private $versionIdsToDelete = array();
private $tagIdsToDelete = array();
private $defaultSoapClientOptions = array( 'trace' => true,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
@@ -81,6 +82,10 @@ protected function tearDown() {
$this->password,
$issueIdToDelete);
}

foreach ( $this->tagIdsToDelete as $tagIdToDelete ) {
$this->client->mc_tag_delete ( $this->userName, $this->password, $tagIdToDelete );
}
}

protected function getProjectId() {
@@ -128,6 +133,17 @@ protected function deleteVersionAfterRun( $versionId ) {

$this->versionIdsToDelete[] = $versionId;
}

/**
* Registers a tag for deletion after the test method has run
*
* @param int $tagId
* @return void
*/
protected function deleteTagAfterRun ( $tagId ) {

$this->tagIdsToDelete[] = $tagId;
}

protected function skipIfDueDateIsNotEnabled() {

Loading