Skip to content

Commit

Permalink
REST API: Delete Project Users API
Browse files Browse the repository at this point in the history
Fixes #32467
  • Loading branch information
vboctor committed May 9, 2023
1 parent aadf178 commit 34b8974
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions api/rest/restcore/projects_rest.php
Expand Up @@ -24,6 +24,8 @@
* @noinspection PhpFullyQualifiedNameUsageInspection
*/

use Mantis\Exceptions\ClientException;

/**
* @var \Slim\App $g_app
*/
Expand Down Expand Up @@ -62,10 +64,11 @@
$g_app->delete( '/{id}/subprojects/{subproject_id}/', 'rest_project_hierarchy_delete' );

# Project Users
$g_app->group( '/{id}/users[/]', function() use ( $g_app ) {
$g_app->post( '', 'rest_project_user_add' );
$g_app->put( '', 'rest_project_user_add' );
$g_app->get( '', 'rest_project_users' );
$g_app->group( '/{id}/users', function() use ( $g_app ) {
$g_app->post( '[/]', 'rest_project_user_add' );
$g_app->put( '[/]', 'rest_project_user_add' );
$g_app->get( '[/]', 'rest_project_users' );
$g_app->delete( '/{user_id}[/]', 'rest_project_user_delete' );
});

# Project Users that can handle issues
Expand Down Expand Up @@ -165,6 +168,39 @@ function rest_project_user_add( \Slim\Http\Request $p_request, \Slim\Http\Respon
return $p_response->withStatus( HTTP_STATUS_NO_CONTENT );
}

/**
* A method to remove user access to a 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_user_delete( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_project_id = (int)$p_args['id'];

# a user id or 0 to delete all users, don't cast right away, just in case an invalid value is passed
# that can cast to 0.
$t_user = $p_args['user_id'];
if( !is_numeric( $t_user ) ) {
throw new ClientException( 'Invalid user id', ERROR_INVALID_FIELD_VALUE, array( 'user_id' ) );
}

$t_user_id = (int)$t_user;

$t_data = array(
'payload' => array(
'project' => array( 'id' => $t_project_id ),
'user' => array( 'id' => $t_user_id )
)
);

$t_command = new ProjectUsersDeleteCommand( $t_data );
$t_command->execute();

return $p_response->withStatus( HTTP_STATUS_NO_CONTENT );
}

/**
* A method to get list of projects accessible to user with all their related information.
*
Expand Down

0 comments on commit 34b8974

Please sign in to comment.