Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9c1398

Browse files
committedDec 5, 2011
SOAP API: tag fixes
- add mc_issue_set_tags - use proper access checks when attaching and detaching tags Fixes #13446: Add tags support to soap api
1 parent 0a8bbbd commit c9c1398

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed
 

‎api/soap/mantisconnect.php

+16
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,22 @@
895895
'Update Issue method.'
896896
);
897897

898+
$l_oServer->register( 'mc_issue_set_tags',
899+
array(
900+
'username' => 'xsd:string',
901+
'password' => 'xsd:string',
902+
'issue_id' => 'xsd:integer',
903+
'tags' => 'tns:TagDataArray'
904+
),
905+
array(
906+
'return' => 'xsd:boolean'
907+
),
908+
$t_namespace,
909+
false, false, false,
910+
'Sets the tags for a specified issue.'
911+
);
912+
913+
898914
### mc_issue_delete
899915
$l_oServer->register( 'mc_issue_delete',
900916
array(

‎api/soap/mc_issue_api.php

+25-3
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
673673
}
674674

675675
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
676-
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'] );
676+
mci_tag_set_for_issue( $t_issue_id, $p_issue['tags'], $t_user_id );
677677
}
678678

679679
email_new_bug( $t_issue_id );
@@ -880,13 +880,35 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
880880
}
881881

882882
if ( isset ( $p_issue['tags']) && is_array ( $p_issue['tags']) ) {
883-
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] );
883+
mci_tag_set_for_issue( $p_issue_id, $p_issue['tags'] , $t_user_id );
884884
}
885885

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

890+
function mc_issue_set_tags ( $p_username, $p_password, $p_issue_id, $p_tags ) {
891+
892+
$t_user_id = mci_check_login( $p_username, $p_password );
893+
if( $t_user_id === false ) {
894+
return mci_soap_fault_login_failed();
895+
}
896+
897+
if( !bug_exists( $p_issue_id ) ) {
898+
return new soap_fault( 'Client', '', "Issue '$p_issue_id' does not exist." );
899+
}
900+
901+
$t_project_id = bug_get_field( $p_issue_id, 'project_id' );
902+
903+
if( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
904+
return mci_soap_fault_access_denied( $t_user_id );
905+
}
906+
907+
mci_tag_set_for_issue( $p_issue_id, $p_tags, $t_user_id );
908+
909+
return true;
910+
}
911+
890912
/**
891913
* Delete the specified issue.
892914
*
@@ -1332,4 +1354,4 @@ function mci_issue_get_tags_for_bug_id( $p_bug_id, $p_user_id ) {
13321354
}
13331355

13341356
return $t_result;
1335-
}
1357+
}

‎api/soap/mc_tag_api.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function mc_tag_delete( $p_username, $p_password, $p_tag_id ) {
116116
return tag_delete( $p_tag_id );
117117
}
118118

119-
function mci_tag_set_for_issue ( $p_issue_id, $p_tags ) {
119+
function mci_tag_set_for_issue ( $p_issue_id, $p_tags, $p_user_id ) {
120120

121121
$t_tag_ids_to_attach = array();
122122
$t_tag_ids_to_detach = array();
@@ -147,9 +147,15 @@ function mci_tag_set_for_issue ( $p_issue_id, $p_tags ) {
147147
}
148148
}
149149

150-
foreach ( $t_tag_ids_to_detach as $t_tag_id )
151-
tag_bug_detach( $t_tag_id, $p_issue_id, true);
150+
foreach ( $t_tag_ids_to_detach as $t_tag_id ) {
151+
if ( access_has_bug_level ( config_get('tag_detach_threshold'), $p_issue_id, $p_user_id ) ) {
152+
tag_bug_detach( $t_tag_id, $p_issue_id, true);
153+
}
154+
}
152155

153-
foreach ( $t_tag_ids_to_attach as $t_tag_id )
154-
tag_bug_attach( $t_tag_id, $p_issue_id, true);
156+
foreach ( $t_tag_ids_to_attach as $t_tag_id ) {
157+
if ( access_has_bug_level ( config_get('tag_attach_threshold'), $p_issue_id, $p_user_id ) ) {
158+
tag_bug_attach( $t_tag_id, $p_issue_id, true);
159+
}
160+
}
155161
}

‎tests/soap/TagTest.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,32 @@ public function testCreateTagWithExistingName() {
132132
$this->client->mc_tag_add ( $this->userName, $this->password, $tagToCreate );
133133
self::fail("Expected an error");
134134
} catch ( SoapFault $e ) {
135-
echo 'Testing';
136135
$this->assertContains( "A tag with the same name already exists", $e->getMessage() );
137136
}
138137
}
138+
139+
/**
140+
* Tests that setting tags on issues works
141+
*/
142+
public function testSetTagsOnIssue() {
143+
144+
// create tag
145+
$tagToCreate = array (
146+
'name' => 'TagTest.testCreateTagWithExistingName'
147+
);
148+
$tagId = $this->client->mc_tag_add ( $this->userName, $this->password, $tagToCreate );
149+
$this->deleteTagAfterRun( $tagId );
150+
151+
// create issue
152+
$issueToCreate = $this->getIssueToAdd('testTestTagsOnIssue');
153+
$issueId = $this->client->mc_issue_add ( $this->userName, $this->password, $issueToCreate );
154+
$this->deleteAfterRun( $issueId );
155+
156+
// set tags
157+
$this->client->mc_issue_set_tags ( $this->userName, $this->password, $issueId, array ( array ( 'id' => $tagId ) ) );
158+
159+
$issue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
160+
161+
self::assertEquals( 1, count ( $issue->tags ) );
162+
}
139163
}

0 commit comments

Comments
 (0)
Please sign in to comment.