From 5380ad1b27a7e809bd2d5af7d706f62beb35dede Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sat, 25 Sep 2021 16:59:18 +0300 Subject: [PATCH] Reports: Still makin it... --- Web/Models/Entities/Report.php | 2 +- Web/Models/Repositories/Reports.php | 10 +-- Web/Presenters/ReportPresenter.php | 84 ++++++++++-------------- Web/Presenters/templates/@layout.xml | 1 + Web/Presenters/templates/Report/List.xml | 31 +++++++++ Web/Presenters/templates/Report/View.xml | 22 +++++++ Web/di.yml | 2 + Web/routes.yml | 6 ++ 8 files changed, 101 insertions(+), 57 deletions(-) create mode 100644 Web/Presenters/templates/Report/List.xml create mode 100644 Web/Presenters/templates/Report/View.xml diff --git a/Web/Models/Entities/Report.php b/Web/Models/Entities/Report.php index ef5fe15a..15c1e017 100644 --- a/Web/Models/Entities/Report.php +++ b/Web/Models/Entities/Report.php @@ -85,7 +85,7 @@ class Report extends RowModel $this->save(); } - function delete() + function setDeleted() { $this->setDeleted(1); $this->unwire(); diff --git a/Web/Models/Repositories/Reports.php b/Web/Models/Repositories/Reports.php index c44df33d..264879e7 100644 --- a/Web/Models/Repositories/Reports.php +++ b/Web/Models/Repositories/Reports.php @@ -23,20 +23,20 @@ class Reports function getReports(int $state = 0, int $page = 1): \Traversable { foreach($this->reports->where(["deleted" => 0])->page($page, 15) as $t) - yield new Ticket($t); + yield new Report($t); } function getReportsCount(int $state = 0): int { - return sizeof($this->tickets->where(["deleted" => 0, "type" => $state])); + return sizeof($this->reports->where(["deleted" => 0, "type" => $state])); } - function get(int $id): ?Ticket + function get(int $id): ?Report { - return $this->toTicket($this->tickets->get($id)); + return $this->toReport($this->reports->get($id)); } - function getByContentId(int $id): ?Ticket + function getByContentId(int $id): ?Report { $post = $this->reports->where(["deleted" => 0, "content_id" => $id])->fetch(); diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php index a052b69b..3b6970e1 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -21,7 +21,7 @@ final class ReportPresenter extends OpenVKPresenter $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); $this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1)); - $this->template->count = $this->notes->getReportsCount(); + $this->template->count = $this->reports->getReportsCount(); $this->template->paginatorConf = (object) [ "count" => $this->template->count, "page" => $this->queryParam("p") ?? 1, @@ -35,7 +35,7 @@ final class ReportPresenter extends OpenVKPresenter $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); $report = $this->reports->get($id); - if(!$report || $note->isDeleted()) + if(!$report || $report->isDeleted()) $this->notFound(); $this->template->report = $report; @@ -63,10 +63,6 @@ final class ReportPresenter extends OpenVKPresenter if(!$post) $this->flashFail("err", "Ага! Попался, гадёныш блядь!", "Нельзя отправить жалобу на несуществующий контент"); - $postDublicate = $this->reports->getByContentId($post->getId()); - if($postDublicate) - $this->flashFail("err", tr("error"), "На этот контент уже пожаловался один из пользователей"); - $report = new Report; $report->setUser_id($this->user->id); $note->setContent_id($this->postParam("id")); @@ -77,61 +73,47 @@ final class ReportPresenter extends OpenVKPresenter $this->flashFail("suc", "Жалоба отправлена", "Скоро её рассмотрят модераторы"); } else { - $this->flashFail("err", "Пока низя", "Нельзя отправить жалобу на данный тип контент"); + $this->flashFail("err", "Пока низя", "Нельзя отправить жалобу на данный тип контента"); } } } - function renderBan(int $id): void + function renderAction(int $id): void { $this->assertUserLoggedIn(); $this->willExecuteWriteAction(); $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); - $report = $this->report->get($id); - if(!$report) $this->notFound(); - if($note->isDeleted()) $this->notFound(); - if(is_null($this->user)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); - - $report->banUser(); - $report->deleteContent(); - $this->flash("suc", "Смэрть...", "Пользователь успешно забанен."); - $this->redirect("/report/list"); - } - - function renderDeleteContent(int $id): void - { - $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); - $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); - - $report = $this->report->get($id); - if(!$report) $this->notFound(); - if($note->isDeleted()) $this->notFound(); - if(is_null($this->user)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); - - $report->deleteContent(); - $this->flash("suc", "Нехай живе!", "Контент удалён, а пользователю прилетело предупреждение."); - $this->redirect("/report/list"); - } - - function renderIgnoreReport(int $id): void - { - $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); - $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); - - $report = $this->report->get($id); - if(!$report) $this->notFound(); - if($note->isDeleted()) $this->notFound(); - if(is_null($this->user)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); - - $report->delete(); - $this->flash("suc", "Нехай живе!", "Жалоба проигнорирована."); + if($this->postParam("ban")) { + $report = $this->report->get($id); + if(!$report) $this->notFound(); + if($note->isDeleted()) $this->notFound(); + if(is_null($this->user)) + $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + + $report->banUser(); + $report->deleteContent(); + $this->flash("suc", "Смэрть...", "Пользователь успешно забанен."); + }else if($this->postParam("delete")){ + $report = $this->report->get($id); + if(!$report) $this->notFound(); + if($note->isDeleted()) $this->notFound(); + if(is_null($this->user)) + $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + + $report->deleteContent(); + $this->flash("suc", "Нехай живе!", "Контент удалён, а пользователю прилетело предупреждение."); + }else if($this->postParam("ignore")){ + $report = $this->report->get($id); + if(!$report) $this->notFound(); + if($report->isDeleted()) $this->notFound(); + if(is_null($this->user)) + $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + + $report->setDeleted(); + $this->flash("suc", "Нехай живе!", "Жалоба проигнорирована."); + } $this->redirect("/report/list"); } } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 8b8fe2be..aabc4892 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -160,6 +160,7 @@ {/if} {if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)} Helpdesk + Reports {/if} page} + +{block title}Список жалоб{/block} + +{block header} + Список жалоб +{/block} + +{block actions} + +{/block} + +{* BEGIN ELEMENTS DESCRIPTION *} + +{block link|strip|stripHtml} + /admin/report{$x->getId()} +{/block} + +{block preview} +
+{/block} + +{block name} + {$x->getReason()} +{/block} + +{block description} + Текст поста: {$x->getContentObject()->getText()} +{/block} diff --git a/Web/Presenters/templates/Report/View.xml b/Web/Presenters/templates/Report/View.xml new file mode 100644 index 00000000..a89d8bef --- /dev/null +++ b/Web/Presenters/templates/Report/View.xml @@ -0,0 +1,22 @@ +{extends "../@layout.xml"} + +{block title}{$report->getReason()}{/block} + +{block header} +
Список репортов + » + Жалоба №{$report->getId()} +{/block} + +{block content} +

