Skip to content

Commit

Permalink
Implement mc_tag_get_all, mc_tag_add, mc_tag_delete
Browse files Browse the repository at this point in the history
Fixes #13446: Add tags support to soap api
  • Loading branch information
rombert committed Dec 5, 2011
1 parent 23ef296 commit 9a1a1c4
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 0 deletions.
93 changes: 93 additions & 0 deletions api/soap/mantisconnect.php
Expand Up @@ -553,6 +553,52 @@
'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
###
Expand Down Expand Up @@ -1479,6 +1525,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
###
Expand Down
1 change: 1 addition & 0 deletions api/soap/mc_core.php
Expand Up @@ -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
@@ -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 );

This comment has been minimized.

Copy link
@atrol

atrol Dec 5, 2011

Member

Should be $t_user_id

This comment has been minimized.

Copy link
@rombert

rombert Dec 5, 2011

Author Member

Will fix , thanks.

This comment has been minimized.

Copy link
@atrol

atrol Dec 5, 2011

Member

I saw that you fixed the other one in mc_tag_delete.
Maybe you forgot this one?

This comment has been minimized.

Copy link
@rombert

rombert via email Dec 5, 2011

Author Member

This comment has been minimized.

Copy link
@atrol

atrol Dec 5, 2011

Member

Still not fixed in master :-)

This comment has been minimized.

Copy link
@rombert

rombert Dec 5, 2011

Author Member

Third time's a charm :-) Hopefully fixed


$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 );

This comment has been minimized.

Copy link
@atrol

atrol Dec 5, 2011

Member

Should be $t_user_id

This comment has been minimized.

Copy link
@rombert

rombert Dec 5, 2011

Author Member

Thanks, I'll fix this.


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
Expand Up @@ -40,6 +40,7 @@
require_once 'VersionTest.php';
require_once 'RelationshipTest.php';
require_once 'UserTest.php';
require_once 'TagTest.php';

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

return $suite;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/soap/SoapBase.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {

Expand Down

0 comments on commit 9a1a1c4

Please sign in to comment.