wall: fix 500 when no user

This commit is contained in:
mrilyew 2024-11-02 16:31:35 +03:00 committed by veselcraft
parent fad7dc039e
commit 4271f59c18
No known key found for this signature in database
GPG key ID: 9CF0B42766CCF7BA
2 changed files with 12 additions and 3 deletions

View file

@ -46,8 +46,11 @@ class Comment extends Post
return parent::getOwner($honourFlags, $real); return parent::getOwner($honourFlags, $real);
} }
function canBeDeletedBy(User $user): bool function canBeDeletedBy(User $user = NULL): bool
{ {
if(!$user)
return false;
return $this->getOwner()->getId() == $user->getId() || return $this->getOwner()->getId() == $user->getId() ||
$this->getTarget()->getOwner()->getId() == $user->getId() || $this->getTarget()->getOwner()->getId() == $user->getId() ||
$this->getTarget() instanceof Post && $this->getTarget()->getTargetWall() < 0 && (new Clubs)->get(abs($this->getTarget()->getTargetWall()))->canBeModifiedBy($user) || $this->getTarget() instanceof Post && $this->getTarget()->getTargetWall() < 0 && (new Clubs)->get(abs($this->getTarget()->getTargetWall()))->canBeModifiedBy($user) ||

View file

@ -260,16 +260,22 @@ class Post extends Postable
$this->save(); $this->save();
} }
function canBePinnedBy(User $user): bool function canBePinnedBy(User $user = NULL): bool
{ {
if(!$user)
return false;
if($this->getTargetWall() < 0) if($this->getTargetWall() < 0)
return (new Clubs)->get(abs($this->getTargetWall()))->canBeModifiedBy($user); return (new Clubs)->get(abs($this->getTargetWall()))->canBeModifiedBy($user);
return $this->getTargetWall() === $user->getId(); return $this->getTargetWall() === $user->getId();
} }
function canBeDeletedBy(User $user): bool function canBeDeletedBy(User $user = NULL): bool
{ {
if(!$user)
return false;
if($this->getTargetWall() < 0 && !$this->getWallOwner()->canBeModifiedBy($user) && $this->getWallOwner()->getWallType() != 1 && $this->getSuggestionType() == 0) if($this->getTargetWall() < 0 && !$this->getWallOwner()->canBeModifiedBy($user) && $this->getWallOwner()->getWallType() != 1 && $this->getSuggestionType() == 0)
return false; return false;