Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show All 15 Lines | |||||
/** | /** | ||||
* The eloquent definition of a User. | * The eloquent definition of a User. | ||||
* | * | ||||
* @property string $email | * @property string $email | ||||
* @property int $id | * @property int $id | ||||
* @property string $password | * @property string $password | ||||
* @property int $status | * @property int $status | ||||
* @property int $tenant_id | |||||
*/ | */ | ||||
class User extends Authenticatable implements JWTSubject | class User extends Authenticatable implements JWTSubject | ||||
{ | { | ||||
use Notifiable; | use Notifiable; | ||||
use NullableFields; | use NullableFields; | ||||
use UserAliasesTrait; | use UserAliasesTrait; | ||||
use SettingsTrait; | use SettingsTrait; | ||||
use SoftDeletes; | use SoftDeletes; | ||||
Show All 21 Lines | class User extends Authenticatable implements JWTSubject | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'id', | 'id', | ||||
'email', | 'email', | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'status' | 'status', | ||||
]; | ]; | ||||
/** | /** | ||||
* The attributes that should be hidden for arrays. | * The attributes that should be hidden for arrays. | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $hidden = [ | protected $hidden = [ | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
* Check if current user can read data of another object. | * Check if current user can read data of another object. | ||||
* | * | ||||
* @param \App\User|\App\Domain|\App\Wallet $object A user|domain|wallet object | * @param \App\User|\App\Domain|\App\Wallet $object A user|domain|wallet object | ||||
* | * | ||||
* @return bool True if he can, False otherwise | * @return bool True if he can, False otherwise | ||||
*/ | */ | ||||
public function canRead($object): bool | public function canRead($object): bool | ||||
{ | { | ||||
if ($this->role == "admin") { | if ($this->role == 'admin') { | ||||
return true; | return true; | ||||
} | } | ||||
if ($object instanceof User && $this->id == $object->id) { | if ($object instanceof User && $this->id == $object->id) { | ||||
return true; | return true; | ||||
} | } | ||||
if ($this->role == 'reseller') { | |||||
if ($object instanceof User && $object->role == 'admin') { | |||||
return false; | |||||
} | |||||
if ($object instanceof Wallet && !empty($object->owner)) { | |||||
$object = $object->owner; | |||||
} | |||||
return isset($object->tenant_id) && $object->tenant_id == $this->tenant_id; | |||||
} | |||||
if ($object instanceof Wallet) { | if ($object instanceof Wallet) { | ||||
return $object->user_id == $this->id || $object->controllers->contains($this); | return $object->user_id == $this->id || $object->controllers->contains($this); | ||||
} | } | ||||
if (!method_exists($object, 'wallet')) { | if (!method_exists($object, 'wallet')) { | ||||
return false; | return false; | ||||
} | } | ||||
$wallet = $object->wallet(); | $wallet = $object->wallet(); | ||||
return $this->wallets->contains($wallet) || $this->accounts->contains($wallet); | return $wallet && ($this->wallets->contains($wallet) || $this->accounts->contains($wallet)); | ||||
} | } | ||||
/** | /** | ||||
* Check if current user can update data of another object. | * Check if current user can update data of another object. | ||||
* | * | ||||
* @param \App\User|\App\Domain $object A user|domain object | * @param \App\User|\App\Domain $object A user|domain object | ||||
* | * | ||||
* @return bool True if he can, False otherwise | * @return bool True if he can, False otherwise | ||||
*/ | */ | ||||
public function canUpdate($object): bool | public function canUpdate($object): bool | ||||
{ | { | ||||
if (!method_exists($object, 'wallet')) { | |||||
return false; | |||||
} | |||||
if ($object instanceof User && $this->id == $object->id) { | if ($object instanceof User && $this->id == $object->id) { | ||||
return true; | return true; | ||||
} | } | ||||
return $this->canDelete($object); | return $this->canDelete($object); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | public function suspend(): void | ||||
return; | return; | ||||
} | } | ||||
$this->status |= User::STATUS_SUSPENDED; | $this->status |= User::STATUS_SUSPENDED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* The tenant for this user account. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function tenant() | |||||
{ | |||||
return $this->belongsTo('App\Tenant', 'tenant_id', 'id'); | |||||
} | |||||
/** | |||||
* Unsuspend this domain. | * Unsuspend this domain. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function unsuspend(): void | public function unsuspend(): void | ||||
{ | { | ||||
if (!$this->isSuspended()) { | if (!$this->isSuspended()) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |