diff --git a/composer.json b/composer.json index e75bb402..42fe5bfa 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.6.42", + "version": "1.6.43", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/src/Events/UserCreatedNewCompany.php b/src/Events/UserCreatedNewCompany.php new file mode 100644 index 00000000..3a873bbc --- /dev/null +++ b/src/Events/UserCreatedNewCompany.php @@ -0,0 +1,30 @@ +user = $user; + $this->company = $company; + } +} diff --git a/src/Http/Controllers/Internal/v1/AuthController.php b/src/Http/Controllers/Internal/v1/AuthController.php index 70b4953e..ba9d8160 100644 --- a/src/Http/Controllers/Internal/v1/AuthController.php +++ b/src/Http/Controllers/Internal/v1/AuthController.php @@ -2,6 +2,7 @@ namespace Fleetbase\Http\Controllers\Internal\v1; +use Fleetbase\Events\UserCreatedNewCompany; use Fleetbase\Exceptions\InvalidVerificationCodeException; use Fleetbase\Http\Controllers\Controller; use Fleetbase\Http\Requests\AdminRequest; @@ -799,7 +800,22 @@ public function createOrganization(Request $request) try { $company = Company::create($input); - $company->assignUser($user, 'Administrator'); + + // Set company owner + $company->setOwner($user)->save(); + + // Assign user to organization + $user->assignCompany($company, 'Administrator'); + $user->assignSingleRole('Administrator'); + + // Company onboarding is not necessary - set correct flags + $company->update([ + 'onboarding_completed_at' => now(), + 'onboarding_completed_by_uuid' => $user->uuid, + ]); + + // Fire event that user created a new organization + event(new UserCreatedNewCompany($user, $company)); } catch (\Throwable $e) { return response()->error($e->getMessage()); }