Skip to content

Commit

Permalink
SOAP API: tag fixes
Browse files Browse the repository at this point in the history
- add mc_issue_set_tags
- use proper access checks when attaching and detaching tags

Fixes #13446: Add tags support to soap api
  • Loading branch information
rombert committed Dec 5, 2011
1 parent 0a8bbbd commit c9c1398
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
16 changes: 16 additions & 0 deletions api/soap/mantisconnect.php
Expand Up @@ -895,6 +895,22 @@
'Update Issue method.'
);

$l_oServer->register( 'mc_issue_set_tags',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'issue_id' => 'xsd:integer',
'tags' => 'tns:TagDataArray'
),
array(
'return' => 'xsd:boolean'
),
$t_namespace,
false, false, false,
'Sets the tags for a specified issue.'
);


### mc_issue_delete
$l_oServer->register( 'mc_issue_delete',
array(
Expand Down
28 changes: 25 additions & 3 deletions api/soap/mc_issue_api.php
Expand Up @@ -673,7 +673,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
}

if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'] );
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'], $t_user_id );
}

email_new_bug( $t_issue_id );
Expand Down Expand Up @@ -880,13 +880,35 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
}

if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] );
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] , $t_user_id );
}

# submit the issue
return $t_is_success = $t_bug_data->update( /* update_extended */ true, /* bypass_email */ false);
}

function mc_issue_set_tags ( $p_username, $p_password, $p_issue_id, $p_tags ) {

$t_user_id = mci_check_login( $p_username, $p_password );
if( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

if( !bug_exists( $p_issue_id ) ) {
return new soap_fault( 'Client', '', "Issue '$p_issue_id' does not exist." );
}

$t_project_id = bug_get_field( $p_issue_id, 'project_id' );

if( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
return mci_soap_fault_access_denied( $t_user_id );
}

mci_tag_set_for_issue( $p_issue_id, $p_tags, $t_user_id );

return true;
}

/**
* Delete the specified issue.
*
Expand Down Expand Up @@ -1332,4 +1354,4 @@ function mci_issue_get_tags_for_bug_id( $p_bug_id, $p_user_id ) {
}

return $t_result;
}
}
16 changes: 11 additions & 5 deletions api/soap/mc_tag_api.php
Expand Up @@ -116,7 +116,7 @@ function mc_tag_delete( $p_username, $p_password, $p_tag_id ) {
return tag_delete( $p_tag_id );
}

function mci_tag_set_for_issue ( $p_issue_id, $p_tags ) {
function mci_tag_set_for_issue ( $p_issue_id, $p_tags, $p_user_id ) {

$t_tag_ids_to_attach = array();
$t_tag_ids_to_detach = array();
Expand Down Expand Up @@ -147,9 +147,15 @@ function mci_tag_set_for_issue ( $p_issue_id, $p_tags ) {
}
}

foreach ( $t_tag_ids_to_detach as $t_tag_id )
tag_bug_detach( $t_tag_id, $p_issue_id, true);
foreach ( $t_tag_ids_to_detach as $t_tag_id ) {
if ( access_has_bug_level ( config_get('tag_detach_threshold'), $p_issue_id, $p_user_id ) ) {
tag_bug_detach( $t_tag_id, $p_issue_id, true);
}
}

foreach ( $t_tag_ids_to_attach as $t_tag_id )
tag_bug_attach( $t_tag_id, $p_issue_id, true);
foreach ( $t_tag_ids_to_attach as $t_tag_id ) {
if ( access_has_bug_level ( config_get('tag_attach_threshold'), $p_issue_id, $p_user_id ) ) {
tag_bug_attach( $t_tag_id, $p_issue_id, true);
}
}
}
26 changes: 25 additions & 1 deletion tests/soap/TagTest.php
Expand Up @@ -132,8 +132,32 @@ public function testCreateTagWithExistingName() {
$this->client->mc_tag_add ( $this->userName, $this->password, $tagToCreate );
self::fail("Expected an error");
} catch ( SoapFault $e ) {
echo 'Testing';
$this->assertContains( "A tag with the same name already exists", $e->getMessage() );
}
}

/**
* Tests that setting tags on issues works
*/
public function testSetTagsOnIssue() {

// create tag
$tagToCreate = array (
'name' => 'TagTest.testCreateTagWithExistingName'
);
$tagId = $this->client->mc_tag_add ( $this->userName, $this->password, $tagToCreate );
$this->deleteTagAfterRun( $tagId );

// create issue
$issueToCreate = $this->getIssueToAdd('testTestTagsOnIssue');
$issueId = $this->client->mc_issue_add ( $this->userName, $this->password, $issueToCreate );
$this->deleteAfterRun( $issueId );

// set tags
$this->client->mc_issue_set_tags ( $this->userName, $this->password, $issueId, array ( array ( 'id' => $tagId ) ) );

$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );

self::assertEquals( 1, count ( $issue->tags ) );
}
}

0 comments on commit c9c1398

Please sign in to comment.