diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index 1afd0126..c10db7d6 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -34,11 +34,16 @@ class Comment extends Post */ function getOwner(bool $honourFlags = true, bool $real = false): RowModel { - if($honourFlags && $this->isPostedOnBehalfOfGroup()) { - if($this->getTarget() instanceof Post) - return (new Clubs)->get(abs($this->getTarget()->getTargetWall())); - } + if($honourFlags && $this->isPostedOnBehalfOfGroup() && $this->getTarget() instanceof Post) + return (new Clubs)->get(abs($this->getTarget()->getTargetWall())); return parent::getOwner($honourFlags, $real); } + + function canBeDeletedBy(User $user): bool + { + return $this->getOwner()->getId() == $user->getId() || + $this->getTarget()->getOwner()->getId() == $user->getId() || + $this->getTarget() instanceof Post && $this->getTarget()->getTargetWall() < 0; + } } diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index 90be5222..f9d8500f 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -106,9 +106,8 @@ final class CommentPresenter extends OpenVKPresenter $comment = (new Comments)->get($id); if(!$comment) $this->notFound(); - if($comment->getOwner()->getId() !== $this->user->id) - if($comment->getTarget()->getOwner()->getId() !== $this->user->id) - $this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс."); + if(!$comment->canBeDeletedBy($this->user)) + $this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс."); $comment->delete(); $this->flashFail( diff --git a/Web/Presenters/templates/components/comment.xml b/Web/Presenters/templates/components/comment.xml index cfea3148..701db922 100644 --- a/Web/Presenters/templates/components/comment.xml +++ b/Web/Presenters/templates/components/comment.xml @@ -29,9 +29,7 @@
{$comment->getPublicationTime()} | - {var canDelete = $comment->getOwner()->getId() == $thisUser->getId()} - {var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()} - {if $canDelete} + {if $comment->canBeDeletedBy($thisUser)} {_"delete"} | {/if} Ответить