diff --git a/app/Database/seeds/dev/dev.yml b/app/Database/seeds/dev/base.yml similarity index 100% rename from app/Database/seeds/dev/dev.yml rename to app/Database/seeds/dev/base.yml diff --git a/app/Database/seeds/dev/sample.yml b/app/Database/seeds/dev/sample.yml index 93aa0646..2edc9e58 100644 --- a/app/Database/seeds/dev/sample.yml +++ b/app/Database/seeds/dev/sample.yml @@ -15,76 +15,6 @@ roles: - name: fleet-only display_name: Edit Fleet -users: - - id: 1 - pilot_id: 1 - name: Admin User - email: admin@phpvms.net - password: admin - api_key: testadminapikey - airline_id: 1 - rank_id: 1 - country: us - home_airport_id: KAUS - curr_airport_id: KJFK - last_pirep_id: pirepid_3 - flights: 3 - flight_time: 0 - timezone: America/Chicago - state: 1 - opt_in: 1 - toc_accepted: 1 - created_at: now - updated_at: now - - id: 2 - pilot_id: 2 - name: Carla Walters - email: carla.walters68@example.com - password: admin - api_key: testuserapikey1 - airline_id: 1 - rank_id: 1 - home_airport_id: KJFK - curr_airport_id: KJFK - flights: 1 - flight_time: 4320 - created_at: now - updated_at: now - state: 0 - opt_in: 1 - toc_accepted: 1 - - id: 3 - pilot_id: 3 - name: Raymond Pearson - email: raymond.pearson56@example.com - password: admin - api_key: testuserapikey2 - airline_id: 1 - rank_id: 1 - home_airport_id: KJFK - curr_airport_id: KAUS - flights: 1 - flight_time: 4320 - created_at: now - updated_at: now - state: 1 - opt_in: 0 - toc_accepted: 1 - -role_user: - - user_id: 1 - role_id: 1 - user_type: App\Models\User - - user_id: 1 - role_id: 2 - user_type: App\Models\User - - user_id: 2 - role_id: 2 - user_type: App\Models\User - - user_id: 3 - role_id: 2 - user_type: App\Models\User - awards: - id: 1 name: Pilot 50 flights diff --git a/app/Database/seeds/dev/users.yml b/app/Database/seeds/dev/users.yml new file mode 100644 index 00000000..36f5ae46 --- /dev/null +++ b/app/Database/seeds/dev/users.yml @@ -0,0 +1,71 @@ +users: + - id: 1 + pilot_id: 1 + name: Admin User + email: admin@phpvms.net + password: admin + api_key: testadminapikey + airline_id: 1 + rank_id: 1 + country: us + home_airport_id: KAUS + curr_airport_id: KJFK + last_pirep_id: pirepid_3 + flights: 3 + flight_time: 0 + timezone: America/Chicago + state: 1 + opt_in: 1 + toc_accepted: 1 + created_at: now + updated_at: now + - id: 2 + pilot_id: 2 + name: Carla Walters + email: carla.walters68@example.com + password: admin + api_key: testuserapikey1 + airline_id: 1 + rank_id: 1 + home_airport_id: KJFK + curr_airport_id: KJFK + flights: 1 + flight_time: 4320 + transfer_time: 360 + created_at: now + updated_at: now + state: 0 + opt_in: 1 + toc_accepted: 1 + - id: 3 + pilot_id: 3 + name: Raymond Pearson + email: raymond.pearson56@example.com + password: admin + api_key: testuserapikey2 + airline_id: 1 + rank_id: 1 + home_airport_id: KJFK + curr_airport_id: KAUS + flights: 1 + flight_time: 4320 + transfer_time: 120 + created_at: now + updated_at: now + state: 1 + opt_in: 0 + toc_accepted: 1 + +role_user: + - user_id: 1 + role_id: 1 + user_type: App\Models\User + - user_id: 1 + role_id: 2 + user_type: App\Models\User + - user_id: 2 + role_id: 2 + user_type: App\Models\User + - user_id: 3 + role_id: 2 + user_type: App\Models\User diff --git a/app/Database/seeds/settings.yml b/app/Database/seeds/settings.yml index 679d334e..17332d43 100644 --- a/app/Database/seeds/settings.yml +++ b/app/Database/seeds/settings.yml @@ -194,3 +194,10 @@ options: '' type: boolean description: 'Allow specifying transfer hours on registration page and displayed on profile page' +- key: pilots.count_transfer_hours + name: 'Count transfer hours in calculations' + group: pilots + value: false + options: '' + type: boolean + description: 'Count transfer hours in calculations, like ranks and the total hours' diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 3d654e20..ffa1b2b8 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -10,12 +10,12 @@ use App\Repositories\AirlineRepository; use App\Repositories\AirportRepository; use App\Services\UserService; use App\Support\Countries; +use Illuminate\Contracts\Validation\Validator; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Log; use Jackiedo\Timezonelist\Facades\Timezonelist; -use Log; -use Validator; /** * Class RegisterController diff --git a/app/Models/Rank.php b/app/Models/Rank.php index d5d7d399..28d1e4fa 100644 --- a/app/Models/Rank.php +++ b/app/Models/Rank.php @@ -11,6 +11,7 @@ use App\Contracts\Model; * @property int hours * @property float manual_base_pay_rate * @property float acars_base_pay_rate + * @property bool auto_promote */ class Rank extends Model { diff --git a/app/Models/User.php b/app/Models/User.php index 2dd899d9..66f790ef 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -22,7 +22,8 @@ use Laratrust\Traits\LaratrustUserTrait; * @property string home_airport_id * @property Airline airline * @property Flight[] flights - * @property string flight_time + * @property int flight_time + * @property int transfer_time * @property string remember_token * @property \Carbon\Carbon created_at * @property \Carbon\Carbon updated_at diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f968027a..a7dc5e76 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -17,8 +17,8 @@ use App\Repositories\AircraftRepository; use App\Repositories\SubfleetRepository; use App\Support\Units\Time; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use function is_array; -use Log; /** * Class UserService @@ -258,7 +258,12 @@ class UserService extends Service return $user; } - $pilot_hours = new Time($user->flight_time); + // If we should count their transfer hours? + if (setting('pilots.count_transfer_hours') === true) { + $pilot_hours = new Time($user->flight_time + $user->transfer_time); + } else { + $pilot_hours = new Time($user->flight_time); + } // The current rank's hours are over the pilot's current hours, // so assume that they were "placed" here by an admin so don't diff --git a/app/Services/VersionService.php b/app/Services/VersionService.php index ed63434d..c1789e49 100644 --- a/app/Services/VersionService.php +++ b/app/Services/VersionService.php @@ -179,11 +179,10 @@ class VersionService extends Service $current_version = $this->cleanVersionString($current_version); } - $current_version = Version::fromString($current_version); - $latest_version = Version::fromString($this->getLatestVersion()); + $latest_version = $this->getLatestVersion(); // Convert to semver - if ($latest_version->isGreaterThan($current_version)) { + if ($this->isGreaterThan($latest_version, $current_version)) { $this->kvpRepo->save('new_version_available', true); return true; } @@ -191,4 +190,17 @@ class VersionService extends Service $this->kvpRepo->save('new_version_available', false); return false; } + + /** + * @param string $version1 + * @param string $version2 + * + * @return bool If $version1 is greater than $version2 + */ + public function isGreaterThan($version1, $version2): bool + { + $version1 = Version::fromString($version1); + $version2 = Version::fromString($version2); + return $version1->isGreaterThan($version2); + } } diff --git a/resources/views/layouts/default/auth/register.blade.php b/resources/views/layouts/default/auth/register.blade.php index a8a00836..06e011f0 100644 --- a/resources/views/layouts/default/auth/register.blade.php +++ b/resources/views/layouts/default/auth/register.blade.php @@ -62,7 +62,7 @@ @if (setting('pilots.allow_transfer_hours') === true)
{{ $errors->first('transfer_time') }}
diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index b313f1b7..bdf90d1f 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -196,6 +196,8 @@ class PIREPTest extends TestCase */ public function testPilotStatsIncr() { + $this->updateSetting('pilots.count_transfer_hours', false); + $user = factory(User::class)->create([ 'flights' => 0, 'flight_time' => 0, @@ -254,6 +256,41 @@ class PIREPTest extends TestCase $this->assertNotEquals($last_pirep->id, $latest_pirep->id); } + /** + * check the stats/ranks, etc have incremented properly + */ + public function testPilotStatsIncrWithTransferHours() + { + $this->updateSetting('pilots.count_transfer_hours', true); + + $user = factory(User::class)->create([ + 'flights' => 0, + 'flight_time' => 0, + 'transfer_time' => 720, + 'rank_id' => 1, + ]); + + // Submit two PIREPs + // 1 hour flight times, but the rank should bump up because of the transfer hours + $pireps = factory(Pirep::class, 2)->create([ + 'airline_id' => $user->airline_id, + 'aircraft_id' => 1, + 'user_id' => $user->id, + 'flight_time' => 60, + ]); + + foreach ($pireps as $pirep) { + $this->pirepSvc->create($pirep); + $this->pirepSvc->accept($pirep); + } + + $pilot = User::find($user->id); + $last_pirep = Pirep::where('id', $pilot->last_pirep_id)->first(); + + // Make sure rank went up + $this->assertGreaterThan($user->rank_id, $pilot->rank_id); + } + /** * Find and check for any duplicate PIREPs by a user */ diff --git a/tests/VersionTest.php b/tests/VersionTest.php index 32298129..5b2d3715 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -14,7 +14,26 @@ class VersionTest extends TestCase $this->kvpRepo = app(KvpRepository::class); } - public function testGetLatestVersion() + /** + * Test that the new versions (keys) are properly regarded as new versions + */ + public function testGreaterThanVersionStrings(): void + { + $test = [ + '7.0.0' => '6.0.0', + '7.0.0-beta' => '7.0.0-alpha', + '7.0.0-beta.1' => '7.0.0-beta', + '7.0.0-beta.2' => '7.0.0-beta.1', + '7.0.0-beta.1' => '7.0.0-alpha', + ]; + + $versionSvc = app(VersionService::class); + foreach ($test as $newVersion => $currentVersion) { + $this->assertTrue($versionSvc->isGreaterThan($newVersion, $currentVersion)); + } + } + + public function testGetLatestVersion(): void { setting('general.check_prerelease_version', false); @@ -27,7 +46,7 @@ class VersionTest extends TestCase $this->assertEquals('7.0.0-alpha2', $this->kvpRepo->get('latest_version_tag')); } - public function testGetLatestPrereleaseVersion() + public function testGetLatestPrereleaseVersion(): void { $this->updateSetting('general.check_prerelease_version', true); @@ -40,7 +59,7 @@ class VersionTest extends TestCase $this->assertEquals('7.0.0-beta', $this->kvpRepo->get('latest_version_tag')); } - public function testNewVersionNotAvailable() + public function testNewVersionNotAvailable(): void { $this->updateSetting('general.check_prerelease_version', false); @@ -59,7 +78,10 @@ class VersionTest extends TestCase } } - public function testNewVersionIsAvailable() + /** + * Version in the prerelease releases.json is v7.0.0-beta + */ + public function testNewVersionIsAvailable(): void { $this->updateSetting('general.check_prerelease_version', true);