diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index 0801c39f..a9fb684a 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -127,5 +127,10 @@ class TicketComment extends RowModel return $mark === 1; } + function isDeleted(): bool + { + return (bool) $this->getRecord()->deleted; + } + use Traits\TRichText; } diff --git a/Web/Models/Repositories/TicketComments.php b/Web/Models/Repositories/TicketComments.php index 94360aec..4d3c5316 100644 --- a/Web/Models/Repositories/TicketComments.php +++ b/Web/Models/Repositories/TicketComments.php @@ -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 diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 8a48a0db..a96ac465 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -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(); diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index c8fea4d7..a35ad6a6 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -101,11 +101,9 @@ {/if} - {if $comment->getUType() === 0} -
- {_delete} -
- {/if} +
+ {_delete} +
{if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
diff --git a/Web/Presenters/templates/Support/View.xml b/Web/Presenters/templates/Support/View.xml index 8f502fc3..4ef1ce2b 100644 --- a/Web/Presenters/templates/Support/View.xml +++ b/Web/Presenters/templates/Support/View.xml @@ -103,7 +103,7 @@ {if $comment->getUType() === 0}
- {_delete} + {_delete}
{/if} diff --git a/Web/routes.yml b/Web/routes.yml index 7bd01965..9fc08750 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -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}"