-
Notifications
You must be signed in to change notification settings - Fork 12
[IP-11]: Redirect to ivplv2 company dashboard after login #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nielsdrost7
wants to merge
4
commits into
develop
from
claude/default-company-dashboard-redirect-wxfk3i
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
36c34fa
Redirect to ivplv2 company dashboard after login
claude 6c3b466
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 388309f
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 8cdc147
Merge branch 'develop' into claude/default-company-dashboard-redirect…
nielsdrost7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| <?php | ||
|
|
||
| namespace Modules\Core\Tests\Feature; | ||
|
|
||
| use Illuminate\Support\Carbon; | ||
| use Livewire\Livewire; | ||
| use Modules\Core\Enums\UserRole; | ||
| use Modules\Core\Filament\Pages\Auth\Login; | ||
| use Modules\Core\Filament\Responses\LoginResponse; | ||
| use Modules\Core\Models\Company; | ||
| use Modules\Core\Models\User; | ||
| use Modules\Core\Tests\AbstractCompanyPanelTestCase; | ||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use PHPUnit\Framework\Attributes\Group; | ||
| use PHPUnit\Framework\Attributes\Test; | ||
| use Spatie\Permission\Models\Role; | ||
|
|
||
| #[CoversClass(LoginResponse::class)] | ||
| class LoginRedirectTest extends AbstractCompanyPanelTestCase | ||
| { | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| // Clean slate: remove companies created by base class to properly test fallback logic | ||
| Company::query()->delete(); | ||
| Carbon::setTestNow(Carbon::parse('2026-01-01 00:00:00')); | ||
| filament()->setCurrentPanel(filament()->getPanel('company')); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Carbon::setTestNow(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function activeUser(array $overrides = []): User | ||
| { | ||
| return User::factory()->create(array_merge([ | ||
| 'is_active' => true, | ||
| 'email_verified_at' => Carbon::now(), | ||
| 'password' => bcrypt('password'), | ||
| ], $overrides)); | ||
| } | ||
|
|
||
| private function ivplv2Company(): Company | ||
| { | ||
| return Company::factory()->create([ | ||
| 'search_code' => 'ivplv2', | ||
| 'name' => 'InvoicePlane Corporation', | ||
| 'slug' => 'invoiceplane-corporation', | ||
| ]); | ||
| } | ||
|
|
||
| private function elevatedRole(string $role): void | ||
| { | ||
| Role::query()->firstOrCreate(['name' => $role, 'guard_name' => 'web']); | ||
| } | ||
|
|
||
| # region elevated users | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_redirects_elevated_user_to_ivplv2_dashboard_after_login(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::SUPER_ADMIN->value); | ||
| $this->ivplv2Company(); | ||
|
|
||
| $user = $this->activeUser(['email' => 'super@example.com']); | ||
| $user->assignRole(UserRole::SUPER_ADMIN->value); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'super@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'ivplv2']) | ||
| ); | ||
| $this->assertAuthenticated(); | ||
| } | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_redirects_admin_user_to_ivplv2_dashboard_after_login(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::ADMIN->value); | ||
| $this->ivplv2Company(); | ||
|
|
||
| $user = $this->activeUser(['email' => 'admin@example.com']); | ||
| $user->assignRole(UserRole::ADMIN->value); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'admin@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'ivplv2']) | ||
| ); | ||
| } | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_falls_back_to_first_company_when_ivplv2_absent_for_elevated_user(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::SUPER_ADMIN->value); | ||
| Company::factory()->create(['search_code' => 'acme']); | ||
|
|
||
| $user = $this->activeUser(['email' => 'super@example.com']); | ||
| $user->assignRole(UserRole::SUPER_ADMIN->value); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'super@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'acme']) | ||
| ); | ||
| } | ||
|
|
||
| # endregion | ||
|
|
||
| # region regular users | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_redirects_regular_user_to_ivplv2_when_attached_to_it(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::CUSTOMER_ADMIN->value); | ||
| $ivplv2 = $this->ivplv2Company(); | ||
|
|
||
| $user = $this->activeUser(['email' => 'client@example.com']); | ||
| $user->assignRole(UserRole::CUSTOMER_ADMIN->value); | ||
| $user->companies()->attach($ivplv2->id); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'client@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'ivplv2']) | ||
| ); | ||
| $this->assertAuthenticated(); | ||
| } | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_prefers_ivplv2_over_other_companies_for_regular_user(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::CUSTOMER_ADMIN->value); | ||
| $other = Company::factory()->create(['search_code' => 'acme']); | ||
| $ivplv2 = $this->ivplv2Company(); | ||
|
|
||
| $user = $this->activeUser(['email' => 'client@example.com']); | ||
| $user->assignRole(UserRole::CUSTOMER_ADMIN->value); | ||
| // Attach other company first — ivplv2 should still win | ||
| $user->companies()->attach($other->id); | ||
| $user->companies()->attach($ivplv2->id); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'client@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'ivplv2']) | ||
| ); | ||
| } | ||
|
|
||
| #[Test] | ||
| #[Group('authentication')] | ||
| #[Group('redirect')] | ||
| public function it_falls_back_to_first_company_when_regular_user_is_not_attached_to_ivplv2(): void | ||
| { | ||
| /* Arrange */ | ||
| $this->elevatedRole(UserRole::CUSTOMER_ADMIN->value); | ||
| $otherCompany = Company::factory()->create(['search_code' => 'acme']); | ||
|
|
||
| $user = $this->activeUser(['email' => 'client@example.com']); | ||
| $user->assignRole(UserRole::CUSTOMER_ADMIN->value); | ||
| $user->companies()->attach($otherCompany->id); | ||
|
|
||
| /* Act */ | ||
| $response = Livewire::test(Login::class) | ||
| ->fillForm([ | ||
| 'email' => 'client@example.com', | ||
| 'password' => 'password', | ||
| ]) | ||
| ->call('authenticate'); | ||
|
|
||
| /* Assert */ | ||
| $response->assertRedirect( | ||
| route('filament.company.pages.dashboard', ['tenant' => 'acme']) | ||
| ); | ||
| } | ||
|
|
||
| # endregion | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.