1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Extend /users API endpoint

* add /users/{id} to get a single user
* add variable to print fields that are otherwise hidden (e.g. email)
This commit is contained in:
Jascha Sticher
2021-05-06 11:10:49 +02:00
parent 07626669da
commit 4cbd1a9eb5
5 changed files with 35 additions and 9 deletions

View File

@ -13,6 +13,10 @@ class UserApiController extends ApiController
protected $user;
protected $userRepo;
protected $printHidden = [
'email', 'created_at', 'updated_at', 'last_activity_at'
];
# TBD: Endpoints to create / update users
# protected $rules = [
# 'create' => [
@ -28,15 +32,30 @@ class UserApiController extends ApiController
}
/**
* Get a listing of pages visible to the user.
* Get a listing of users
*/
public function list()
{
$this->checkPermission('users-manage');
$users = $this->userRepo->getUsersBuilder();
return $this->apiListingResponse($users, [
'id', 'name', 'slug',
'email', 'created_at', 'updated_at',
]);
'id', 'name', 'slug', 'email',
'created_at', 'updated_at', 'last_activity_at',
], $this->printHidden);
}
/**
* View the details of a single user
*/
public function read(string $id)
{
$this->checkPermission('users-manage');
$singleUser = $this->userRepo->getById($id);
$singleUser = $singleUser->makeVisible($this->printHidden);
return response()->json($singleUser);
}
}