Skip to content

Commit

Permalink
Implement removal of issue monitors on issue update
Browse files Browse the repository at this point in the history
Bug: 8558 ( SOAP API needs ability to Monitor a Task )
  • Loading branch information
rombert committed Feb 13, 2011
1 parent 1298228 commit fff800a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
35 changes: 31 additions & 4 deletions api/soap/mc_issue_api.php
Expand Up @@ -336,10 +336,14 @@ function mci_issue_get_notes( $p_issue_id ) {
*/
function mci_issue_set_monitors( $p_issue_id , $p_user_id, $p_monitors ) {

foreach ( $p_monitors as $t_monitor ) {

$t_user_id = $t_monitor['id'];
$t_existing_monitors = bug_get_monitors( $p_issue_id );

$t_monitors = array();
foreach ( $p_monitors as $t_monitor )
$t_monitors[] = $t_monitor['id'];

foreach ( $t_monitors as $t_user_id ) {

$t_has_access;

if ( $p_user_id == $t_user_id ) {
Expand All @@ -351,8 +355,31 @@ function mci_issue_set_monitors( $p_issue_id , $p_user_id, $p_monitors ) {
if ( !$t_has_access )
continue;

bug_monitor( $p_issue_id, $t_user_id );
if ( in_array( $p_user_id, $t_existing_monitors) )
continue;

bug_monitor( $p_issue_id, $t_user_id);
}

foreach ( $t_existing_monitors as $t_user_id ) {

$t_has_access;

if ( $p_user_id == $t_user_id ) {
$t_has_access = access_has_bug_level( config_get( 'monitor_bug_threshold' ), $p_issue_id );
} else {
$t_has_access = access_has_bug_level( config_get( 'monitor_remove_others_bug_threshold' ), $p_issue_id );
}

if ( !$t_has_access )
continue;

if ( in_array( $p_user_id, $t_monitors) )
continue;

bug_unmonitor( $p_issue_id, $t_user_id);
}

}

/**
Expand Down
40 changes: 38 additions & 2 deletions tests/soap/IssueMonitorTest.php
Expand Up @@ -63,7 +63,7 @@ public function testCreateIssueHasEmptyMonitorList() {
*/
public function testAddMonitorWhenCreatingAnIssue() {

$issueToAdd = $this->getIssueToAdd( 'IssueMonitorTest.testAddRemoveMonitorFromIssue' );
$issueToAdd = $this->getIssueToAdd( 'IssueMonitorTest.testAddMonitorWhenCreatingAnIssue' );
$issueToAdd['monitors'] = array(
array ('id' => $this->userId )
);
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testAddMonitorWhenCreatingAnIssue() {
*/
public function testAddMonitorToExistingIssue() {

$issueToAdd = $this->getIssueToAdd( 'IssueMonitorTest.testAddRemoveMonitorFromIssue' );
$issueToAdd = $this->getIssueToAdd( 'IssueMonitorTest.testAddMonitorToExistingIssue' );

$issueId = $this->client->mc_issue_add(
$this->userName,
Expand Down Expand Up @@ -127,4 +127,40 @@ public function testAddMonitorToExistingIssue() {
self::assertEquals( $this->userId, $monitor->id );
self::assertEquals( $this->userName, $monitor->name );
}

/**
* A test case that tests the following
*
* 1. Creates a new issue with a monitor
* 2. Retrieves the issue
* 3. Updates the monitor list to be empty
* 4. Retrieves the issue and verifies that the monitors list is empty
*/
public function testRemoveMonitor() {

$issueToAdd = $this->getIssueToAdd( 'IssueMonitorTest.testAddRemoveMonitorFromIssue' );
$issueToAdd['monitors'] = array(
array ('id' => $this->userId )
);

$issueId = $this->client->mc_issue_add(
$this->userName,
$this->password,
$issueToAdd);

$this->deleteAfterRun( $issueId );

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

$issue->monitors = array();

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

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

self::assertEquals(0, sizeof($issue->monitors));
}
}

0 comments on commit fff800a

Please sign in to comment.