From 341226cac506fb02949f005805bf422d3f206831 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 fd32c0b8b..c0460dd5a 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -46,8 +46,11 @@ function getOwner(bool $honourFlags = true, bool $real = false): RowModel 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 21f1591c9..5d5469d4e 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -260,16 +260,22 @@ function unpin(): void $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;