Reports: Backend is done

This commit is contained in:
veselcraft 2021-09-21 01:02:53 +03:00
parent 75c0aecf47
commit d715fa9575
3 changed files with 93 additions and 20 deletions

View file

@ -84,4 +84,11 @@ class Report extends RowModel
$this->unwire(); $this->unwire();
$this->save(); $this->save();
} }
function delete()
{
$this->setDeleted(1);
$this->unwire();
$this->save();
}
} }

View file

@ -35,6 +35,16 @@ class Reports
{ {
return $this->toTicket($this->tickets->get($id)); return $this->toTicket($this->tickets->get($id));
} }
function getByContentId(int $id): ?Ticket
{
$post = $this->reports->where(["deleted" => 0, "content_id" => $id])->fetch();
if($post)
return new Report($post);
else
return null;
}
use \Nette\SmartObject; use \Nette\SmartObject;
} }

View file

@ -2,6 +2,7 @@
namespace openvk\Web\Presenters; namespace openvk\Web\Presenters;
use openvk\Web\Models\Repositories\Users; use openvk\Web\Models\Repositories\Users;
use openvk\Web\Models\Repositories\Reports; use openvk\Web\Models\Repositories\Reports;
use openvk\Web\Models\Repositories\Posts;
use openvk\Web\Models\Entities\Report; use openvk\Web\Models\Entities\Report;
final class ReportPresenter extends OpenVKPresenter final class ReportPresenter extends OpenVKPresenter
@ -17,6 +18,8 @@ final class ReportPresenter extends OpenVKPresenter
function renderList(): void function renderList(): void
{ {
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
$this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1)); $this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1));
$this->template->count = $this->notes->getReportsCount(); $this->template->count = $this->notes->getReportsCount();
$this->template->paginatorConf = (object) [ $this->template->paginatorConf = (object) [
@ -29,6 +32,8 @@ final class ReportPresenter extends OpenVKPresenter
function renderView(int $id): void function renderView(int $id): void
{ {
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
$report = $this->reports->get($id); $report = $this->reports->get($id);
if(!$report || $note->isDeleted()) if(!$report || $note->isDeleted())
$this->notFound(); $this->notFound();
@ -42,40 +47,91 @@ final class ReportPresenter extends OpenVKPresenter
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
// ЛАПСКИЙ Я НЕ ДО КОНЦА ДОДЕЛАЛ Я ПРОСТО МЫТЬСЯ ПОШЁЛ // ЛАПСКИЙ Я НЕ ДО КОНЦА ДОДЕЛАЛ Я ПРОСТО МЫТЬСЯ ПОШЁЛ
// А ВОТ ЩА ДОДЕЛАЮ
// апд 01:00 по мск доделал фронт вроде!!!!
if(!$id) if(!$id)
$this->notFound(); $this->notFound();
if($_SERVER["REQUEST_METHOD"] === "POST") { if($_SERVER["REQUEST_METHOD"] === "POST") {
if(empty($this->postParam("name"))) { if(empty($this->postParam("type")) && empty($this->postParam('id'))) {
$this->flashFail("err", tr("error"), tr("error_segmentation")); $this->flashFail("err", tr("error"), tr("error_segmentation"));
} }
$note = new Note; // At this moment, only Posts will be implemented
$note->setOwner($this->user->id); if($this->postParam("type") == 'posts') {
$note->setCreated(time()); $post = (new Posts)->get(intval($this->postParam("id")));
$note->setName($this->postParam("name")); if(!$post)
$note->setSource($this->postParam("html")); $this->flashFail("err", "Ага! Попался, гадёныш блядь!", "Нельзя отправить жалобу на несуществующий контент");
$note->save();
$postDublicate = $this->reports->getByContentId($post->getId());
$this->redirect("/note" . $this->user->id . "_" . $note->getId()); if($postDublicate)
$this->flashFail("err", tr("error"), "На этот контент уже пожаловался один из пользователей");
$report = new Report;
$report->setUser_id($this->user->id);
$note->setContent_id($this->postParam("id"));
$note->setReason($this->postParam("reason"));
$note->setCreated(time());
$note->setType($this->postParam("type"));
$note->save();
$this->flashFail("suc", "Жалоба отправлена", "Скоро её рассмотрят модераторы");
} else {
$this->flashFail("err", "Пока низя", "Нельзя отправить жалобу на данный тип контент");
}
} }
} }
function renderDelete(int $owner, int $id): void function renderBan(int $id): void
{ {
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
$this->assertNoCSRF(); $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
$note = $this->notes->get($id); $report = $this->report->get($id);
if(!$note) $this->notFound(); if(!$report) $this->notFound();
if($note->getOwner()->getId() . "_" . $note->getId() !== $owner . "_" . $id || $note->isDeleted()) $this->notFound(); if($note->isDeleted()) $this->notFound();
if(is_null($this->user) || !$note->canBeModifiedBy($this->user->identity)) if(is_null($this->user))
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
$name = $note->getName(); $report->banUser();
$note->delete(); $report->deleteContent();
$this->flash("succ", "Заметка удалена", "Заметка \"$name\" была успешно удалена."); $this->flash("suc", "Смэрть...", "Пользователь успешно забанен.");
$this->redirect("/notes" . $this->user->id); $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", "Нехай живе!", "Жалоба проигнорирована.");
$this->redirect("/report/list");
} }
} }