Add per-store managers for Woo Business accounts.
Deploy Ladill Woo Manager / deploy (push) Successful in 39s
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:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/** Thin local mirror of the platform identity (auth.ladill.com owns users). */
|
||||
@@ -33,6 +34,34 @@ class User extends Authenticatable
|
||||
return $this->hasMany(WooStore::class);
|
||||
}
|
||||
|
||||
public function wooMemberships(): HasMany
|
||||
{
|
||||
return $this->hasMany(WooStoreMember::class, 'user_ref', 'public_id');
|
||||
}
|
||||
|
||||
public function canAccessAccount(int $accountId): bool
|
||||
{
|
||||
if ($accountId === $this->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$account = self::find($accountId);
|
||||
|
||||
return $account !== null
|
||||
&& $this->wooMemberships()->where('owner_ref', $account->public_id)->exists();
|
||||
}
|
||||
|
||||
/** @return Collection<int, User> */
|
||||
public function accessibleAccounts(): Collection
|
||||
{
|
||||
$ownerRefs = $this->wooMemberships()->pluck('owner_ref')->all();
|
||||
|
||||
return collect([$this])
|
||||
->merge(self::whereIn('public_id', $ownerRefs)->get())
|
||||
->unique('id')
|
||||
->values();
|
||||
}
|
||||
|
||||
public function avatarUrl(): ?string
|
||||
{
|
||||
$url = trim((string) $this->avatar_url);
|
||||
|
||||
Reference in New Issue
Block a user