mirror of
https://github.com/openvk/openvk
synced 2024-12-23 09:01:15 +03:00
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:
parent
e35b4dc70e
commit
67c61bf7a1
6 changed files with 35 additions and 8 deletions
|
@ -127,5 +127,10 @@ class TicketComment extends RowModel
|
||||||
return $mark === 1;
|
return $mark === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDeleted(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getRecord()->deleted;
|
||||||
|
}
|
||||||
|
|
||||||
use Traits\TRichText;
|
use Traits\TRichText;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace openvk\Web\Models\Repositories;
|
||||||
// use openvk\Web\Models\Entities\User;
|
// use openvk\Web\Models\Entities\User;
|
||||||
// use openvk\Web\Models\Repositories\Users;
|
// use openvk\Web\Models\Repositories\Users;
|
||||||
use openvk\Web\Models\Entities\TicketComment;
|
use openvk\Web\Models\Entities\TicketComment;
|
||||||
use Nette\Database\Table\ActiveRow;
|
|
||||||
use Chandler\Database\DatabaseConnection;
|
use Chandler\Database\DatabaseConnection;
|
||||||
|
|
||||||
class TicketComments
|
class TicketComments
|
||||||
|
@ -20,7 +19,7 @@ class TicketComments
|
||||||
|
|
||||||
function getCommentsById(int $ticket_id): \Traversable
|
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
|
// private function toTicket(?ActiveRow $ar): ?Ticket
|
||||||
|
|
|
@ -226,6 +226,29 @@ final class SupportPresenter extends OpenVKPresenter
|
||||||
$this->template->content = $parser->text($content);
|
$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
|
function renderRateAnswer(int $id, int $mark): void
|
||||||
{
|
{
|
||||||
$this->willExecuteWriteAction();
|
$this->willExecuteWriteAction();
|
||||||
|
|
|
@ -101,11 +101,9 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{if $comment->getUType() === 0}
|
<div class="post-menu">
|
||||||
<div class="post-menu">
|
<a href="/support/comment/{$comment->getId()}/delete?hash={urlencode($csrfToken)}">{_delete}</a>
|
||||||
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
|
{if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
|
||||||
<div class="post-menu">
|
<div class="post-menu">
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
|
|
||||||
{if $comment->getUType() === 0}
|
{if $comment->getUType() === 0}
|
||||||
<div class="post-menu">
|
<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>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ routes:
|
||||||
handler: "Support->makeComment"
|
handler: "Support->makeComment"
|
||||||
- url: "/al_comments/create/support/reply/{num}"
|
- url: "/al_comments/create/support/reply/{num}"
|
||||||
handler: "Support->AnswerTicketReply"
|
handler: "Support->AnswerTicketReply"
|
||||||
|
- url: "/support/comment/{num}/delete"
|
||||||
|
handler: "Support->deleteComment"
|
||||||
- url: "/al_comments/create/{text}/{num}"
|
- url: "/al_comments/create/{text}/{num}"
|
||||||
handler: "Comment->makeComment"
|
handler: "Comment->makeComment"
|
||||||
- url: "/support/delete/{num}"
|
- url: "/support/delete/{num}"
|
||||||
|
|
Loading…
Reference in a new issue