mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Add post deletion
Co-authored-by: vovocka <22993408+veselcraft@users.noreply.github.com>
This commit is contained in:
parent
026b9895b5
commit
20ba764f22
4 changed files with 25 additions and 6 deletions
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
</div>
|
||||
<div style="float: left; min-height: 100px; width: 32%;">
|
||||
<h4>Действия</h4>
|
||||
{if $post->getOwnerPost() == $thisUser->getId() || $post->getTargetWall() == $thisUser->getId()}
|
||||
<a class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">Удалить</a>
|
||||
{if isset($thisUser)}
|
||||
{var canDelete = $post->canBeDeletedBy($thisUser)}
|
||||
{/if}
|
||||
|
||||
<a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">Удалить</a>
|
||||
{/if}
|
||||
<a class="profile_link" style="display:block;width:96%;" href="/report.pl/{$post->getId()}?type=post">Пожаловаться</a>
|
||||
</div>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
||||
{if ($post->getOwnerPost() == $thisUser->getId() || $post->getTargetWall() == $thisUser->getId()) && !($forceNoDeleteLink ?? false)}
|
||||
{if $post->canBeDeletedBy($thisUser) && !($forceNoDeleteLink ?? false)}
|
||||
<a href="/wall{$post->getPrettyId()}/delete">{_"delete"}</a> |
|
||||
{/if}
|
||||
|
||||
|
|
Loading…
Reference in a new issue