Files
isaaccladandCursor a28e8619a1
Deploy Ladill Frontdesk / deploy (push) Successful in 1m10s
Wire Frontdesk demo seeder to shared DemoWorld
Org name, branches, and visitors now come from DemoWorld so continuity
matches Care/Queue across the suite, plus Members for DemoWorld staff
with a frontdesk role. Also resolve organization by owner_ref when
metadata.frontdesk.organization_id is missing, and skip reseed-on-login
for DemoWorld staff emails.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 13:35:52 +00:00

62 lines
1.8 KiB
PHP

<?php
namespace App\Services\Frontdesk;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use App\Services\Identity\IdentityTeamClient;
class TeamMemberProvisioner
{
public function __construct(
protected IdentityTeamClient $identity,
) {}
public function sync(User $user): void
{
Member::query()
->where('user_ref', strtolower((string) $user->email))
->update(['user_ref' => $user->ownerRef()]);
try {
$access = $this->identity->teamAccess($user->ownerRef());
} catch (\Throwable) {
return;
}
foreach ($access as $grant) {
if (($grant['self'] ?? false) || ($grant['full_access'] ?? false)) {
continue;
}
$apps = (array) ($grant['apps'] ?? []);
if (! in_array('frontdesk', $apps, true)) {
continue;
}
$meta = (array) data_get($grant, 'metadata.frontdesk', []);
$ownerRef = (string) ($grant['account'] ?? '');
$organizationId = (int) ($meta['organization_id'] ?? 0);
if ($organizationId <= 0 && $ownerRef !== '') {
$organizationId = (int) Organization::query()->where('owner_ref', $ownerRef)->value('id');
}
if ($organizationId <= 0) {
continue;
}
Member::updateOrCreate(
[
'organization_id' => $organizationId,
'user_ref' => $user->ownerRef(),
],
[
'owner_ref' => $ownerRef !== '' ? $ownerRef : $user->ownerRef(),
'role' => (string) ($meta['role'] ?? 'member'),
'branch_id' => $meta['branch_id'] ?? null,
],
);
}
}
}