Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
* @return bool True if he can, False otherwise | * @return bool True if he can, False otherwise | ||||
*/ | */ | ||||
public function canDelete($object): bool | public function canDelete($object): bool | ||||
{ | { | ||||
if (!method_exists($object, 'wallet')) { | if (!method_exists($object, 'wallet')) { | ||||
return false; | return false; | ||||
} | } | ||||
if ($this->role == "admin") { | |||||
return true; | |||||
} | |||||
$wallet = $object->wallet(); | $wallet = $object->wallet(); | ||||
// TODO: For now controller can delete/update the account owner, | // TODO: For now controller can delete/update the account owner, | ||||
// 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); | ||||
} | } | ||||
Show All 31 Lines | class User extends Authenticatable implements JWTSubject | ||||
* @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')) { | if (!method_exists($object, 'wallet')) { | ||||
return false; | return false; | ||||
} | } | ||||
if ($this->role == "admin") { | |||||
return true; | |||||
} | |||||
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 334 Lines • Show Last 20 Lines |