Groups: Allow coadmins to delete comments on posts

Closes #341
This commit is contained in:
Maxim Leshchenko 2021-12-12 21:47:39 +02:00
parent d8b37366cb
commit 78a8ee9a45
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
3 changed files with 12 additions and 10 deletions

View file

@ -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;
}
} }

View file

@ -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();

View file

@ -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>&nbsp;| <a href="#_comment{$comment->getId()}" class="date">{$comment->getPublicationTime()}</a>&nbsp;|
{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>&nbsp;| <a href="/comment{$comment->getId()}/delete">{_"delete"}</a>&nbsp;|
{/if} {/if}
<a class="comment-reply">Ответить</a> <a class="comment-reply">Ответить</a>