Deploy Ladill Hosting / deploy (push) Failing after 17s
Shared web hosting extracted from the platform monolith, with CI deploy to /var/www/ladill-hosting matching Bird/Domains/Email. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\User;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\View;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Resolves the "acting account" (owner User) the request operates on. Defaults
|
|
* to the authenticated user; a team member who switched accounts (session
|
|
* ladill_account) gets that owner, after an access check. Exposed via request
|
|
* attribute (ladill_account()) and to views.
|
|
*/
|
|
class SetActingAccount
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
if ($user = $request->user()) {
|
|
$accountId = (int) $request->session()->get('ladill_account', $user->id);
|
|
|
|
if (! $user->canAccessAccount($accountId)) {
|
|
$accountId = $user->id;
|
|
$request->session()->put('ladill_account', $accountId);
|
|
}
|
|
|
|
$account = $accountId === $user->id ? $user : (User::find($accountId) ?? $user);
|
|
|
|
$request->attributes->set('actingAccount', $account);
|
|
View::share('actingAccount', $account);
|
|
View::share('accessibleAccounts', $user->accessibleAccounts());
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|