Passed
Push — dev5 ( 4b89af...8662bf )
by Ron
06:47
created
database/seeds/UserTableSeeder.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@
 block discarded – undo
12 12
     public function run()
13 13
     {
14 14
         //  Create the test users - note, none are installers - permissions are assigned randomly
15
-        factory(App\User::class, 15)->create()->each(function($user)
16
-        {
15
+        factory(App\User::class, 15)->create()->each(function($user) {
17 16
             // $user->UserPermissions()->save(factory(App\UserPermissions::class)->create(['user_id' => $user->user_id]));
18 17
         });
19 18
     }
Please login to merge, or discard this patch.
app/Http/Controllers/Admin/UserController.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
     public function __construct()
32 32
     {
33 33
         $this->middleware('auth')->except('initializeUser', 'submitInitializeUser');
34
-        $this->middleware(function ($request, $next) {
35
-            $this->user = auth()->user();  //  TODO - is this correct????
34
+        $this->middleware(function($request, $next) {
35
+            $this->user = auth()->user(); //  TODO - is this correct????
36 36
             $this->authorize('hasAccess', 'Manage Users');
37 37
             return $next($request);
38 38
         });
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
         $route    = '';
46 46
 
47 47
 
48
-        $userList = new UserCollection(User::where('active', 1)->with(['UserLogins' => function ($query) {
48
+        $userList = new UserCollection(User::where('active', 1)->with(['UserLogins' => function($query) {
49 49
             $query->latest()->limit(1);
50 50
         }])->get()
51 51
             /** @scrutinizer ignore-call */
52 52
             ->makeVisible('user_id'));
53
-        $route    = 'admin.user.edit';
53
+        $route = 'admin.user.edit';
54 54
 
55 55
         return view('admin.userIndex', [
56 56
             'userList' => $userList,
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     {
114 114
         //  Validate the new user form
115 115
         $request->validate([
116
-            'role'       => 'required|numeric',  //  TODO - add validation rule - is in user roles table
116
+            'role'       => 'required|numeric', //  TODO - add validation rule - is in user roles table
117 117
             'username'   => 'required|unique:users|regex:/^[a-zA-Z0-9_]*$/',
118 118
             'first_name' => 'required',
119 119
             'last_name'  => 'required',
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
         $user  = new UserResource(User::findOrFail($id));
192 192
 
193 193
         //  Make sure that the user is not trying to deactivate someone with more permissions
194
-        if ($user->role_id < Auth::user()->role_id) 
194
+        if($user->role_id < Auth::user()->role_id) 
195 195
         {
196 196
             return abort(403);
197 197
         }
198 198
 
199 199
         //  Good to go - update user password
200 200
         $roleArr = [];
201
-        foreach ($roles as $role) {
202
-            if ($role->role_id == 1 && Auth::user()->role_id != 1) {
201
+        foreach($roles as $role) {
202
+            if($role->role_id == 1 && Auth::user()->role_id != 1) {
203 203
                 continue;
204
-            } else if ($role->role_id == 2 && Auth::user()->role_id > 1) {
204
+            } else if($role->role_id == 2 && Auth::user()->role_id > 1) {
205 205
                 continue;
206 206
             } else {
207 207
                 // $roleArr[$role->role_id] = $role->name;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             }
213 213
         }
214 214
 
215
-        Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id);
215
+        Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id);
216 216
         return view('admin.userEdit', [
217 217
             'roles' => $roleArr,
218 218
             'user'  => $user->makeVisible(['user_id', 'username']),
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
         //  Update the user data
240 240
         $user = User::findOrFail($id);
241 241
 
242
-        if ($user->role_id < Auth::user()->role_id) 
242
+        if($user->role_id < Auth::user()->role_id) 
243 243
         {
244 244
             return abort(403);
245 245
         }
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
         $user = User::find($request->user_id);
283 283
 
284 284
         //  Verify this is a valid user ID
285
-        if (!$user) {
285
+        if(!$user) {
286 286
             $success = false;
287 287
             $reason  = 'Cannot find user with this ID';
288 288
         }
289 289
         //  Make sure that the user is not trying to deactivate someone with more permissions
290
-        else if ($user->role_id < Auth::user()->role_id) {
290
+        else if($user->role_id < Auth::user()->role_id) {
291 291
             $success = false;
292 292
             $reason  = 'You cannot change password for a user with higher permissions that you.  If this user has locked themselves out, have then use the reset link on the login page.';
293 293
         }
@@ -300,11 +300,11 @@  discard block
 block discarded – undo
300 300
                 'password_expires' => $nextChange
301 301
             ]);
302 302
             $success = true;
303
-            $reason  = 'Password for ' . $user->full_name . ' successfully reset.';
303
+            $reason  = 'Password for '.$user->full_name.' successfully reset.';
304 304
         }
305 305
 
306
-        Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id);
307
-        Log::notice('User ID-' . $request->user_id . ' password chagned by ' . Auth::user()->user_id, [
306
+        Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id);
307
+        Log::notice('User ID-'.$request->user_id.' password chagned by '.Auth::user()->user_id, [
308 308
             'success' => $success,
309 309
             'reason'  => $reason,
310 310
         ]);
Please login to merge, or discard this patch.
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -191,19 +191,25 @@  discard block
 block discarded – undo
191 191
         $user  = new UserResource(User::findOrFail($id));
192 192
 
193 193
         //  Make sure that the user is not trying to deactivate someone with more permissions
194
-        if ($user->role_id < Auth::user()->role_id) 
194
+        if ($user->role_id < Auth::user()->role_id)
195 195
         {
196 196
             return abort(403);
197 197
         }
198 198
 
199 199
         //  Good to go - update user password
200 200
         $roleArr = [];
201
-        foreach ($roles as $role) {
202
-            if ($role->role_id == 1 && Auth::user()->role_id != 1) {
201
+        foreach ($roles as $role)
202
+        {
203
+            if ($role->role_id == 1 && Auth::user()->role_id != 1)
204
+            {
203 205
                 continue;
204
-            } else if ($role->role_id == 2 && Auth::user()->role_id > 1) {
206
+            }
207
+            else if ($role->role_id == 2 && Auth::user()->role_id > 1)
208
+            {
205 209
                 continue;
206
-            } else {
210
+            }
211
+            else
212
+            {
207 213
                 // $roleArr[$role->role_id] = $role->name;
208 214
                 $roleArr[] = [
209 215
                     'value' => $role->role_id,
@@ -239,7 +245,7 @@  discard block
 block discarded – undo
239 245
         //  Update the user data
240 246
         $user = User::findOrFail($id);
241 247
 
242
-        if ($user->role_id < Auth::user()->role_id) 
248
+        if ($user->role_id < Auth::user()->role_id)
243 249
         {
244 250
             return abort(403);
245 251
         }
@@ -282,17 +288,20 @@  discard block
 block discarded – undo
282 288
         $user = User::find($request->user_id);
283 289
 
284 290
         //  Verify this is a valid user ID
285
-        if (!$user) {
291
+        if (!$user)
292
+        {
286 293
             $success = false;
287 294
             $reason  = 'Cannot find user with this ID';
288 295
         }
289 296
         //  Make sure that the user is not trying to deactivate someone with more permissions
290
-        else if ($user->role_id < Auth::user()->role_id) {
297
+        else if ($user->role_id < Auth::user()->role_id)
298
+        {
291 299
             $success = false;
292 300
             $reason  = 'You cannot change password for a user with higher permissions that you.  If this user has locked themselves out, have then use the reset link on the login page.';
293 301
         }
294 302
         //  Good to go - update user password
295
-        else {
303
+        else
304
+        {
296 305
             //  Update the user data
297 306
             $user->update(
298 307
             [
Please login to merge, or discard this patch.