mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
* Issue-630: Fixed issue with deleting user profile pics when deleting a user. * Issue #630: Deleting user's profile pics on deleting of user account * Issue-630: Added test case for deleting user
This commit is contained in:
parent
4eb5205070
commit
35e00ddb95
@ -3,6 +3,7 @@
|
|||||||
use BookStack\Role;
|
use BookStack\Role;
|
||||||
use BookStack\User;
|
use BookStack\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use BookStack\Services\ImageService;
|
||||||
|
|
||||||
class UserRepo
|
class UserRepo
|
||||||
{
|
{
|
||||||
@ -10,6 +11,7 @@ class UserRepo
|
|||||||
protected $user;
|
protected $user;
|
||||||
protected $role;
|
protected $role;
|
||||||
protected $entityRepo;
|
protected $entityRepo;
|
||||||
|
protected $imageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserRepo constructor.
|
* UserRepo constructor.
|
||||||
@ -17,11 +19,12 @@ class UserRepo
|
|||||||
* @param Role $role
|
* @param Role $role
|
||||||
* @param EntityRepo $entityRepo
|
* @param EntityRepo $entityRepo
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user, Role $role, EntityRepo $entityRepo)
|
public function __construct(User $user, Role $role, EntityRepo $entityRepo, ImageService $imageService)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->role = $role;
|
$this->role = $role;
|
||||||
$this->entityRepo = $entityRepo;
|
$this->entityRepo = $entityRepo;
|
||||||
|
$this->imageService = $imageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,6 +148,12 @@ class UserRepo
|
|||||||
{
|
{
|
||||||
$user->socialAccounts()->delete();
|
$user->socialAccounts()->delete();
|
||||||
$user->delete();
|
$user->delete();
|
||||||
|
|
||||||
|
// Deleting User profile pics
|
||||||
|
$profilePic = $user->image_id ? $user->avatar->findOrFail($user->image_id) : FALSE;
|
||||||
|
if ($profilePic) {
|
||||||
|
$this->imageService->destroyImage($profilePic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,4 +115,19 @@ class UserProfileTest extends BrowserKitTest
|
|||||||
->visit('/books')
|
->visit('/books')
|
||||||
->pageHasElement('.featured-image-container');
|
->pageHasElement('.featured-image-container');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_user_delete()
|
||||||
|
{
|
||||||
|
$newUser = $this->getNewBlankUser();
|
||||||
|
$this->actingAs($newUser);
|
||||||
|
$this->asAdmin()->visit('/settings/users/' . $newUser->id . '/delete')
|
||||||
|
->see('Delete User')
|
||||||
|
->press('Confirm')
|
||||||
|
->seePageIs('/settings/users/')
|
||||||
|
->see('USERS')->see('ADD NEW USER');
|
||||||
|
|
||||||
|
$this->dontSeeInDatabase('images', [
|
||||||
|
'id' => $newUser->image_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user