diff --git a/composer.json b/composer.json index d4fb4b1..817e7fe 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.5.19", + "version": "1.5.20", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/config/responsecache.php b/config/responsecache.php index f46be37..631b1bb 100644 --- a/config/responsecache.php +++ b/config/responsecache.php @@ -4,7 +4,7 @@ /* * Determine if the response cache middleware should be enabled. */ - 'enabled' => env('RESPONSE_CACHE_ENABLED', true), + 'enabled' => env('RESPONSE_CACHE_ENABLED', false), /* * The given class will determinate if a request should be cached. The diff --git a/src/Console/Commands/FixUserCompanies.php b/src/Console/Commands/FixUserCompanies.php new file mode 100644 index 0000000..f135842 --- /dev/null +++ b/src/Console/Commands/FixUserCompanies.php @@ -0,0 +1,52 @@ +get(); + + // Fix these users + /** @var User $user */ + foreach ($users as $user) { + // Check if user has a customer user record with the company + $doesntHaveCompanyUser = CompanyUser::where(['user_uuid' => $user->uuid, 'company_uuid' => $user->company_uuid])->doesntExist(); + if ($doesntHaveCompanyUser) { + $this->line('Found user ' . $user->name . ' (' . $user->email . ') which doesnt have correct company assignment.'); + $company = Company::where('uuid', $user->company_uuid)->first(); + if ($company) { + $user->assignCompany($company); + $this->line('User ' . $user->email . ' was assigned to company: ' . $company->name); + } + } + } + + return Command::SUCCESS; + } +} diff --git a/src/Models/User.php b/src/Models/User.php index 47ebbf6..d7ebbc4 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -21,6 +21,7 @@ use Fleetbase\Traits\Searchable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; @@ -1106,6 +1107,11 @@ public function sendInviteFromCompany(?Company $company = null): bool return false; } + // if no email cant send invite + if (!$this->email) { + return false; + } + // make sure user isn't already invited $isAlreadyInvited = Invite::isAlreadySentToJoinCompany($this, $company); if ($isAlreadyInvited) { @@ -1350,4 +1356,21 @@ public function getRoleName(): ?string return null; } + + public function syncProperty(string $property, Model $model): bool + { + $synced = false; + + if ($this->isFillable($property) && !$this->{$property} && $model->{$property}) { + $this->updateQuietly([$property => $model->{$property}]); + $synced = true; + } + + if ($model->isFillable($property) && !$model->{$property} && $this->{$property}) { + $model->updateQuietly([$property => $this->{$property}]); + $synced = true; + } + + return $synced; + } } diff --git a/src/Providers/CoreServiceProvider.php b/src/Providers/CoreServiceProvider.php index c1fef01..8d59b38 100644 --- a/src/Providers/CoreServiceProvider.php +++ b/src/Providers/CoreServiceProvider.php @@ -72,6 +72,7 @@ class CoreServiceProvider extends ServiceProvider \Fleetbase\Console\Commands\InitializeSandboxKeyColumn::class, \Fleetbase\Console\Commands\SyncSandbox::class, \Fleetbase\Console\Commands\CreatePermissions::class, + \Fleetbase\Console\Commands\FixUserCompanies::class, \Fleetbase\Console\Commands\BackupDatabase\MysqlS3Backup::class, ]; diff --git a/src/Support/Auth.php b/src/Support/Auth.php index e403625..c7dcdde 100644 --- a/src/Support/Auth.php +++ b/src/Support/Auth.php @@ -77,7 +77,7 @@ public static function setSession($user = null, $login = false): bool return true; } - session(['company' => $user->company_uuid, 'user' => $user->uuid, 'is_admin' => $user->isAdmin()]); + session(['company' => $user->company_uuid, 'user' => $user->uuid, 'is_admin' => $user->isAdmin(), 'is_customer' => $user->isType('customer'), 'is_driver' => $user->isType('driver')]); if ($login) { Authentication::login($user); }