Skip to content

Commit

Permalink
Apply PR review comments
Browse files Browse the repository at this point in the history
1. Remove redundant check.
2. Refactor functions that get project users to use helper function.
3. Fix warnings when user preference for language is set to auto.

Fixes #30908
  • Loading branch information
vboctor committed Aug 24, 2022
1 parent bf4415f commit 15647bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
61 changes: 25 additions & 36 deletions api/rest/restcore/projects_rest.php
Expand Up @@ -61,26 +61,27 @@
});

/**
* A method to get list of users with the specified access level in the specified project.
* A helper function to get project users with the specified access level or above.
* The function will extract the parameters from the request and args.
*
* @param \Slim\Http\Request $p_request The request.
* @param \Slim\Http\Response $p_response The response.
* @param array $p_args Arguments
* @param int $p_access_level access level to use or null to extract from request.
* @return \Slim\Http\Response The augmented response.
*/
function rest_project_users(\Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_project_id = $p_args['id'];
if( is_blank( $t_project_id ) ) {
$t_message = "Project id is missing.";
return $p_response->withStatus( HTTP_STATUS_BAD_REQUEST, $t_message );
}

$t_project_id = (int)$t_project_id;
function project_users( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args, $p_access_level = null ) {
$t_project_id = (int)$p_args['id'];
$t_page_size = $p_request->getParam( 'page_size' );
$t_page = $p_request->getParam( 'page' );
$t_access_level = $p_request->getParam( 'access_level' );
$t_include_access_levels = $p_request->getParam( 'include_access_levels' );

if( is_null( $p_access_level ) ) {
$t_access_level = (int)$p_request->getParam( 'access_level' );
} else {
$t_access_level = (int)$p_access_level;
}

$t_data = array(
'query' => array(
'id' => $t_project_id,
Expand All @@ -97,6 +98,18 @@ function rest_project_users(\Slim\Http\Request $p_request, \Slim\Http\Response $
return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
}

/**
* A method to get list of users with the specified access level in the specified project.
*
* @param \Slim\Http\Request $p_request The request.
* @param \Slim\Http\Response $p_response The response.
* @param array $p_args Arguments
* @return \Slim\Http\Response The augmented response.
*/
function rest_project_users( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
return project_users( $p_request, $p_response, $p_args );
}

/**
* A method to get list of users with the handler access level in the specified project.
*
Expand All @@ -106,33 +119,9 @@ function rest_project_users(\Slim\Http\Request $p_request, \Slim\Http\Response $
* @return \Slim\Http\Response The augmented response.
*/
function rest_project_handlers(\Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_project_id = $p_args['id'];
if( is_blank( $t_project_id ) ) {
$t_message = "Project id is missing.";
return $p_response->withStatus( HTTP_STATUS_BAD_REQUEST, $t_message );
}

$t_project_id = (int)$t_project_id;
$t_page_size = $p_request->getParam( 'page_size' );
$t_page = $p_request->getParam( 'page' );
$t_include_access_levels = $p_request->getParam( 'include_access_levels' );

$t_project_id = (int)$p_args['id'];
$t_access_level = config_get( 'handle_bug_threshold', null, null, $t_project_id );

$t_data = array(
'query' => array(
'id' => $t_project_id,
'page_size' => $t_page_size,
'page' => $t_page,
'access_level' => $t_access_level,
'include_access_levels' => $t_include_access_levels
)
);

$t_command = new ProjectUsersGetCommand( $t_data );
$t_result = $t_command->execute();

return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
return project_users( $p_request, $p_response, $p_args, $t_access_level );
}

/**
Expand Down
9 changes: 1 addition & 8 deletions core/commands/ProjectUsersGetCommand.php
Expand Up @@ -103,13 +103,6 @@ function validate() {
$this->page_size = (int)$this->query( 'page_size', 50 );
$this->include_access_levels = (int)$this->query( 'include_access_levels', true );

if( $this->project_id <= ALL_PROJECTS ) {
throw new ClientException(
sprintf( "Must specify a specific project id.", $this->project_id ),
ERROR_PROJECT_NOT_FOUND,
array( $this->project_id ) );
}

if( !project_exists( $this->project_id ) ) {
throw new ClientException(
sprintf( "Project '%d' not found", $this->project_id ),
Expand Down Expand Up @@ -162,7 +155,7 @@ protected function process() {
$t_taken = 0;
$t_users_result = array();

$t_lang = user_pref_get_pref( auth_get_current_user_id(), 'language' );
$t_lang = mci_get_user_lang( auth_get_current_user_id() );

for( $i = $t_skip; $i < count( $t_users ); $i++ ) {
$t_user_id = (int)$t_users[$i]['id'];
Expand Down

0 comments on commit 15647bc

Please sign in to comment.