Skip to content

fix: domain autoload#134

Merged
danielhe4rt merged 3 commits into
3.xfrom
fix/domain-autoload
Nov 27, 2025
Merged

fix: domain autoload#134
danielhe4rt merged 3 commits into
3.xfrom
fix/domain-autoload

Conversation

@danielhe4rt
Copy link
Copy Markdown
Contributor

@danielhe4rt danielhe4rt commented Nov 27, 2025

Summary by CodeRabbit

  • New Features

    • Participant dashboards and event views now respect the active tenant/context so users see event data for the correct organization.
  • Refactor

    • Tenant resolution and panel/provider initialization streamlined to use Filament's tenant resolver and consistent panel/theme mapping; panel ordering adjusted for predictable behavior.
  • Tests

    • Filament test setups updated to initialize the admin panel context; one test marked as skipped.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 27, 2025

Walkthrough

Replaces ad-hoc request-based tenant resolution with Filament's centralized tenant APIs across event components, middleware, and panel providers; adjusts provider ordering and FilamentServiceProvider tenant mapping; adds tenant mounting to ParticipantDashboard and updates tests to set current Filament panel where needed.

Changes

Cohort / File(s) Summary
Event module tenant integration
app-modules/events/src/Filament/Events/EventLandingPage.php, app-modules/events/src/Filament/Events/ParticipantDashboard.php
Removed manual request parsing for tenant; EventLandingPage now uses filament()->getTenant(). ParticipantDashboard adds a mounted tenant property, mount() to set it via filament()->getTenant(), tenant-aware view resolution, and getViewData() for tenant-scoped event data.
Tenant middleware
app/Http/Middleware/GuestTenantIdentifier.php
Replaced manual Tenant model lookup and conditional guest fallback with panel-based getTenant(route('tenant')), then Filament::setTenant(...) and continue to next middleware.
Filament panel providers
app/Providers/Filament/EventPanelProvider.php, app/Providers/Filament/GuestPanelProvider.php
EventPanelProvider: switched to named tenant() args (model => Tenant::class, conditional slugAttribute, ownershipRelationship). GuestPanelProvider: returns chained builder, added conditional domain() in chain, removed redundant UI button fragments.
Filament service provider
app/Providers/FilamentServiceProvider.php
Simplified tenant slug extraction (local path vs host header), introduced match mapping to normalized slugs ('3pontos' vs 'he4rt'), removed prior sanitization, and moved session()->put('panel', ...) to after tenant determination.
Bootstrap configuration
bootstrap/providers.php
Reordered providers array: moved AdminPanelProvider::class to after GuestPanelProvider::class (placed between Guest and Event providers).
Tests: Filament panel context changes
app-modules/events/tests/.../CreateTalkTest.php, app-modules/feedback/tests/.../Admin/*
One test marked skipped. Several feedback admin tests now call filament()->setCurrentPanel('admin') at test start to ensure panel context.

Sequence Diagram(s)

sequenceDiagram
    participant Req as HTTP Request
    participant MW as GuestTenantIdentifier
    participant Panel as Filament Panel
    participant Fil as Filament API
    participant Comp as Event Component

    Note over Req,MW: request enters app
    Req->>MW: incoming request
    MW->>Panel: panel->getTenant(route('tenant'))
    Panel-->>MW: Tenant
    MW->>Fil: Filament::setTenant(Tenant)
    Fil-->>MW: tenant set
    MW->>Req: next($request)

    Note over Req,Comp: component lifecycle
    Req->>Comp: mount()
    Comp->>Fil: filament()->getTenant()
    Fil-->>Comp: Tenant
    Comp->>Comp: compute view path using tenant->slug
    Comp->>Fil: render view with tenant-scoped data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review FilamentServiceProvider's slug mapping/match for correctness and future extensibility.
  • Validate ParticipantDashboard mount/getViewData properly handle null tenant and view existence checks.
  • Confirm middleware change preserves guest flows and that provider reordering doesn't cause init-time regressions.

Possibly related PRs

Suggested reviewers

  • RichardGL11
  • Clintonrocha98

Poem

🐇 I hopped through lines to find the claim,
Filament called — no slug to name,
Tenant found with one small cheer,
Views align and tests draw near,
A joyful hop, a tidy frame. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'fix: domain autoload' is vague and does not clearly convey the main purpose of the changeset, which involves tenant resolution refactoring and panel provider updates. Consider a more descriptive title that reflects the primary change, such as 'refactor: unify tenant resolution via Filament getTenant()' or 'fix: consolidate domain-based tenant identification logic'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/domain-autoload

Comment @coderabbitai help to get the list of available commands and usage tips.

gvieira18
gvieira18 previously approved these changes Nov 27, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app-modules/events/src/Filament/Events/ParticipantDashboard.php (1)

44-47: Reuse cached tenant instead of calling getTenant() again.

getViewData() calls filament()->getTenant() rather than using the already-mounted $this->tenant. This is inconsistent with getView() and makes an unnecessary additional call.

     protected function getViewData(): array
     {
-        return ['event' => filament()->getTenant()->events()->first()];
+        return ['event' => $this->tenant->events()->first()];
     }
🧹 Nitpick comments (1)
app/Providers/FilamentServiceProvider.php (1)

25-30: Hardcoded tenant mapping limits extensibility.

The match expression maps slugs to a fixed set of values ('3pontos' and 'he4rt'). This works for the current tenants but requires code changes when adding new tenants.

Consider externalizing tenant mappings to configuration if tenant additions are expected:

$tenantSlug = collect(config('tenants.mappings', []))
    ->first(fn ($_, $pattern) => str_contains($tenantSlug, $pattern), 'he4rt');
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b63cf6 and 06909df.

📒 Files selected for processing (7)
  • app-modules/events/src/Filament/Events/EventLandingPage.php (1 hunks)
  • app-modules/events/src/Filament/Events/ParticipantDashboard.php (2 hunks)
  • app/Http/Middleware/GuestTenantIdentifier.php (1 hunks)
  • app/Providers/Filament/EventPanelProvider.php (1 hunks)
  • app/Providers/Filament/GuestPanelProvider.php (1 hunks)
  • app/Providers/FilamentServiceProvider.php (2 hunks)
  • bootstrap/providers.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
app/Providers/Filament/EventPanelProvider.php (2)
app-modules/provider/src/Models/Provider.php (1)
  • model (51-54)
app-modules/tenant/src/Models/Tenant.php (1)
  • Tenant (23-104)
bootstrap/providers.php (1)
app/Providers/Filament/AdminPanelProvider.php (1)
  • AdminPanelProvider (24-75)
app-modules/events/src/Filament/Events/ParticipantDashboard.php (3)
app-modules/tenant/src/Models/Tenant.php (1)
  • Tenant (23-104)
app-modules/events/src/Filament/Events/EventLandingPage.php (2)
  • mount (18-21)
  • getView (23-30)
app-modules/events/src/Filament/Shared/EventLogin.php (1)
  • mount (66-76)
app-modules/events/src/Filament/Events/EventLandingPage.php (2)
app-modules/events/src/Models/Talk.php (1)
  • tenant (66-69)
app-modules/events/src/Models/EventModel.php (1)
  • tenant (140-143)
app/Providers/Filament/GuestPanelProvider.php (1)
app/Providers/Filament/EventPanelProvider.php (1)
  • panel (35-92)
🔇 Additional comments (4)
bootstrap/providers.php (1)

19-23: LGTM!

The provider reordering correctly positions AdminPanelProvider after EventPanelProvider, ensuring tenant-aware panel initialization occurs before the default admin panel loads.

app/Providers/Filament/GuestPanelProvider.php (1)

30-36: LGTM!

The production-aware domain binding using config('app.domain') is appropriate for the guest panel, which serves non-tenanted public pages. This correctly differentiates from tenant-specific domain handling in EventPanelProvider.

app/Providers/FilamentServiceProvider.php (1)

47-48: LGTM!

Moving the panel session persistence after tenant determination ensures the panel context is stored consistently with the resolved tenant.

app/Providers/Filament/EventPanelProvider.php (1)

39-43: The ownedTenants relationship exists and is properly configured.

The relationship is defined in the InteractsWithTenants trait (line 41-44 of app-modules/tenant/src/Models/Concerns/InteractsWithTenants.php):

public function ownedTenants(): HasMany
{
    return $this->hasMany(Tenant::class, 'owner_id');
}

The User model uses this trait, so the configuration in the EventPanelProvider is valid. The environment-aware slugAttribute correctly aligns production domain-based routing with local slug-based routing, and named parameters improve readability.

Comment thread app-modules/events/src/Filament/Events/EventLandingPage.php
Comment thread app-modules/events/src/Filament/Events/ParticipantDashboard.php
Comment thread app/Http/Middleware/GuestTenantIdentifier.php
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app-modules/events/src/Filament/Events/ParticipantDashboard.php (1)

35-42: Add null check before accessing tenant properties.

If filament()->getTenant() returns null, accessing $this->tenant->slug on line 37 will throw a null pointer exception before reaching the abort_unless check.

 public function getView(): string
 {
+    abort_unless($this->tenant, 403, 'Forbidden Tenant');
+
     $view = sprintf('events::components.themes.%s.participant-dashboard', $this->tenant->slug);

     abort_unless(view()->exists($view), 403, 'Forbidden Tenant');

     return $view;
 }
♻️ Duplicate comments (1)
app-modules/events/src/Filament/Events/ParticipantDashboard.php (1)

13-18: Type the property as Tenant for consistency.

The docblock declares @property Tenant $tenant, but the property is typed as ?Model. Use the concrete type for better IDE support and type safety.

-/** @property Tenant $tenant  */
 class ParticipantDashboard extends Page
 {
     protected Width|string|null $maxContentWidth = Width::Full;

-    private ?Model $tenant = null;
+    private ?Tenant $tenant = null;
🧹 Nitpick comments (2)
app-modules/events/tests/Feature/Filament/App/Talks/CreateTalkTest.php (1)

118-118: Add a skip reason or TODO comment explaining why this test is skipped.

Skipping tests without documentation makes it difficult to track why they were disabled and when they should be re-enabled. Consider using ->skip('reason') or adding a TODO comment.

-    })->skip();
+    })->skip('TODO: Fix tenant context resolution for this test scenario');
app-modules/events/src/Filament/Events/ParticipantDashboard.php (1)

