Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | public function canDelete($object): bool | ||||
// this may change in future, controllers are not 0-regression feature | // this may change in future, controllers are not 0-regression feature | ||||
return $this->wallets->contains($wallet) || $this->accounts->contains($wallet); | return $this->wallets->contains($wallet) || $this->accounts->contains($wallet); | ||||
} | } | ||||
/** | /** | ||||
* 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 $object A user|domain 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 (!method_exists($object, 'wallet')) { | |||||
return false; | |||||
} | |||||
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 ($object instanceof Wallet) { | |||||
return $object->user_id == $this->id || $object->controllers->contains($this); | |||||
} | |||||
if (!method_exists($object, 'wallet')) { | |||||
return false; | |||||
} | |||||
$wallet = $object->wallet(); | $wallet = $object->wallet(); | ||||
return $this->wallets->contains($wallet) || $this->accounts->contains($wallet); | return $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. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 373 Lines • Show Last 20 Lines |