Skip to content

Commit

Permalink
SOAP API: Return an empty result when the page is outside the filter
Browse files Browse the repository at this point in the history
Rather than return the last page when an out of bounds page is
requested, return no issues. This allows clients to find out when
there are no more issues for a specific filter.

Fixes #12991 : mc_filter_get_issues returns incorrect results for page_number > page_count
  • Loading branch information
rombert committed May 19, 2011
1 parent a744e69 commit c70ff52
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api/soap/mc_filter_api.php
Expand Up @@ -58,6 +58,7 @@ function mc_filter_get_issues( $p_username, $p_password, $p_project_id, $p_filte
return mci_soap_fault_access_denied( $t_user_id );
}

$t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
$t_page_count = 0;
$t_bug_count = 0;
$t_filter = filter_db_get_filter( $p_filter_id );
Expand All @@ -71,6 +72,10 @@ function mc_filter_get_issues( $p_username, $p_password, $p_project_id, $p_filte
$t_result = array();
$t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter, $p_project_id );

// the page number was moved back, so we have exceeded the actual page number, see bug #12991
if ( $t_orig_page_number > $p_page_number )
return $t_result;

foreach( $t_rows as $t_issue_data ) {
$t_result[] = mci_issue_data_as_array( $t_issue_data, $t_user_id, $t_lang );
}
Expand All @@ -97,6 +102,7 @@ function mc_filter_get_issue_headers( $p_username, $p_password, $p_project_id, $
return mci_soap_fault_access_denied( $t_user_id );
}

$t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
$t_page_count = 0;
$t_bug_count = 0;
$t_filter = filter_db_get_filter( $p_filter_id );
Expand All @@ -110,6 +116,10 @@ function mc_filter_get_issue_headers( $p_username, $p_password, $p_project_id, $
$t_result = array();
$t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter, $p_project_id );

// the page number was moved back, so we have exceeded the actual page number, see bug #12991
if ( $t_orig_page_number > $p_page_number )
return $t_result;

foreach( $t_rows as $t_issue_data ) {
$t_id = $t_issue_data->id;

Expand Down
13 changes: 12 additions & 1 deletion api/soap/mc_project_api.php
Expand Up @@ -22,11 +22,17 @@ function mc_project_get_issues( $p_username, $p_password, $p_project_id, $p_page
return mci_soap_fault_access_denied( $t_user_id );
}

$t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
$t_page_count = 0;
$t_bug_count = 0;

$t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );

$t_result = array();

// the page number was moved back, so we have exceeded the actual page number, see bug #12991
if ( $t_orig_page_number > $p_page_number )
return $t_result;

foreach( $t_rows as $t_issue_data ) {
$t_result[] = mci_issue_data_as_array( $t_issue_data, $t_user_id, $t_lang );
Expand Down Expand Up @@ -855,12 +861,17 @@ function mc_project_get_issue_headers( $p_username, $p_password, $p_project_id,
if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
return mci_soap_fault_access_denied( $t_user_id );
}


$t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
$t_page_count = 0;
$t_bug_count = 0;

$t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );
$t_result = array();

// the page number was moved back, so we have exceeded the actual page number, see bug #12991
if ( $t_orig_page_number > $p_page_number )
return $t_result;

foreach( $t_rows as $t_issue_data ) {
$t_id = $t_issue_data->id;
Expand Down
27 changes: 27 additions & 0 deletions tests/soap/FilterTest.php
Expand Up @@ -182,6 +182,33 @@ public function testGetProjectIssuesWithoutCategory() {

$this->assertEquals( $issueId, $projectIssues[0]->id, "id" );
}

/**
* Verifies that after the last page no more issues are being returned
*/
public function testGetIssueHeadersPaged() {

$issue = $this->getIssueToAdd('FilterTest.getIssueHeadersPaged');
$issueId = $this->client->mc_issue_add($this->userName, $this->password, $issue);
$this->deleteAfterRun($issueId);

self::assertEquals(1, count($this->client->mc_project_get_issue_headers($this->userName, $this->password, $this->getProjectId(),1, 1 )));
self::assertEquals(0, count($this->client->mc_project_get_issue_headers($this->userName, $this->password, $this->getProjectId(),2, 1 )));
}

/**
* Verifies that after the last page no more issues are being returned
*/
public function testGetIssuesPaged() {

$issue = $this->getIssueToAdd('FilterTest.getIssuesPaged');
$issueId = $this->client->mc_issue_add($this->userName, $this->password, $issue);
$this->deleteAfterRun($issueId);

self::assertEquals(1, count($this->client->mc_project_get_issues($this->userName, $this->password, $this->getProjectId(),1, 1 )));
self::assertEquals(0, count($this->client->mc_project_get_issues($this->userName, $this->password, $this->getProjectId(),2, 1 )));
}


/**
*
Expand Down

0 comments on commit c70ff52

Please sign in to comment.