Scope Frontdesk team members and add mailbox invite picker.
Deploy Ladill Frontdesk / deploy (push) Successful in 38s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-14 21:59:57 +00:00
co-authored by Cursor
parent a40e1f05c1
commit 1ec397d292
8 changed files with 237 additions and 15 deletions
@@ -286,7 +286,10 @@ class SsoLoginController extends Controller
private function resolveLanding(IdentityTeamClient $identity, User $user, string $intended): string
{
try {
return $identity->postAuthRedirect($user->ownerRef(), $intended);
$access = $identity->appAccess($user->ownerRef(), $intended);
\App\Support\StaffUx::remember($access);
return $access['url'] !== '' ? $access['url'] : $intended;
} catch (\Throwable) {
return $intended;
}
@@ -42,7 +42,7 @@ class MemberController extends Controller
]);
}
public function create(Request $request): View
public function create(Request $request, IdentityTeamClient $identity): View
{
$this->authorizeAbility($request, 'admin.members.manage');
$organization = $this->organization($request);
@@ -53,10 +53,18 @@ class MemberController extends Controller
->orderBy('name')
->get();
$mailboxOptions = [];
try {
$mailboxOptions = $identity->mailboxOptions($this->ownerRef($request));
} catch (\Throwable) {
// Identity optional for form rendering.
}
return view('frontdesk.admin.members.create', [
'organization' => $organization,
'branches' => $branches,
'roles' => config('frontdesk.roles'),
'mailboxOptions' => $mailboxOptions,
]);
}
+30 -4
View File
@@ -32,14 +32,40 @@ class IdentityTeamClient
return (array) $response->json('data', []);
}
/**
* @return array{url: string, apps: list<string>, full_access: bool, show_hub: bool, show_billing: bool}
*/
public function appAccess(string $userPublicId, string $intendedUrl = ''): array
{
$response = $this->request('get', '/identity/team/post-auth-redirect', array_filter([
'user' => $userPublicId,
'redirect' => $intendedUrl !== '' ? $intendedUrl : null,
]));
$data = (array) $response->json('data', []);
return [
'url' => (string) ($data['url'] ?? $intendedUrl),
'apps' => array_values(array_map('strval', (array) ($data['apps'] ?? []))),
'full_access' => (bool) ($data['full_access'] ?? false),
'show_hub' => (bool) ($data['show_hub'] ?? ($data['full_access'] ?? false)),
'show_billing' => (bool) ($data['show_billing'] ?? ($data['full_access'] ?? false)),
];
}
public function postAuthRedirect(string $userPublicId, string $intendedUrl): string
{
$response = $this->request('get', '/identity/team/post-auth-redirect', [
'user' => $userPublicId,
'redirect' => $intendedUrl,
return $this->appAccess($userPublicId, $intendedUrl)['url'];
}
/** @return list<string> */
public function mailboxOptions(string $ownerPublicId): array
{
$response = $this->request('get', '/identity/team/mailbox-options', [
'owner' => $ownerPublicId,
]);
return (string) $response->json('data.url', $intendedUrl);
return array_values(array_map('strval', (array) $response->json('data', [])));
}
/** @return list<array<string, mixed>> */
+119
View File
@@ -0,0 +1,119 @@
<?php
namespace App\Support;
use Illuminate\Contracts\Auth\Authenticatable;
/**
* Staff vs account-owner UX: team members are limited to the apps they were
* invited to. Single-app staff skip Home/launcher; all scoped staff hide
* Billing/Wallet (the account owner pays).
*
* In Care/Meet/etc., values are cached at SSO via Identity (StaffUx::remember).
* In the monolith, TeamAccessService resolves them live when available.
*/
class StaffUx
{
public const SESSION_KEY = 'ladill.staff_ux';
public static function showProductHub(?Authenticatable $user = null): bool
{
$user ??= auth()->user();
if (! $user) {
return false;
}
if ($resolved = self::fromTeamAccess($user)) {
return $resolved['show_hub'];
}
$cached = session(self::SESSION_KEY);
if (is_array($cached) && array_key_exists('show_hub', $cached)) {
return (bool) $cached['show_hub'];
}
// Unknown in a silo before SSO cache — assume owner (fail open for hub).
return true;
}
public static function showBilling(?Authenticatable $user = null): bool
{
$user ??= auth()->user();
if (! $user) {
return false;
}
if ($resolved = self::fromTeamAccess($user)) {
return $resolved['show_billing'];
}
$cached = session(self::SESSION_KEY);
if (is_array($cached) && array_key_exists('show_billing', $cached)) {
return (bool) $cached['show_billing'];
}
return true;
}
/** @return list<string>|null Null means unrestricted / unknown. */
public static function allowedAppSlugs(?Authenticatable $user = null): ?array
{
$user ??= auth()->user();
if (! $user) {
return [];
}
if ($resolved = self::fromTeamAccess($user)) {
return $resolved['full_access'] ? null : $resolved['apps'];
}
$cached = session(self::SESSION_KEY);
if (is_array($cached)) {
if (! empty($cached['full_access'])) {
return null;
}
if (array_key_exists('apps', $cached) && is_array($cached['apps'])) {
return array_values(array_map('strval', $cached['apps']));
}
}
return null;
}
/**
* @param array{full_access?: bool, apps?: list<string>, show_hub?: bool, show_billing?: bool} $payload
*/
public static function remember(array $payload): void
{
session([self::SESSION_KEY => [
'full_access' => (bool) ($payload['full_access'] ?? false),
'apps' => array_values(array_map('strval', (array) ($payload['apps'] ?? []))),
'show_hub' => (bool) ($payload['show_hub'] ?? false),
'show_billing' => (bool) ($payload['show_billing'] ?? false),
]]);
}
/** @return array{full_access: bool, apps: list<string>, show_hub: bool, show_billing: bool}|null */
private static function fromTeamAccess(Authenticatable $user): ?array
{
$service = 'App\\Services\\Team\\TeamAccessService';
$userClass = 'App\\Models\\User';
if (! class_exists($service) || ! is_a($user, $userClass)) {
return null;
}
try {
$access = app($service);
return [
'full_access' => $access->hasFullProductAccess($user),
'apps' => $access->accessibleAppSlugs($user),
'show_hub' => $access->showProductHub($user),
'show_billing' => $access->showBilling($user),
];
} catch (\Throwable) {
return null;
}
}
}
+13 -3
View File
@@ -21,15 +21,25 @@ class UserProfileMenu
return [];
}
$showHub = StaffUx::showProductHub($user);
$showBilling = StaffUx::showBilling($user);
$items = [];
foreach ([
['label' => 'Home', 'path' => '', 'host' => 'home'],
['label' => 'Home', 'path' => '', 'host' => 'home', 'requires_hub' => true],
['label' => 'Profile', 'path' => 'profile'],
['label' => 'Account Settings', 'path' => 'account-settings'],
['label' => 'Dashboard', 'path' => 'dashboard'],
['label' => 'Billing', 'path' => 'billing'],
['label' => 'Billing', 'path' => 'billing', 'requires_billing' => true],
] as $link) {
if (! empty($link['requires_hub']) && ! $showHub) {
continue;
}
if (! empty($link['requires_billing']) && ! $showBilling) {
continue;
}
$href = self::platformUrl($link['host'] ?? 'account', $link['path']);
if (self::isCurrentMenuLink($link, $href)) {
@@ -43,7 +53,7 @@ class UserProfileMenu
];
}
if (Route::has((string) config('billing.wallet_balance_route', 'wallet.balance'))) {
if ($showBilling && Route::has((string) config('billing.wallet_balance_route', 'wallet.balance'))) {
$items[] = ['type' => 'wallet'];
}