mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Added users-delete API endpoint
- Refactored some delete checks into repo. - Added tests to cover. - Moved some translations to align with activity/logging system.
This commit is contained in:
@ -5,6 +5,7 @@ namespace BookStack\Http\Controllers\Api;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Auth\UserRepo;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserApiController extends ApiController
|
||||
{
|
||||
@ -19,6 +20,9 @@ class UserApiController extends ApiController
|
||||
],
|
||||
'update' => [
|
||||
],
|
||||
'delete' => [
|
||||
'migrate_ownership_id' => ['integer', 'exists:users,id'],
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct(UserRepo $userRepo)
|
||||
@ -56,6 +60,24 @@ class UserApiController extends ApiController
|
||||
return response()->json($singleUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user from the system.
|
||||
* Can optionally accept a user id via `migrate_ownership_id` to indicate
|
||||
* who should be the new owner of their related content.
|
||||
* Requires permission to manage users.
|
||||
*/
|
||||
public function delete(Request $request, string $id)
|
||||
{
|
||||
$this->checkPermission('users-manage');
|
||||
|
||||
$user = $this->userRepo->getById($id);
|
||||
$newOwnerId = $request->get('migrate_ownership_id', null);
|
||||
|
||||
$this->userRepo->destroy($user, $newOwnerId);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given user model for single-result display.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user