Navigation Menu

Skip to content

Commit

Permalink
Support getting a single project in REST API
Browse files Browse the repository at this point in the history
Fixes #24333
  • Loading branch information
vboctor committed Apr 28, 2018
1 parent a96bf27 commit 7fbb1d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion api/rest/restcore/projects_rest.php
Expand Up @@ -25,6 +25,8 @@
$g_app->group('/projects', function() use ( $g_app ) {
$g_app->get( '', 'rest_projects_get' );
$g_app->get( '/', 'rest_projects_get' );
$g_app->get( '/{id}', 'rest_projects_get' );
$g_app->get( '/{id}/', 'rest_projects_get' );
});

/**
Expand All @@ -36,10 +38,17 @@
* @return \Slim\Http\Response The augmented response.
*/
function rest_projects_get( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_project_id = isset( $p_args['id'] ) ? $p_args['id'] : $p_request->getParam( 'id' );
if( is_blank( $t_project_id ) ) {
$t_project_id = ALL_PROJECTS;
} else {
$t_project_id = (int)$t_project_id;
}

$t_user_id = auth_get_current_user_id();
$t_lang = mci_get_user_lang( $t_user_id );

$t_project_ids = user_get_all_accessible_projects( $t_user_id, /* disabled */ false );
$t_project_ids = user_get_all_accessible_projects( $t_user_id, $t_project_id );
$t_projects = array();

foreach( $t_project_ids as $t_project_id ) {
Expand Down
9 changes: 5 additions & 4 deletions core/project_api.php
Expand Up @@ -60,6 +60,8 @@
$g_cache_project_missing = array();
$g_cache_project_all = false;

use Mantis\Exceptions\ClientException;

/**
* Checks if there are no projects defined.
* @return boolean true if there are no projects defined, false otherwise.
Expand Down Expand Up @@ -110,11 +112,10 @@ function project_cache_row( $p_project_id, $p_trigger_errors = true ) {
$g_cache_project_missing[(int)$p_project_id] = true;

if( $p_trigger_errors ) {
error_parameters( $p_project_id );
trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
} else {
return false;
throw new ClientException( "Project #$p_project_id not found", ERROR_PROJECT_NOT_FOUND, array( $p_project_id ) );
}

return false;
}

$t_row = db_fetch_array( $t_result );
Expand Down

0 comments on commit 7fbb1d2

Please sign in to comment.