Комментарий: {$report->getReason()}

+{include "../components/post/oldpost.xml", post => $report->getContentObject()} +
+
+ + + + +
+
+{/block} diff --git a/Web/di.yml b/Web/di.yml index a91d4f2a..fa24fa6f 100644 --- a/Web/di.yml +++ b/Web/di.yml @@ -16,6 +16,7 @@ services: - openvk\Web\Presenters\UnknownTextRouteStrategyPresenter - openvk\Web\Presenters\NotificationPresenter - openvk\Web\Presenters\SupportPresenter + - openvk\Web\Presenters\ReportPresenter - openvk\Web\Presenters\AdminPresenter - openvk\Web\Presenters\MessengerPresenter - openvk\Web\Presenters\ThemepacksPresenter @@ -30,6 +31,7 @@ services: - openvk\Web\Models\Repositories\Tickets - openvk\Web\Models\Repositories\Messages - openvk\Web\Models\Repositories\Restores + - openvk\Web\Models\Repositories\Reports - openvk\Web\Models\Repositories\Notifications - openvk\Web\Models\Repositories\TicketComments - openvk\Web\Models\Repositories\IPs diff --git a/Web/routes.yml b/Web/routes.yml index 5298b16f..3629a214 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -213,6 +213,12 @@ routes: handler: "Admin->quickBan" - url: "/admin/warn.pl/{num}" handler: "Admin->quickWarn" + - url: "/admin/reports" + handler: "Report->list" + - url: "/admin/report{num}" + handler: "Report->view" + - url: "/admin/reportAction{num}" + handler: "Report->action" - url: "/method/{text}.{text}" handler: "VKAPI->route" - url: "/token"