use BookStack\Role;
use BookStack\User;
use Exception;
+use BookStack\Services\ImageService;
class UserRepo
{
protected $user;
protected $role;
protected $entityRepo;
+ protected $imageService;
/**
* UserRepo constructor.
* @param Role $role
* @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->role = $role;
$this->entityRepo = $entityRepo;
+ $this->imageService = $imageService;
}
/**
*/
public function isOnlyAdmin(User $user)
{
- if (!$user->roles->pluck('name')->contains('admin')) return false;
+ if (!$user->hasSystemRole('admin')) return false;
- $adminRole = $this->role->getRole('admin');
+ $adminRole = $this->role->getSystemRole('admin');
if ($adminRole->users->count() > 1) return false;
return true;
}
{
$user->socialAccounts()->delete();
$user->delete();
+
+ // Deleting User profile pics
+ $profilePic = $user->image_id ? $user->avatar->findOrFail($user->image_id) : FALSE;
+ if ($profilePic) {
+ $this->imageService->destroyImage($profilePic);
+ }
}
/**