Prevent user from being deleted if they still have assets assigned to them

This commit is contained in:
snipe
2013-11-29 16:57:24 -05:00
parent 7142e37372
commit 35155dfc4c
2 changed files with 15 additions and 3 deletions
+15 -2
View File
@@ -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)
{