44-47: Use $this->tenant instead of redundant filament()->getTenant() call.

The tenant is already resolved and stored in $this->tenant during mount(). Using the cached property improves consistency and avoids redundant resolution.

 protected function getViewData(): array
 {
-    return ['event' => filament()->getTenant()->events()->first()];
+    return ['event' => $this->tenant?->events()->first()];
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 961354a and c394624.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • app-modules/events/src/Filament/Events/ParticipantDashboard.php (2 hunks)
  • app-modules/events/tests/Feature/Filament/App/Talks/CreateTalkTest.php (1 hunks)
  • app-modules/feedback/tests/Feature/Filament/Admin/Feedback/CreateFeedbackTest.php (1 hunks)
  • app-modules/feedback/tests/Feature/Filament/Admin/Feedback/DeleteFeedbackTest.php (1 hunks)
  • app-modules/feedback/tests/Feature/Filament/Admin/Feedback/EditFeedbackTest.php (2 hunks)
  • app-modules/feedback/tests/Feature/Filament/Admin/Feedback/FeedbackResourceTest.php (1 hunks)
  • app/Providers/Filament/EventPanelProvider.php (1 hunks)
  • app/Providers/Filament/GuestPanelProvider.php (1 hunks)
  • bootstrap/providers.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Providers/Filament/GuestPanelProvider.php
🧰 Additional context used
🧬 Code graph analysis (1)
bootstrap/providers.php (1)
app/Providers/Filament/AdminPanelProvider.php (1)
  • AdminPanelProvider (24-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Perform Pest Tests / Run
  • GitHub Check: Perform Rector Check / Run
🔇 Additional comments (7)
app-modules/feedback/tests/Feature/Filament/Admin/Feedback/FeedbackResourceTest.php (1)

8-12: Initializing the admin panel before asserting resources looks correct

Setting filament()->setCurrentPanel('admin'); before calling Filament::getResources() ensures the resource list is evaluated in the correct panel context and aligns with the rest of the PR’s panel-handling changes.

app-modules/feedback/tests/Feature/Filament/Admin/Feedback/CreateFeedbackTest.php (1)

13-35: Admin panel initialization is correctly placed at test start

Calling filament()->setCurrentPanel('admin'); as the first line in the test ensures subsequent Livewire interactions with CreateFeedback run in the intended admin panel context.

app-modules/feedback/tests/Feature/Filament/Admin/Feedback/DeleteFeedbackTest.php (1)

12-26: Correctly scoping the delete flow to the admin panel

Using filament()->setCurrentPanel('admin'); before instantiating EditFeedback ensures the delete action executes within the admin panel context, consistent with the other feedback admin tests.

app-modules/feedback/tests/Feature/Filament/Admin/Feedback/EditFeedbackTest.php (2)

11-26: Explicit admin panel context for loading the edit page is appropriate

Initializing with filament()->setCurrentPanel('admin'); before creating the feedback and mounting EditFeedback ensures the schema state assertions reflect the admin panel configuration.


28-50: Admin panel initialization before updating feedback is consistent and correct

Setting filament()->setCurrentPanel('admin'); at the beginning of the update test guarantees the form fill and save call operate within the admin panel context, matching the rest of the feedback admin suite.

app/Providers/Filament/EventPanelProvider.php (1)

39-46: LGTM - tenant configuration with environment-aware routing.

The named parameters improve readability. The conditional logic correctly distinguishes between production (domain-based routing with empty path) and non-production (slug-based routing with /event path). This aligns with the tenantDomain configuration on line 46.

bootstrap/providers.php (1)

18-24: Verify provider ordering impact on panel resolution.

The AdminPanelProvider (which sets ->default() on its panel) has been repositioned between GuestPanelProvider and EventPanelProvider. Provider registration order can affect how Filament resolves the current panel, especially during domain-based tenant identification.

Please confirm this ordering correctly prioritizes panel resolution for the domain autoload fix.

@danielhe4rt danielhe4rt merged commit 47e2115 into 3.x Nov 27, 2025
10 of 11 checks passed
@danielhe4rt danielhe4rt deleted the fix/domain-autoload branch November 27, 2025 01:23
RichardGL11 pushed a commit that referenced this pull request Dec 3, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Participant dashboards and event views now respect the active
tenant/context so users see event data for the correct organization.

* **Refactor**
* Tenant resolution and panel/provider initialization streamlined to use
Filament's tenant resolver and consistent panel/theme mapping; panel
ordering adjusted for predictable behavior.

* **Tests**
* Filament test setups updated to initialize the admin panel context;
one test marked as skipped.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants