Skip to content

A free open source IT asset/license management system

Merge branch 'develop' into fixes/companyable_trait_on_users

snipe7e3d66ec53ca
diff --cc app/Http/Controllers/Api/UsersController.php
index bc9b3db5dd,848adb66ff..e48994fbae
--- a/app/Http/Controllers/Api/UsersController.php
+++ b/app/Http/Controllers/Api/UsersController.php
@@@ -278,12 -288,12 +287,8 @@@ class UsersController extends Controlle
break;
}
- if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) {
- $users = $users->onlyTrashed();
- } elseif (($request->filled('all')) && ($request->input('all') == 'true')) {
- $users = $users->withTrashed();
- }
+
- // Apply companyable scope
- $users = Company::scopeCompanyables($users);
-
-
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $users->count()) ? $users->count() : app('api_offset_value');
$limit = app('api_limit_value');
@@@ -514,30 -531,16 +519,16 @@@
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function destroy($id)
+ public function destroy(DeleteUserRequest $request, $id)
{
$this->authorize('delete', User::class);
- $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc');
- $user = Company::scopeCompanyables($user)->find($id);
+ $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($id);
- $this->authorize('delete', $user);
-
- if ($user) {
-
- if (($user->assets) && ($user->assets->count() > 0)) {
- return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete_has_assets')));
- }
+
- if (($user->licenses) && ($user->licenses->count() > 0)) {
- return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->licenses->count() . ' license(s) associated with them and cannot be deleted.'));
- }
-
- if (($user->accessories) && ($user->accessories->count() > 0)) {
- return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->accessories->count() . ' accessories associated with them.'));
- }
+ $this->authorize('delete', $user);
- if (($user->managedLocations()) && ($user->managedLocations()->count() > 0)) {
- return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->managedLocations()->count() . ' locations that they manage.'));
- }
+ if ($user) {
+
if ($user->delete()) {
// Remove the user's avatar if they have one
diff --cc app/Http/Controllers/Users/UsersController.php
index 920e896d54,e88572b586..a82993f048
--- a/app/Http/Controllers/Users/UsersController.php
+++ b/app/Http/Controllers/Users/UsersController.php
@@@ -334,41 -338,10 +335,10 @@@ class UsersController extends Controlle
{
$this->authorize('delete', User::class);
+
- $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($id);
-
- if ($user) {
- // Check if we are not trying to delete ourselves
- if ($user->id === Auth::id()) {
- // Redirect to the user management page
- return redirect()->route('users.index')
- ->with('error', 'We would feel really bad if you deleted yourself, please reconsider.');
- }
-
- if (($user->assets()) && (($assetsCount = $user->assets()->count()) > 0)) {
- // Redirect to the user management page
- return redirect()->route('users.index')
- ->with('error', 'This user still has '.$assetsCount.' assets associated with them.');
- }
-
- if (($user->licenses()) && (($licensesCount = $user->licenses()->count())) > 0) {
- // Redirect to the user management page
- return redirect()->route('users.index')
- ->with('error', 'This user still has '.$licensesCount.' licenses associated with them.');
- }
-
- if (($user->accessories()) && (($accessoriesCount = $user->accessories()->count()) > 0)) {
- // Redirect to the user management page
- return redirect()->route('users.index')
- ->with('error', 'This user still has '.$accessoriesCount.' accessories associated with them.');
- }
-
- if (($user->managedLocations()) && (($managedLocationsCount = $user->managedLocations()->count())) > 0) {
- // Redirect to the user management page
- return redirect()->route('users.index')
- ->with('error', 'This user still has '.$managedLocationsCount.' locations that they manage.');
- }
+ $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc');
- $user = Company::scopeCompanyables($user)->find($id);
+ if (($user) && ($user->deleted_at = '')) {
// Delete the user
$user->delete();
return redirect()->route('users.index')->with('success', trans('admin/users/message.success.delete'));