Prevent user from being deleted if they still have assets assigned to them
This commit is contained in:
@@ -353,6 +353,7 @@ class UsersController extends AdminController {
|
||||
return Redirect::route('users')->with('error', $error);
|
||||
}
|
||||
|
||||
|
||||
// Do we have permission to delete this user?
|
||||
if ($user->isSuperUser() and ! Sentry::getUser()->isSuperUser())
|
||||
{
|
||||
@@ -360,14 +361,26 @@ class UsersController extends AdminController {
|
||||
return Redirect::route('users')->with('error', 'Insufficient permissions!');
|
||||
}
|
||||
|
||||
if (count($user->assets) > 0) {
|
||||
//print_r ($user->assets());
|
||||
// Redirect to the user management page
|
||||
return Redirect::route('users')->with('error', 'This user still has '.count($user->assets).' assets associated with them.');
|
||||
}
|
||||
|
||||
if (count($user->licenses) > 0) {
|
||||
//print_r ($user->licenses());
|
||||
// Redirect to the user management page
|
||||
return Redirect::route('users')->with('error', 'This user still has '.count($user->licenses).' licenses associated with them.');
|
||||
}
|
||||
|
||||
// Delete the user
|
||||
$user->delete();
|
||||
//$user->delete();
|
||||
|
||||
// Prepare the success message
|
||||
$success = Lang::get('admin/users/message.success.delete');
|
||||
|
||||
// Redirect to the user management page
|
||||
return Redirect::route('users')->with('success', $success);
|
||||
//return Redirect::route('users')->with('success', $success);
|
||||
}
|
||||
catch (UserNotFoundException $e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user