Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Notifications\Notifiable; | use Illuminate\Notifications\Notifiable; | ||||
use Illuminate\Contracts\Auth\MustVerifyEmail; | use Illuminate\Contracts\Auth\MustVerifyEmail; | ||||
use Illuminate\Foundation\Auth\User as Authenticatable; | use Illuminate\Foundation\Auth\User as Authenticatable; | ||||
use Iatstuti\Database\Support\NullableFields; | use Iatstuti\Database\Support\NullableFields; | ||||
use Tymon\JWTAuth\Contracts\JWTSubject; | use Tymon\JWTAuth\Contracts\JWTSubject; | ||||
use App\Traits\UserSettingsTrait; | use App\Traits\UserSettingsTrait; | ||||
/** | /** | ||||
* The eloquent definition of a User. | * The eloquent definition of a User. | ||||
* | |||||
* @property integer $id | |||||
* @property integer $status | |||||
*/ | */ | ||||
class User extends Authenticatable implements JWTSubject | class User extends Authenticatable implements JWTSubject | ||||
{ | { | ||||
use Notifiable; | use Notifiable; | ||||
use NullableFields; | use NullableFields; | ||||
use UserSettingsTrait; | use UserSettingsTrait; | ||||
// a new user, default on creation | // a new user, default on creation | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
*/ | */ | ||||
protected $casts = [ | protected $casts = [ | ||||
'email_verified_at' => 'datetime', | 'email_verified_at' => 'datetime', | ||||
]; | ]; | ||||
/** | /** | ||||
* Any wallets on which this user is a controller. | * Any wallets on which this user is a controller. | ||||
* | * | ||||
* @return Wallet[] | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
*/ | */ | ||||
public function accounts() | public function accounts() | ||||
{ | { | ||||
return $this->belongsToMany( | return $this->belongsToMany( | ||||
'App\Wallet', // The foreign object definition | 'App\Wallet', // The foreign object definition | ||||
'user_accounts', // The table name | 'user_accounts', // The table name | ||||
'user_id', // The local foreign key | 'user_id', // The local foreign key | ||||
'wallet_id' // The remote foreign key | 'wallet_id' // The remote foreign key | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* List the domains to which this user is entitled. | * List the domains to which this user is entitled. | ||||
* | * | ||||
* @return Domain[] | * @return Domain[] | ||||
*/ | */ | ||||
machniak: The $user argument can be a domain object too. And I see the method body is still not aware of… | |||||
public function domains() | public function domains() | ||||
{ | { | ||||
$domains = Domain::whereRaw( | $dbdomains = Domain::whereRaw( | ||||
sprintf( | sprintf( | ||||
'(type & %s) AND (status & %s)', | '(type & %s) AND (status & %s)', | ||||
Domain::TYPE_PUBLIC, | Domain::TYPE_PUBLIC, | ||||
Domain::STATUS_ACTIVE | Domain::STATUS_ACTIVE | ||||
) | ) | ||||
)->get(); | )->get(); | ||||
$domains = []; | |||||
foreach ($dbdomains as $dbdomain) { | |||||
$domains[] = $dbdomain; | |||||
} | |||||
foreach ($this->entitlements()->get() as $entitlement) { | foreach ($this->entitlements()->get() as $entitlement) { | ||||
if ($entitlement->entitleable instanceof Domain) { | if ($entitlement->entitleable instanceof Domain) { | ||||
$domain = Domain::find($entitlement->entitleable_id); | $domain = Domain::find($entitlement->entitleable_id); | ||||
\Log::info("Found domain {$domain->namespace}"); | \Log::info("Found domain {$domain->namespace}"); | ||||
$domains[] = $domain; | $domains[] = $domain; | ||||
} | } | ||||
} | } | ||||
Show All 13 Lines | class User extends Authenticatable implements JWTSubject | ||||
public function entitlement() | public function entitlement() | ||||
{ | { | ||||
return $this->morphOne('App\Entitlement', 'entitleable'); | return $this->morphOne('App\Entitlement', 'entitleable'); | ||||
} | } | ||||
/** | /** | ||||
* Entitlements for this user. | * Entitlements for this user. | ||||
* | * | ||||
* @return Entitlement[] | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function entitlements() | public function entitlements() | ||||
{ | { | ||||
return $this->hasMany('App\Entitlement', 'owner_id', 'id'); | return $this->hasMany('App\Entitlement', 'owner_id', 'id'); | ||||
Not Done Inline ActionsWithout checking entitleable_type this may return wrong results, I guess. Also, that method might end up to be not that useful if it does not return the domain entitlement. Something's looking fishy or just unfinished here. machniak: Without checking entitleable_type this may return wrong results, I guess. Also, that method… | |||||
} | } | ||||
public function addEntitlement($entitlement) | public function addEntitlement($entitlement) | ||||
{ | { | ||||
// FIXME: This contains() check looks fishy | // FIXME: This contains() check looks fishy | ||||
if (!$this->entitlements()->get()->contains($entitlement)) { | if (!$this->entitlements()->get()->contains($entitlement)) { | ||||
return $this->entitlements()->save($entitlement); | return $this->entitlements()->save($entitlement); | ||||
} | } | ||||
Show All 32 Lines | class User extends Authenticatable implements JWTSubject | ||||
/** | /** | ||||
* Returns whether this domain is active. | * Returns whether this domain is active. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isActive(): bool | public function isActive(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_ACTIVE; | if ($this->status & self::STATUS_ACTIVE) { | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is deleted. | * Returns whether this domain is deleted. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isDeleted(): bool | public function isDeleted(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_DELETED; | if ($this->status & self::STATUS_DELETED) { | ||||
return true; | |||||
} | |||||
return false; | |||||
Done Inline ActionsReally? One-liner looked much better. machniak: Really? One-liner looked much better. | |||||
Done Inline ActionsYeah, I did the one-liner for app/Domain.php. vanmeeuwen: Yeah, I did the one-liner for `app/Domain.php`. | |||||
} | } | ||||
/** | /** | ||||
* Returns whether this (external) domain has been verified | * Returns whether this (external) domain has been verified | ||||
* to exist in DNS. | * to exist in DNS. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isImapReady(): bool | public function isImapReady(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_IMAP_READY; | if ($this->status & self::STATUS_IMAP_READY) { | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether this user is registered in LDAP. | * Returns whether this user is registered in LDAP. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isLdapReady(): bool | public function isLdapReady(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_LDAP_READY; | if ($this->status & self::STATUS_LDAP_READY) { | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether this user is new. | * Returns whether this user is new. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isNew(): bool | public function isNew(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_NEW; | if ($this->status & self::STATUS_NEW) { | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether this domain is suspended. | * Returns whether this domain is suspended. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isSuspended(): bool | public function isSuspended(): bool | ||||
{ | { | ||||
return $this->status & self::STATUS_SUSPENDED; | if ($this->status & self::STATUS_SUSPENDED) { | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Any (additional) properties of this user. | * Any (additional) properties of this user. | ||||
* | * | ||||
* @return \App\UserSetting[] | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function settings() | public function settings() | ||||
{ | { | ||||
return $this->hasMany('App\UserSetting', 'user_id'); | return $this->hasMany('App\UserSetting', 'user_id'); | ||||
} | } | ||||
/** | /** | ||||
* Verification codes for this user. | * Verification codes for this user. | ||||
* | * | ||||
* @return VerificationCode[] | * @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'); | ||||
} | } | ||||
/** | /** | ||||
* Wallets this user owns. | * Wallets this user owns. | ||||
* | * | ||||
* @return Wallet[] | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function wallets() | public function wallets() | ||||
{ | { | ||||
return $this->hasMany('App\Wallet'); | return $this->hasMany('App\Wallet'); | ||||
} | } | ||||
public function setPasswordAttribute($password) | public function setPasswordAttribute($password) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |
The $user argument can be a domain object too. And I see the method body is still not aware of that.