Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
} | } | ||||
public function getJWTCustomClaims() | public function getJWTCustomClaims() | ||||
{ | { | ||||
return []; | return []; | ||||
} | } | ||||
/** | /** | ||||
* Return groups controlled by the current user. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | |||||
*/ | |||||
public function groups() | |||||
{ | |||||
$wallets = $this->wallets()->pluck('id')->all(); | |||||
$groupIds = \App\Entitlement::whereIn('entitlements.wallet_id', $wallets) | |||||
->where('entitlements.entitleable_type', Group::class) | |||||
->pluck('entitleable_id') | |||||
->all(); | |||||
return Group::whereIn('id', $groupIds); | |||||
} | |||||
/** | |||||
* Check if user has an entitlement for the specified SKU. | * Check if user has an entitlement for the specified SKU. | ||||
* | * | ||||
* @param string $title The SKU title | * @param string $title The SKU title | ||||
* | * | ||||
* @return bool True if specified SKU entitlement exists | * @return bool True if specified SKU entitlement exists | ||||
*/ | */ | ||||
public function hasSku($title): bool | public function hasSku($title): bool | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | public function users($with_accounts = true) | ||||
if ($with_accounts) { | if ($with_accounts) { | ||||
$wallets = array_merge($wallets, $this->accounts()->pluck('wallet_id')->all()); | $wallets = array_merge($wallets, $this->accounts()->pluck('wallet_id')->all()); | ||||
} | } | ||||
return $this->select(['users.*', 'entitlements.wallet_id']) | return $this->select(['users.*', 'entitlements.wallet_id']) | ||||
->distinct() | ->distinct() | ||||
->leftJoin('entitlements', 'entitlements.entitleable_id', '=', 'users.id') | ->leftJoin('entitlements', 'entitlements.entitleable_id', '=', 'users.id') | ||||
->whereIn('entitlements.wallet_id', $wallets) | ->whereIn('entitlements.wallet_id', $wallets) | ||||
->where('entitlements.entitleable_type', 'App\User'); | ->where('entitlements.entitleable_type', User::class); | ||||
} | } | ||||
/** | /** | ||||
* Verification codes for this user. | * Verification codes for this user. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function verificationcodes() | public function verificationcodes() | ||||
{ | { | ||||
return $this->hasMany('App\VerificationCode', 'user_id', 'id'); | return $this->hasMany('App\VerificationCode', 'user_id', 'id'); | ||||
} | } | ||||
/** | /** | ||||
* Returns the wallet by which the user is controlled | * Returns the wallet by which the user is controlled | ||||
* | * | ||||
* @return \App\Wallet A wallet object | * @return ?\App\Wallet A wallet object | ||||
*/ | */ | ||||
public function wallet(): Wallet | public function wallet(): ?Wallet | ||||
{ | { | ||||
$entitlement = $this->entitlement()->first(); | $entitlement = $this->entitlement()->withTrashed()->first(); | ||||
// TODO: No entitlement should not happen, but in tests we have | // TODO: No entitlement should not happen, but in tests we have | ||||
// such cases, so we fallback to the user's wallet in this case | // such cases, so we fallback to the user's wallet in this case | ||||
return $entitlement ? $entitlement->wallet : $this->wallets()->first(); | return $entitlement ? $entitlement->wallet : $this->wallets()->first(); | ||||
} | } | ||||
/** | /** | ||||
* Wallets this user owns. | * Wallets this user owns. | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |