diff --git a/app/Database/factories/RoleFactory.php b/app/Database/factories/RoleFactory.php new file mode 100644 index 00000000..7373766b --- /dev/null +++ b/app/Database/factories/RoleFactory.php @@ -0,0 +1,13 @@ +define(App\Models\Role::class, function (Faker $faker) { + return [ + 'id' => null, + 'name' => $faker->name, + 'display_name' => $faker->name, + 'read_only' => false, + 'disable_activity_checks' => $faker->boolean(), + ]; +}); diff --git a/app/Database/migrations/2021_03_18_161419_add_disableactivitychecks_to_roles.php b/app/Database/migrations/2021_03_18_161419_add_disableactivitychecks_to_roles.php new file mode 100644 index 00000000..72318d42 --- /dev/null +++ b/app/Database/migrations/2021_03_18_161419_add_disableactivitychecks_to_roles.php @@ -0,0 +1,34 @@ +boolean('disable_activity_checks') + ->default(false) + ->after('read_only'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('roles', function (Blueprint $table) { + $table->dropColumn('disable_activity_checks'); + }); + } +} diff --git a/app/Models/Role.php b/app/Models/Role.php index f2684a38..65454112 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -5,6 +5,12 @@ namespace App\Models; use Laratrust\Models\LaratrustRole; /** + * @property int id + * @property string name + * @property string display_name + * @property bool read_only + * @property bool disable_activity_checks + * * @mixin \Illuminate\Database\Eloquent\Builder */ class Role extends LaratrustRole @@ -14,10 +20,12 @@ class Role extends LaratrustRole 'name', 'display_name', 'read_only', + 'disable_activity_checks', ]; protected $casts = [ - 'read_only' => 'boolean', + 'read_only' => 'boolean', + 'disable_activity_checks' => 'boolean', ]; /** diff --git a/app/Services/UserService.php b/app/Services/UserService.php index fdfb91c8..275117cf 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -282,9 +282,24 @@ class UserService extends Service } // See if the difference is larger than what the setting calls for - if ($date->diffInDays($diff_date) > $leave_days) { - $return_users[] = $user; + if ($date->diffInDays($diff_date) <= $leave_days) { + continue; } + + $skip = false; + // If any role for this user has the "disable_activity_check" feature activated, skip this user + foreach ($user->roles()->get() as $role) { + /** @var Role $role */ + if ($role->disable_activity_checks) { + $skip = true; + break; + } + } + + if ($skip) { + continue; + } + $return_users[] = $user; } return $return_users; diff --git a/resources/views/admin/roles/fields.blade.php b/resources/views/admin/roles/fields.blade.php index 929c6598..69ebe526 100644 --- a/resources/views/admin/roles/fields.blade.php +++ b/resources/views/admin/roles/fields.blade.php @@ -14,6 +14,23 @@ +
+
+ Features +
+
+
+
+
+ {{ Form::hidden('disable_activity_checks', 0) }} + {{ Form::checkbox('disable_activity_checks', 1) }} + {{ Form::label('disable_activity_checks', 'disable activity checks') }} +

{{ $errors->first('disable_activity_checks') }}

+
+
+
+
+
diff --git a/tests/TestData.php b/tests/TestData.php index d25e9bba..fbe24c68 100644 --- a/tests/TestData.php +++ b/tests/TestData.php @@ -6,6 +6,7 @@ use App\Models\Aircraft; use App\Models\Enums\UserState; use App\Models\Flight; use App\Models\Pirep; +use App\Models\Role; use App\Models\Subfleet; use App\Models\User; use Exception; @@ -154,4 +155,16 @@ trait TestData 'aircraft' => $aircraft, ]; } + + /** + * Create a role + * + * @param array $attrs Additional role attributes + * + * @return Role + */ + public function createRole(array $attrs = []): Role + { + return factory(Role::class)->create($attrs); + } } diff --git a/tests/UserTest.php b/tests/UserTest.php index 18978eec..173783b6 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -370,5 +370,19 @@ class UserTest extends TestCase $users_on_leave = $this->userSvc->findUsersOnLeave(); $this->assertEquals(0, count($users_on_leave)); + + // Check disable_activity_checks + $user = $this->createUser([ + 'status' => UserState::ACTIVE, + 'created_at' => Carbon::now('UTC')->subDays(5), + ]); + $role = $this->createRole([ + 'disable_activity_checks' => true, + ]); + $user->attachRole($role); + $user->save(); + + $users_on_leave = $this->userSvc->findUsersOnLeave(); + $this->assertEquals(0, count($users_on_leave)); } }