2022-04-29 13:58:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\SCIMServiceProvider\Controller;
|
|
|
|
|
2022-05-18 16:51:34 +00:00
|
|
|
use OCP\AppFramework\ApiController;
|
2022-04-29 13:58:37 +00:00
|
|
|
use OCP\AppFramework\Http\Response;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
2022-05-02 10:21:25 +00:00
|
|
|
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
2023-03-03 11:21:27 +00:00
|
|
|
use OCA\SCIMServiceProvider\Service\UserService;
|
|
|
|
|
|
|
|
class UserController extends ApiController
|
|
|
|
{
|
|
|
|
/** @var UserService */
|
|
|
|
private $userService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
UserService $userService
|
|
|
|
) {
|
|
|
|
parent::__construct(
|
|
|
|
$appName,
|
|
|
|
$request
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->userService = $userService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $filter
|
|
|
|
* @return SCIMListResponse
|
|
|
|
* returns a list of users and their data
|
|
|
|
*/
|
|
|
|
public function index(string $filter = ''): SCIMListResponse
|
|
|
|
{
|
|
|
|
return $this->userService->getAll($filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* gets user info
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return SCIMJSONResponse
|
|
|
|
*/
|
|
|
|
// TODO: Add filtering support here as well
|
|
|
|
public function show(string $id): SCIMJSONResponse
|
|
|
|
{
|
|
|
|
return $this->userService->getOneById($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param bool $active
|
|
|
|
* @param string $displayName
|
|
|
|
* @param array $emails
|
|
|
|
* @param string $externalId
|
|
|
|
* @param string $userName
|
|
|
|
* @return SCIMJSONResponse
|
|
|
|
*/
|
|
|
|
public function create(
|
|
|
|
bool $active = true,
|
|
|
|
string $displayName = '',
|
|
|
|
array $emails = [],
|
|
|
|
string $externalId = '',
|
|
|
|
string $userName = ''
|
|
|
|
): SCIMJSONResponse
|
|
|
|
{
|
|
|
|
return $this->userService->create(
|
|
|
|
$active,
|
|
|
|
$displayName,
|
|
|
|
$emails,
|
|
|
|
$externalId,
|
|
|
|
$userName
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
*
|
|
|
|
* @param bool $active
|
|
|
|
* @param string $displayName
|
|
|
|
* @param array $emails
|
|
|
|
* @return SCIMJSONResponse
|
|
|
|
*/
|
|
|
|
public function update(
|
|
|
|
string $id,
|
|
|
|
bool $active,
|
|
|
|
string $displayName = '',
|
|
|
|
array $emails = []
|
|
|
|
): SCIMJSONResponse
|
|
|
|
{
|
|
|
|
return $this->userService->update($id, $active, $displayName, $emails);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy(string $id): Response
|
|
|
|
{
|
|
|
|
return $this->userService->destroy($id);
|
|
|
|
}
|
2022-04-29 13:58:37 +00:00
|
|
|
}
|