diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 81374a35..781bbb56 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -72,6 +72,16 @@ class Post extends Postable return $this->getRecord()->owner; } + function canBeDeletedBy(User $user): bool + { + if($this->getTargetWall() < 0) + $cDel = (new Clubs)->get(abs($this->getTargetWall()))->canBeModifiedBy($user); + else + $cDel = $this->getTargetWall() === $user->getId(); + + return $this->getOwnerPost() === $user->getId() || $cDel; + } + function setContent(string $content): void { if(ctype_space($content)) diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index afb0c5b2..e84d38e5 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -295,9 +295,15 @@ final class WallPresenter extends OpenVKPresenter if(!$post) $this->notFound(); $user = $this->user->id; - + + $wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1)) + ?? $this->flashFail("err", "Не удалось удалить пост", "Такого пользователя не существует."); + + if($wall < 0) $canBeDeletedByOtherUser = $wallOwner->canBeModifiedBy($this->user->identity); + else $canBeDeletedByOtherUser = false; + if(!is_null($user)) { - if($post->getOwnerPost() == $user || $post->getTargetWall() == $user) { + if($post->getOwnerPost() == $user || $post->getTargetWall() == $user || $canBeDeletedByOtherUser) { $post->unwire(); $post->delete(false); } @@ -305,7 +311,7 @@ final class WallPresenter extends OpenVKPresenter $this->flashFail("err", "Не удалось удалить пост", "Вы не вошли в аккаунт."); } - $this->redirect($_SERVER["HTTP_REFERER"], static::REDIRECT_TEMPORARY); + $this->redirect($wall < 0 ? "/club".($wall*-1) : "/id".$wall, static::REDIRECT_TEMPORARY); exit; } } diff --git a/Web/Presenters/templates/Wall/Post.xml b/Web/Presenters/templates/Wall/Post.xml index 9341dd2d..0d879cf5 100644 --- a/Web/Presenters/templates/Wall/Post.xml +++ b/Web/Presenters/templates/Wall/Post.xml @@ -18,8 +18,11 @@