Add per-store managers for Woo Business accounts.
Deploy Ladill Woo Manager / deploy (push) Successful in 39s

Agencies can invite store-scoped managers via Identity, with access limited to one WooCommerce store while owners retain full multi-store control.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-08 07:51:08 +00:00
co-authored by Cursor
parent 1b0831b176
commit 09359ca86a
26 changed files with 921 additions and 28 deletions
+43 -1
View File
@@ -2,8 +2,11 @@
namespace App\Http\Middleware;
use App\Models\User;
use App\Models\WooStore;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Symfony\Component\HttpFoundation\Response;
class SetActingAccount
@@ -11,9 +14,48 @@ class SetActingAccount
public function handle(Request $request, Closure $next): Response
{
if ($user = $request->user()) {
$request->attributes->set('actingAccount', $user);
$accountId = (int) $request->session()->get('ladill_account', $user->id);
if (! $user->canAccessAccount($accountId)) {
$accountId = $user->id;
$request->session()->put('ladill_account', $accountId);
}
$accountId = $this->preferEmployerAccount($request, $user, $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);
}
private function preferEmployerAccount(Request $request, User $user, int $accountId): int
{
if ($accountId !== $user->id) {
return $accountId;
}
if (WooStore::query()->where('user_id', $user->id)->where('status', WooStore::STATUS_ACTIVE)->exists()) {
return $accountId;
}
$membership = $user->wooMemberships()->first();
if (! $membership) {
return $accountId;
}
$employer = User::where('public_id', $membership->owner_ref)->first();
if ($employer && $user->canAccessAccount($employer->id)) {
$request->session()->put('ladill_account', $employer->id);
return $employer->id;
}
return $accountId;
}
}