fix: allow invited members to access workspace when owner has subscription
Members invited to a workspace no longer need their own subscription if the workspace owner has an active subscription or trial. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0544259f93
commit
4b015241ac
2 changed files with 76 additions and 0 deletions
|
|
@ -31,6 +31,17 @@ public function handle(Request $request, Closure $next): Response
|
|||
return $next($request);
|
||||
}
|
||||
|
||||
// Allow access if user belongs to a workspace owned by a subscribed user
|
||||
$currentWorkspace = $user->currentWorkspace;
|
||||
|
||||
if ($currentWorkspace && $currentWorkspace->owner && $currentWorkspace->owner->id !== $user->id) {
|
||||
$owner = $currentWorkspace->owner;
|
||||
|
||||
if ($owner->subscribed('default') || $owner->onTrial('default')) {
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to subscription page
|
||||
return redirect()->route('subscribe');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,3 +122,68 @@
|
|||
->get(route('calendar'))
|
||||
->assertRedirect(route('subscribe'));
|
||||
});
|
||||
|
||||
test('invited member can access workspace when owner has active subscription', function () {
|
||||
config(['trypost.self_hosted' => false]);
|
||||
|
||||
$owner = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$workspace = Workspace::factory()->create(['user_id' => $owner->id]);
|
||||
$workspace->members()->attach($owner->id, ['role' => 'owner']);
|
||||
|
||||
$owner->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_owner_123',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_123',
|
||||
]);
|
||||
|
||||
$member = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$workspace->members()->attach($member->id, ['role' => 'member']);
|
||||
$member->update(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('calendar'))
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('invited member is redirected to subscribe when owner has no subscription', function () {
|
||||
config(['trypost.self_hosted' => false]);
|
||||
|
||||
$owner = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$workspace = Workspace::factory()->create(['user_id' => $owner->id]);
|
||||
$workspace->members()->attach($owner->id, ['role' => 'owner']);
|
||||
|
||||
$member = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$workspace->members()->attach($member->id, ['role' => 'member']);
|
||||
$member->update(['current_workspace_id' => $workspace->id]);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('calendar'))
|
||||
->assertRedirect(route('subscribe'));
|
||||
});
|
||||
|
||||
test('invited member on own workspace without subscription is redirected to subscribe', function () {
|
||||
config(['trypost.self_hosted' => false]);
|
||||
|
||||
$owner = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$ownerWorkspace = Workspace::factory()->create(['user_id' => $owner->id]);
|
||||
$ownerWorkspace->members()->attach($owner->id, ['role' => 'owner']);
|
||||
|
||||
$owner->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_owner_123',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_123',
|
||||
]);
|
||||
|
||||
$member = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$ownerWorkspace->members()->attach($member->id, ['role' => 'member']);
|
||||
|
||||
$memberWorkspace = Workspace::factory()->create(['user_id' => $member->id]);
|
||||
$memberWorkspace->members()->attach($member->id, ['role' => 'owner']);
|
||||
$member->update(['current_workspace_id' => $memberWorkspace->id]);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('calendar'))
|
||||
->assertRedirect(route('subscribe'));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue