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

View file

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

View file

@ -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>&nbsp;|
{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>&nbsp;|
{/if}
<a class="comment-reply">Ответить</a>