* Add boolean field "disable activity checks" to role, check for this field inside PilotLeave-Check, add tests * fix checkbox on form * CS fixes * CS fixes again :-) Co-authored-by: Andreas Palm <ap@ewsp.de>
This commit is contained in:
13
app/Database/factories/RoleFactory.php
Normal file
13
app/Database/factories/RoleFactory.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
|
$factory->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(),
|
||||||
|
];
|
||||||
|
});
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddDisableactivitychecksToRoles extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('roles', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,12 @@ namespace App\Models;
|
|||||||
use Laratrust\Models\LaratrustRole;
|
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
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||||
*/
|
*/
|
||||||
class Role extends LaratrustRole
|
class Role extends LaratrustRole
|
||||||
@@ -14,10 +20,12 @@ class Role extends LaratrustRole
|
|||||||
'name',
|
'name',
|
||||||
'display_name',
|
'display_name',
|
||||||
'read_only',
|
'read_only',
|
||||||
|
'disable_activity_checks',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'read_only' => 'boolean',
|
'read_only' => 'boolean',
|
||||||
|
'disable_activity_checks' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -282,9 +282,24 @@ class UserService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See if the difference is larger than what the setting calls for
|
// See if the difference is larger than what the setting calls for
|
||||||
if ($date->diffInDays($diff_date) > $leave_days) {
|
if ($date->diffInDays($diff_date) <= $leave_days) {
|
||||||
$return_users[] = $user;
|
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;
|
return $return_users;
|
||||||
|
|||||||
@@ -14,6 +14,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-container">
|
||||||
|
<h6><i class="fas fa-check-square"></i>
|
||||||
|
Features
|
||||||
|
</h6>
|
||||||
|
<div class="form-container-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-sm-12">
|
||||||
|
<div class="checkbox">
|
||||||
|
{{ Form::hidden('disable_activity_checks', 0) }}
|
||||||
|
{{ Form::checkbox('disable_activity_checks', 1) }}
|
||||||
|
{{ Form::label('disable_activity_checks', 'disable activity checks') }}
|
||||||
|
<p class="text-danger">{{ $errors->first('disable_activity_checks') }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Permissions Field -->
|
<!-- Permissions Field -->
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Models\Aircraft;
|
|||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
|
use App\Models\Role;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -154,4 +155,16 @@ trait TestData
|
|||||||
'aircraft' => $aircraft,
|
'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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,5 +370,19 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
$users_on_leave = $this->userSvc->findUsersOnLeave();
|
$users_on_leave = $this->userSvc->findUsersOnLeave();
|
||||||
$this->assertEquals(0, count($users_on_leave));
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user