Support: Add ability to delete comments in a ticket

There used to be a button for this, but it didn't work. It works now
This commit is contained in:
Maxim Leshchenko 2022-01-28 15:34:13 +02:00
parent e35b4dc70e
commit 67c61bf7a1
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
6 changed files with 35 additions and 8 deletions

View file

@ -127,5 +127,10 @@ class TicketComment extends RowModel
return $mark === 1;
}
function isDeleted(): bool
{
return (bool) $this->getRecord()->deleted;
}
use Traits\TRichText;
}

View file

@ -4,7 +4,6 @@ namespace openvk\Web\Models\Repositories;
// use openvk\Web\Models\Entities\User;
// use openvk\Web\Models\Repositories\Users;
use openvk\Web\Models\Entities\TicketComment;
use Nette\Database\Table\ActiveRow;
use Chandler\Database\DatabaseConnection;
class TicketComments
@ -20,7 +19,7 @@ class TicketComments
function getCommentsById(int $ticket_id): \Traversable
{
foreach($this->comments->where(['ticket_id' => $ticket_id]) as $comment) yield new TicketComment($comment);
foreach($this->comments->where(['ticket_id' => $ticket_id, 'deleted' => 0]) as $comment) yield new TicketComment($comment);
}
// private function toTicket(?ActiveRow $ar): ?Ticket

View file

@ -226,6 +226,29 @@ final class SupportPresenter extends OpenVKPresenter
$this->template->content = $parser->text($content);
}
function renderDeleteComment(int $id): void
{
$this->assertUserLoggedIn();
$this->assertNoCSRF();
$comment = $this->comments->get($id);
if(is_null($comment))
$this->notFound();
$ticket = $comment->getTicket();
if($ticket->isDeleted())
$this->notFound();
if(!($ticket->getUserId() === $this->user->id && $comment->getUType() === 0))
$this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0);
$this->willExecuteWriteAction();
$comment->delete();
$this->flashFail("succ", tr("ticket_changed"), tr("ticket_changed_comment"));
}
function renderRateAnswer(int $id, int $mark): void
{
$this->willExecuteWriteAction();

View file

@ -101,11 +101,9 @@
{/if}
</div>
{if $comment->getUType() === 0}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete?hash={urlencode($csrfToken)}">{_delete}</a>
</div>
{if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
<div class="post-menu">

View file

@ -103,7 +103,7 @@
{if $comment->getUType() === 0}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
<a href="/support/comment/{$comment->getId()}/delete?hash={urlencode($csrfToken)}">{_delete}</a>
</div>
{/if}

View file

@ -25,6 +25,8 @@ routes:
handler: "Support->makeComment"
- url: "/al_comments/create/support/reply/{num}"
handler: "Support->AnswerTicketReply"
- url: "/support/comment/{num}/delete"
handler: "Support->deleteComment"
- url: "/al_comments/create/{text}/{num}"
handler: "Comment->makeComment"
- url: "/support/delete/{num}"