mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +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
|
function getOwner(bool $honourFlags = true, bool $real = false): RowModel
|
||||||
{
|
{
|
||||||
if($honourFlags && $this->isPostedOnBehalfOfGroup()) {
|
if($honourFlags && $this->isPostedOnBehalfOfGroup() && $this->getTarget() instanceof Post)
|
||||||
if($this->getTarget() instanceof Post)
|
|
||||||
return (new Clubs)->get(abs($this->getTarget()->getTargetWall()));
|
return (new Clubs)->get(abs($this->getTarget()->getTargetWall()));
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getOwner($honourFlags, $real);
|
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,8 +106,7 @@ final class CommentPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
$comment = (new Comments)->get($id);
|
$comment = (new Comments)->get($id);
|
||||||
if(!$comment) $this->notFound();
|
if(!$comment) $this->notFound();
|
||||||
if($comment->getOwner()->getId() !== $this->user->id)
|
if(!$comment->canBeDeletedBy($this->user))
|
||||||
if($comment->getTarget()->getOwner()->getId() !== $this->user->id)
|
|
||||||
$this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс.");
|
$this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс.");
|
||||||
|
|
||||||
$comment->delete();
|
$comment->delete();
|
||||||
|
|
|
@ -29,9 +29,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
||||||
<a href="#_comment{$comment->getId()}" class="date">{$comment->getPublicationTime()}</a> |
|
<a href="#_comment{$comment->getId()}" class="date">{$comment->getPublicationTime()}</a> |
|
||||||
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
{if $comment->canBeDeletedBy($thisUser)}
|
||||||
{var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()}
|
|
||||||
{if $canDelete}
|
|
||||||
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a> |
|
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a> |
|
||||||
{/if}
|
{/if}
|
||||||
<a class="comment-reply">Ответить</a>
|
<a class="comment-reply">Ответить</a>
|
||||||
|
|
Loading…
Reference in a new issue