Reports: Still makin it...

This commit is contained in:
veselcraft 2021-09-25 16:59:18 +03:00
parent d715fa9575
commit 5380ad1b27
8 changed files with 101 additions and 57 deletions

View file

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

View file

@ -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();

View file

@ -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,18 +73,19 @@ 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);
if($this->postParam("ban")) {
$report = $this->report->get($id);
if(!$report) $this->notFound();
if($note->isDeleted()) $this->notFound();
@ -98,15 +95,7 @@ final class ReportPresenter extends OpenVKPresenter
$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);
}else if($this->postParam("delete")){
$report = $this->report->get($id);
if(!$report) $this->notFound();
if($note->isDeleted()) $this->notFound();
@ -115,23 +104,16 @@ final class ReportPresenter extends OpenVKPresenter
$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);
}else if($this->postParam("ignore")){
$report = $this->report->get($id);
if(!$report) $this->notFound();
if($note->isDeleted()) $this->notFound();
if($report->isDeleted()) $this->notFound();
if(is_null($this->user))
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
$report->delete();
$report->setDeleted();
$this->flash("suc", "Нехай живе!", "Жалоба проигнорирована.");
}
$this->redirect("/report/list");
}
}

View file

@ -160,6 +160,7 @@
{/if}
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
<a href="/support/tickets" class="link">Helpdesk</a>
<a href="/admin/reports" class="link">Reports</a>
{/if}
<a
n:foreach="OPENVK_ROOT_CONF['openvk']['preferences']['menu']['links'] as $menuItem"

View file

@ -0,0 +1,31 @@
{extends "../@listView.xml"}
{var iterator = iterator_to_array($reports)}
{var page = $paginatorConf->page}
{block title}Список жалоб{/block}
{block header}
Список жалоб
{/block}
{block actions}
{/block}
{* BEGIN ELEMENTS DESCRIPTION *}
{block link|strip|stripHtml}
/admin/report{$x->getId()}
{/block}
{block preview}
<center><img src="/assets/packages/static/openvk/img/note_icon.png" alt="" style="margin-top: 17px;" /></center>
{/block}
{block name}
{$x->getReason()}
{/block}
{block description}
Текст поста: {$x->getContentObject()->getText()}
{/block}

View file

@ -0,0 +1,22 @@
{extends "../@layout.xml"}
{block title}{$report->getReason()}{/block}
{block header}
<a href="/admin/reports">Список репортов</a>
»
Жалоба №{$report->getId()}
{/block}
{block content}
<p><b>Комментарий: </b>{$report->getReason()}</p>
{include "../components/post/oldpost.xml", post => $report->getContentObject()}
<center>
<form action="/admin/reportAction{$report->getId()}">
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" name="ban" value="Забанить пользователя" class="button">
<input type="submit" name="delete" value="Удалить контент" class="button">
<input type="submit" name="ignore" value="Проигнорировать" class="button">
</form>
</center>
{/block}

View file

@ -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

View file

@ -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"