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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user