mirror of
https://github.com/openvk/openvk
synced 2024-11-13 10:39:24 +03:00
parent
d8b37366cb
commit
78a8ee9a45
3 changed files with 12 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -29,9 +29,7 @@
|
|||
</div>
|
||||
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
||||
<a href="#_comment{$comment->getId()}" class="date">{$comment->getPublicationTime()}</a> |
|
||||
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
||||
{var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()}
|
||||
{if $canDelete}
|
||||
{if $comment->canBeDeletedBy($thisUser)}
|
||||
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a> |
|
||||
{/if}
|
||||
<a class="comment-reply">Ответить</a>
|
||||
|
|
Loading…
Reference in a new issue