Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | public function domain() | ||||
$domain = \App\Domain::withTrashed()->where('namespace', $domainName)->first(); | $domain = \App\Domain::withTrashed()->where('namespace', $domainName)->first(); | ||||
return $domain; | return $domain; | ||||
} | } | ||||
/** | /** | ||||
* List the domains to which this user is entitled. | * List the domains to which this user is entitled. | ||||
* Note: Active public domains are also returned (for the user tenant). | * | ||||
* @param bool $with_accounts Include domains assigned to wallets | |||||
* the current user controls but not owns. | |||||
* @param bool $with_public Include active public domains (for the user tenant). | |||||
* | * | ||||
* @return Domain[] List of Domain objects | * @return Domain[] List of Domain objects | ||||
*/ | */ | ||||
public function domains(): array | public function domains($with_accounts = true, $with_public = true): array | ||||
{ | { | ||||
$domains = []; | |||||
if ($with_public) { | |||||
if ($this->tenant_id) { | if ($this->tenant_id) { | ||||
$domains = Domain::where('tenant_id', $this->tenant_id); | $domains = Domain::where('tenant_id', $this->tenant_id); | ||||
} else { | } else { | ||||
$domains = Domain::withEnvTenantContext(); | $domains = Domain::withEnvTenantContext(); | ||||
} | } | ||||
$domains = $domains->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | $domains = $domains->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | ||||
->whereRaw(sprintf('(status & %s)', Domain::STATUS_ACTIVE)) | ->whereRaw(sprintf('(status & %s)', Domain::STATUS_ACTIVE)) | ||||
->get() | ->get() | ||||
->all(); | ->all(); | ||||
} | |||||
foreach ($this->wallets as $wallet) { | foreach ($this->wallets as $wallet) { | ||||
$entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | $entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | ||||
foreach ($entitlements as $entitlement) { | foreach ($entitlements as $entitlement) { | ||||
$domains[] = $entitlement->entitleable; | $domains[] = $entitlement->entitleable; | ||||
} | } | ||||
} | } | ||||
if ($with_accounts) { | |||||
foreach ($this->accounts as $wallet) { | foreach ($this->accounts as $wallet) { | ||||
$entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | $entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | ||||
foreach ($entitlements as $entitlement) { | foreach ($entitlements as $entitlement) { | ||||
$domains[] = $entitlement->entitleable; | $domains[] = $entitlement->entitleable; | ||||
} | } | ||||
} | } | ||||
} | |||||
return $domains; | return $domains; | ||||
} | } | ||||
/** | /** | ||||
* Find whether an email address exists as a user (including deleted users). | * Find whether an email address exists as a user (including deleted users). | ||||
* | * | ||||
* @param string $email Email address | * @param string $email Email address | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public static function findByEmail(string $email, bool $external = false): ?User | ||||
return $aliases->first()->user; | return $aliases->first()->user; | ||||
} | } | ||||
// TODO: External email | // TODO: External email | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Return groups controlled by the current user. | * Return groups controlled by the current user. | ||||
* | * | ||||
* @param bool $with_accounts Include groups assigned to wallets | * @param bool $with_accounts Include groups assigned to wallets | ||||
* the current user controls but not owns. | * the current user controls but not owns. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | public function removeSku(Sku $sku, int $count = 1): User | ||||
$entitlements_count--; | $entitlements_count--; | ||||
$count--; | $count--; | ||||
} | } | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* Return resources controlled by the current user. | |||||
* | |||||
* @param bool $with_accounts Include resources assigned to wallets | |||||
* the current user controls but not owns. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | |||||
*/ | |||||
public function resources($with_accounts = true) | |||||
{ | |||||
$wallets = $this->wallets()->pluck('id')->all(); | |||||
if ($with_accounts) { | |||||
$wallets = array_merge($wallets, $this->accounts()->pluck('wallet_id')->all()); | |||||
} | |||||
return \App\Resource::select(['resources.*', 'entitlements.wallet_id']) | |||||
->distinct() | |||||
->join('entitlements', 'entitlements.entitleable_id', '=', 'resources.id') | |||||
->whereIn('entitlements.wallet_id', $wallets) | |||||
->where('entitlements.entitleable_type', \App\Resource::class); | |||||
} | |||||
public function senderPolicyFrameworkWhitelist($clientName) | public function senderPolicyFrameworkWhitelist($clientName) | ||||
{ | { | ||||
$setting = $this->getSetting('spf_whitelist'); | $setting = $this->getSetting('spf_whitelist'); | ||||
if (!$setting) { | if (!$setting) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 285 Lines • Show Last 20 Lines |