Skip to content

feat: tenant-scoped audits, a hook around queued jobs, LocaleColumns::writeUsing - #3

Merged
lam0819 merged 15 commits into
mainfrom
feat/tenancy-job-hooks
Nov 30, 2026
Merged

lam0819 merged 15 commits into
mainfrom
feat/tenancy-job-hooks

Conversation

@lam0819

@lam0819 lam0819 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

This PR adds four things the package needs to run inside a multi-tenant CMS, where each site is a Filament tenant. All four are generic, so any panel with tenancy can use them. Target release: 0.14.0.

Changes

  1. Tenant-scoped audits. Every run records the Filament tenant it started in. The migration adds tenant_type, tenant_id and an index.
    • On panels with tenancy, the Import audit page lists only the current tenant's runs. This holds even for users allowed to see every run.
    • ImportApprovals::canDecide() refuses runs of another tenant, so the approve and reject actions are hidden and direct calls throw.
    • HeadlessImport::tenant($model) records a tenant for headless runs.
    • Panels without tenancy are unchanged.
  2. A hook around queued jobs. ImportJobContext::around(fn (JobRun $run, Closure $next) => …) wraps every queued review slice and import slice.
    • JobRun carries the stage (review or import), the importer, the options and the Import.
    • Callbacks nest, the first registered outermost. A callback that doesn't call $next skips the slice.
  3. LocaleColumns::writeUsing(fn ($record, $locale, $value) => …) for translations stored outside the record's attributes, e.g. one row per language. Blank cells are still skipped.
  4. ext-pdo_sqlite is optional. seen_store now defaults to auto: SQLite when the extension is loaded, else the database.

CI gets a new databases job that runs the whole suite on PostgreSQL 16 and MySQL 8.4. tests/OctaneSafetyTest.php fails on any per-request static state. It also runs imports back to back and checks that no context leaks from one job into the next.

Existing tests broken by Filament 5.12

main currently has 6 failing tests with the latest dependencies (Filament 5.12.1). This PR fixes them; it's a test-setup issue, not a package bug.

  • Filament 5.12 restores the panel inside queued ImportCsv jobs. For users that aren't a FilamentUser it only allows this when app.env is local. The test suite's plain user is not a FilamentUser, so the suite now runs with app.env=local.
  • Filament now validates the panel origin of nested Livewire components. Rendering the action's modal content after a Livewire test request in the same test returns a 404, so that assertion moved into its own test.
  • The PostgreSQL and MySQL runs exposed two test-only issues:
    • Filament's stub migrations ran out of FK order, so they now run in dependency order.
    • Two assertions depended on driver-specific types (decimal, boolean, MySQL's varchar(255) length), so they now normalize them.

Checks

  • Pint ✅, PHPStan level 10 ✅
  • Pest: 140 passed on SQLite, PostgreSQL 15 and MariaDB (locally, all three)
  • New tests: TenancyAndJobHooksTest.php (7) and OctaneSafetyTest.php (2)

Upgrade

Run php artisan migrate. Nothing else changes for apps without tenancy.

One small behaviour change: LocaleColumns::filler() is now an instance method. It's protected, so it only matters if you subclassed LocaleColumns and overrode it.

Docs: new docs/multi-tenancy.md, plus updates to translatable.md, configuration.md, installation.md, scaling.md, the README and the CHANGELOG.

solutionforest team added 15 commits November 29, 2026 18:30
…:writeUsing

- Runs record their Filament tenant; the audit page, approvals and
  rejections are limited to the current tenant. HeadlessImport::tenant().
- ImportJobContext::around() wraps every queued review and import slice so
  apps can set up their own context before rows are read or written.
- LocaleColumns::writeUsing() for translations stored outside the record.
- ext-pdo_sqlite is optional: seen_store defaults to auto.
- CI runs the suite on PostgreSQL and MySQL; Octane safety test.
- Tests updated for Filament 5.12 (panel restored in queued import jobs,
  panel-origin check on nested Livewire components).
MySQL's JSON type reorders object keys, which changed the order of the
preview's columns and of the error counts per column. Store the
short-lived review slice payloads as text.
…keys inside their folder

Chunked-upload endpoints were plain authenticated routes, so on a panel
with tenancy no tenant was identified: uploads landed in the panel folder
and the tenant's wizard silently refused them. They are now tenant routes
(Filament checks the user's access to the tenant), and the wizard links to
the current tenant's endpoints.

Tenant keys that are not plain (containing '/', '..' or other characters)
are hashed into the folder name, so they can never climb out of or into
another tenant's folder.
…find users on workers

ReviewSlice now remembers the Filament panel and tenant of the request that
started the review and restores them while it runs (refusing a user who can
no longer access the tenant), like Filament does for import jobs. Without
this, ImportJobContext callbacks and rules saw no tenant on a real worker,
and the documented callback skipped every review slice.

Users are looked up through the auth guard's provider instead of
app(Authenticatable::class), which Laravel binds to the current user: null
on a queue worker and in the console, so parallel review crashed on real
workers and import-wizard:run --user failed unless the app had rebound it.
The callbacks lived in a static property, so every application booted in
the same process (each test of a host app, re-registering them in a
service provider's boot()) added another copy and jobs ran inside them
several times. They now belong to the application they were registered on.
…keeping their scope

modifyExportQuery() was skipped for a relation passed to FileExport::query(),
so resolveExportValue() ran on the wrong records. The relation's constrained
query is now handed over. The contract and docs say to narrow the given query,
which carries the tenant scope, rather than start a new one.
…ostgreSQL

Rolling it back failed: PostgreSQL refuses to change text to json without
a USING cast. Covered by a round-trip test with rows in place, which runs on
SQLite, PostgreSQL and MySQL in CI.
Untenanted runs recorded before the upgrade, moved upload folders, the
LocaleColumns::filler() signature, the optional pdo_sqlite extension, the
morph class in tenant_type, Filament's failed-rows route (user check only)
and what HeadlessImport::tenant() does and does not do.
@lam0819
lam0819 merged commit 1cb5c5d into main Nov 30, 2026
11 checks passed
@lam0819
lam0819 deleted the feat/tenancy-job-hooks branch November 30, 2026 02:57
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.

1 participant