From 4271f59c18e3bf25fe1c1b99b9c16db3c13c4990 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:31:35 +0300 Subject: [PATCH] wall: fix 500 when no user --- Web/Models/Entities/Comment.php | 5 ++++- Web/Models/Entities/Post.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index fd32c0b8..c0460dd5 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -46,8 +46,11 @@ class Comment extends Post 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() || $this->getTarget()->getOwner()->getId() == $user->getId() || $this->getTarget() instanceof Post && $this->getTarget()->getTargetWall() < 0 && (new Clubs)->get(abs($this->getTarget()->getTargetWall()))->canBeModifiedBy($user) || diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 21f1591c..5d5469d4 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -260,16 +260,22 @@ class Post extends Postable $this->save(); } - function canBePinnedBy(User $user): bool + function canBePinnedBy(User $user = NULL): bool { + if(!$user) + return false; + if($this->getTargetWall() < 0) return (new Clubs)->get(abs($this->getTargetWall()))->canBeModifiedBy($user); 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) return false;