Deploy Ladill POS / deploy (push) Successful in 1m58s
Pro and Business users can manage branches, invite cashiers with branch assignment, and switch registers; sales and register flows respect acting location. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pos;
|
|
|
|
use App\Models\PosMember;
|
|
use App\Models\User;
|
|
use App\Services\Identity\IdentityTeamClient;
|
|
|
|
class TeamMemberProvisioner
|
|
{
|
|
public function __construct(
|
|
protected IdentityTeamClient $identity,
|
|
) {}
|
|
|
|
public function sync(User $user): void
|
|
{
|
|
PosMember::query()
|
|
->where('user_ref', strtolower((string) $user->email))
|
|
->update(['user_ref' => $user->public_id]);
|
|
|
|
try {
|
|
$access = $this->identity->teamAccess($user->public_id);
|
|
} catch (\Throwable) {
|
|
return;
|
|
}
|
|
|
|
foreach ($access as $grant) {
|
|
if (($grant['self'] ?? false) || ($grant['full_access'] ?? false)) {
|
|
continue;
|
|
}
|
|
|
|
$apps = (array) ($grant['apps'] ?? []);
|
|
if (! in_array('pos', $apps, true)) {
|
|
continue;
|
|
}
|
|
|
|
$meta = (array) data_get($grant, 'metadata.pos', []);
|
|
|
|
PosMember::updateOrCreate(
|
|
[
|
|
'owner_ref' => (string) ($grant['account'] ?? $user->public_id),
|
|
'user_ref' => $user->public_id,
|
|
],
|
|
[
|
|
'role' => (string) ($meta['role'] ?? PosMember::ROLE_CASHIER),
|
|
'location_id' => $meta['location_id'] ?? null,
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|