Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/UsersController.php
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | public static function statusInfo($user): array | ||||
->pluck('title') | ->pluck('title') | ||||
->sort() | ->sort() | ||||
->unique() | ->unique() | ||||
->values() | ->values() | ||||
->all(); | ->all(); | ||||
$hasBeta = in_array('beta', $skus); | $hasBeta = in_array('beta', $skus); | ||||
$plan = $isController ? $user->wallet()->plan() : null; | |||||
$result = [ | $result = [ | ||||
'skus' => $skus, | 'skus' => $skus, | ||||
'enableBeta' => in_array('beta', $skus), | 'enableBeta' => in_array('beta', $skus), | ||||
// TODO: This will change when we enable all users to create domains | // TODO: This will change when we enable all users to create domains | ||||
'enableDomains' => $isController && $hasCustomDomain, | 'enableDomains' => $isController && $hasCustomDomain, | ||||
// TODO: Make 'enableDistlists' working for wallet controllers that aren't account owners | // TODO: Make 'enableDistlists' working for wallet controllers that aren't account owners | ||||
'enableDistlists' => $isController && $hasCustomDomain && $hasBeta, | 'enableDistlists' => $isController && $hasCustomDomain && $hasBeta, | ||||
'enableFiles' => !$isDegraded && $hasBeta && \config('app.with_files'), | 'enableFiles' => !$isDegraded && $hasBeta && \config('app.with_files'), | ||||
// TODO: Make 'enableFolders' working for wallet controllers that aren't account owners | // TODO: Make 'enableFolders' working for wallet controllers that aren't account owners | ||||
'enableFolders' => $isController && $hasCustomDomain && $hasBeta, | 'enableFolders' => $isController && $hasCustomDomain && $hasBeta, | ||||
// TODO: Make 'enableResources' working for wallet controllers that aren't account owners | // TODO: Make 'enableResources' working for wallet controllers that aren't account owners | ||||
'enableResources' => $isController && $hasCustomDomain && $hasBeta, | 'enableResources' => $isController && $hasCustomDomain && $hasBeta, | ||||
'enableRooms' => $hasMeet, | 'enableRooms' => $hasMeet, | ||||
'enableSettings' => $isController, | 'enableSettings' => $isController, | ||||
'enableUsers' => $isController, | 'enableUsers' => $isController, | ||||
'enableWallets' => $isController, | 'enableWallets' => $isController, | ||||
'enableWalletMandates' => $isController, | |||||
'enableWalletPayments' => $isController && (!$plan || $plan->mode != 'mandate'), | |||||
'enableCompanionapps' => $hasBeta, | 'enableCompanionapps' => $hasBeta, | ||||
]; | ]; | ||||
return array_merge($process, $result); | return array_merge($process, $result); | ||||
} | } | ||||
/** | /** | ||||
* Create a new user record. | * Create a new user record. | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | class UsersController extends RelationController | ||||
* @param \App\User $user User object | * @param \App\User $user User object | ||||
* | * | ||||
* @return array Response data | * @return array Response data | ||||
*/ | */ | ||||
public static function userResponse(User $user): array | public static function userResponse(User $user): array | ||||
{ | { | ||||
$response = array_merge($user->toArray(), self::objectState($user)); | $response = array_merge($user->toArray(), self::objectState($user)); | ||||
$wallet = $user->wallet(); | |||||
// IsLocked flag to lock the user to the Wallet page only | |||||
$response['isLocked'] = ($user->isRestricted() && ($plan = $wallet->plan()) && $plan->mode == 'mandate'); | |||||
// Settings | // Settings | ||||
$response['settings'] = []; | $response['settings'] = []; | ||||
foreach ($user->settings()->whereIn('key', self::USER_SETTINGS)->get() as $item) { | foreach ($user->settings()->whereIn('key', self::USER_SETTINGS)->get() as $item) { | ||||
$response['settings'][$item->key] = $item->value; | $response['settings'][$item->key] = $item->value; | ||||
} | } | ||||
// Status info | // Status info | ||||
$response['statusInfo'] = self::statusInfo($user); | $response['statusInfo'] = self::statusInfo($user); | ||||
Show All 15 Lines | public static function userResponse(User $user): array | ||||
$result['provider'] = $provider->name(); | $result['provider'] = $provider->name(); | ||||
return $result; | return $result; | ||||
}; | }; | ||||
// Information about wallets and accounts for access checks | // Information about wallets and accounts for access checks | ||||
$response['wallets'] = $user->wallets->map($map_func)->toArray(); | $response['wallets'] = $user->wallets->map($map_func)->toArray(); | ||||
$response['accounts'] = $user->accounts->map($map_func)->toArray(); | $response['accounts'] = $user->accounts->map($map_func)->toArray(); | ||||
$response['wallet'] = $map_func($user->wallet()); | $response['wallet'] = $map_func($wallet); | ||||
return $response; | return $response; | ||||
} | } | ||||
/** | /** | ||||
* Prepare user statuses for the UI | * Prepare user statuses for the UI | ||||
* | * | ||||
* @param \App\User $user User object | * @param \App\User $user User object | ||||
▲ Show 20 Lines • Show All 309 Lines • Show Last 20 Lines |