Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

refactor: address third-pass review nits

Paulo Castellanocaad3d3e5300
diff --git a/app/Actions/User/CreateUser.php b/app/Actions/User/CreateUser.php
index ead5eca04..7f7f5e7b3 100644
--- a/app/Actions/User/CreateUser.php
+++ b/app/Actions/User/CreateUser.php
@@ -21,8 +21,9 @@ class CreateUser
*/
public static function execute(array $data, array $utmParameters = []): User
{
- $user = DB::transaction(function () use ($data, $utmParameters): User {
- $isInviteRegistration = data_get($data, 'is_invite', false);
+ $isInviteRegistration = (bool) data_get($data, 'is_invite', false);
+
+ $user = DB::transaction(function () use ($data, $utmParameters, $isInviteRegistration): User {
$requiresCardForTrial = (bool) config('trypost.billing.require_card_for_trial', true);
$accountAttributes = [
'name' => data_get($data, 'name')."'s Account",
@@ -49,13 +50,13 @@ class CreateUser
$account->update(['owner_id' => $user->id]);
- if (! $isInviteRegistration) {
- CreateWorkspace::execute($user, ['name' => data_get($data, 'name')."'s Workspace"]);
- }
-
return $user;
});
+ if (! $isInviteRegistration) {
+ CreateWorkspace::execute($user, ['name' => data_get($data, 'name')."'s Workspace"]);
+ }
+
if (PostHogService::isEnabled()) {
SyncUser::dispatch((string) $user->id);
}
diff --git a/app/Http/Controllers/App/BillingController.php b/app/Http/Controllers/App/BillingController.php
index 32a0cec91..fae503e84 100644
--- a/app/Http/Controllers/App/BillingController.php
+++ b/app/Http/Controllers/App/BillingController.php
@@ -130,6 +130,8 @@ class BillingController extends Controller
$subscription = $account->subscription(Account::SUBSCRIPTION_NAME);
+ abort_if($subscription === null, SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY, 'No active subscription');
+
if ($subscription->stripe_price === $yearlyPriceId) {
return redirect()->route('app.billing.index');
}
diff --git a/app/Http/Controllers/App/Settings/UsageController.php b/app/Http/Controllers/App/Settings/UsageController.php
index 926db2590..13e240e72 100644
--- a/app/Http/Controllers/App/Settings/UsageController.php
+++ b/app/Http/Controllers/App/Settings/UsageController.php
@@ -35,7 +35,7 @@ class UsageController extends Controller
return Inertia::render('settings/account/Usage', [
'usage' => [
- 'workspaceCount' => $account->workspaces()->count(),
+ 'workspaceCount' => $account->workspaces->count(),
'socialAccountCount' => $totalSocialAccounts,
'memberCount' => $totalMembers,
'creditsUsed' => BillingCycle::for($account)->usedCredits(),
diff --git a/tests/Feature/SocialLoginControllerTest.php b/tests/Feature/SocialLoginControllerTest.php
index 9fb08ccd3..382710f24 100644
--- a/tests/Feature/SocialLoginControllerTest.php
+++ b/tests/Feature/SocialLoginControllerTest.php
@@ -72,6 +72,33 @@ test('google callback creates new user when email does not exist', function () {
$this->assertAuthenticatedAs($user);
});
+test('github callback creates new user with a default workspace', function () {
+ $socialiteUser = new SocialiteUser;
+ $socialiteUser->map([
+ 'id' => '987',
+ 'name' => 'New Dev',
+ 'email' => '[email protected]',
+ ]);
+
+ Socialite::shouldReceive('driver')
+ ->with('github')
+ ->andReturn($driver = Mockery::mock());
+ $driver->shouldReceive('user')->andReturn($socialiteUser);
+
+ $response = $this->get(route('auth.github.callback'));
+
+ $response->assertRedirect(route('register.success'));
+
+ $user = User::where('email', '[email protected]')->first();
+ expect($user)->not->toBeNull();
+ expect($user->github_id)->toBe('987');
+ expect($user->name)->toBe('New Dev');
+ expect($user->workspaces()->count())->toBe(1);
+ expect($user->workspaces()->first()->name)->toBe("New Dev's Workspace");
+ expect($user->current_workspace_id)->toBe($user->workspaces()->first()->id);
+ $this->assertAuthenticatedAs($user);
+});
+
test('google callback marks unverified existing user as verified', function () {
$user = User::factory()->create([
'email' => '[email protected]',