Отображение пользователей и удаленного контента

This commit is contained in:
n1rwana 2023-08-11 19:19:19 +03:00
parent ee2e5e8d1c
commit a9332823b1
No known key found for this signature in database
GPG key ID: 184A60085ABF17D8
13 changed files with 74 additions and 7 deletions

View file

@ -93,4 +93,9 @@ class Album extends MediaCollection
return $res; return $res;
} }
function getURL(): string
{
return "/album" . $this->getPrettyId();
}
} }

View file

@ -138,4 +138,9 @@ class Note extends Postable
return $res; return $res;
} }
function getURL(): string
{
return "/note" . $this->getPrettyId();
}
} }

View file

@ -245,6 +245,11 @@ class Post extends Postable
$this->unwire(); $this->unwire();
$this->save(); $this->save();
} }
function getURL(): string
{
return "/wall" . $this->getPrettyId();
}
use Traits\TRichText; use Traits\TRichText;
} }

View file

@ -64,5 +64,10 @@ class Ticket extends RowModel
return false; return false;
} }
function getURL(): string
{
return "/support/reply/" . $this->getId();
}
use Traits\TRichText; use Traits\TRichText;
} }

View file

@ -132,5 +132,10 @@ class TicketComment extends RowModel
return (bool) $this->getRecord()->deleted; return (bool) $this->getRecord()->deleted;
} }
function getURL(): string
{
return "/support/reply/" . $this->getTicket()->getId();
}
use Traits\TRichText; use Traits\TRichText;
} }

View file

@ -1,5 +1,7 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace openvk\Web\Models\Entities; namespace openvk\Web\Models\Entities;
use Chandler\Database\Logs;
use openvk\Web\Models\Repositories\CurrentUser;
use openvk\Web\Util\Shell\Shell; use openvk\Web\Util\Shell\Shell;
use openvk\Web\Util\Shell\Shell\Exceptions\{ShellUnavailableException, UnknownCommandException}; use openvk\Web\Util\Shell\Shell\Exceptions\{ShellUnavailableException, UnknownCommandException};
use openvk\Web\Models\VideoDrivers\VideoDriver; use openvk\Web\Models\VideoDrivers\VideoDriver;
@ -197,6 +199,7 @@ class Video extends Media
function deleteVideo(): void function deleteVideo(): void
{ {
(new Logs)->create(CurrentUser::i()->getUser()->getChandlerGUID(), "videos", get_class($this), 2, $this, ["deleted" => 1]);
$this->setDeleted(1); $this->setDeleted(1);
$this->unwire(); $this->unwire();
$this->save(); $this->save();

View file

@ -48,6 +48,11 @@ class Users
{ {
return $user ? $this->toUser($this->users->where("user", $user->getId())->fetch()) : NULL; return $user ? $this->toUser($this->users->where("user", $user->getId())->fetch()) : NULL;
} }
function getByChandlerGUID(string $GUID): ?User
{
return $this->toUser($this->users->where("user", $GUID)->fetch());
}
function find(string $query, array $pars = [], string $sort = "id DESC"): Util\EntityStream function find(string $query, array $pars = [], string $sort = "id DESC"): Util\EntityStream
{ {

View file

@ -36,8 +36,11 @@ final class NotesPresenter extends OpenVKPresenter
function renderView(int $owner, int $note_id): void function renderView(int $owner, int $note_id): void
{ {
$note = $this->notes->getNoteById($owner, $note_id); $note = $this->notes->getNoteById($owner, $note_id);
if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted()) if(!$note || $note->getOwner()->getId() !== $owner)
$this->notFound(); $this->notFound();
$this->assertCanViewDeleted($note);
if(!$note->getOwner()->getPrivacyPermission('notes.read', $this->user->identity ?? NULL)) if(!$note->getOwner()->getPrivacyPermission('notes.read', $this->user->identity ?? NULL))
$this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); $this->flashFail("err", tr("forbidden"), tr("forbidden_comment"));

View file

@ -6,6 +6,7 @@ use Chandler\Session\Session;
use Chandler\Security\Authenticator; use Chandler\Security\Authenticator;
use Latte\Engine as TemplatingEngine; use Latte\Engine as TemplatingEngine;
use openvk\Web\Models\Entities\IP; use openvk\Web\Models\Entities\IP;
use openvk\Web\Models\RowModel;
use openvk\Web\Themes\Themepacks; use openvk\Web\Themes\Themepacks;
use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets, Reports, CurrentUser}; use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets, Reports, CurrentUser};
use WhichBrowser; use WhichBrowser;
@ -148,6 +149,19 @@ abstract class OpenVKPresenter extends SimplePresenter
$this->flashFail("err", tr("rate_limit_error"), tr("rate_limit_error_comment", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"], $res), NULL, $json); $this->flashFail("err", tr("rate_limit_error"), tr("rate_limit_error_comment", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"], $res), NULL, $json);
} }
} }
protected function assertCanViewDeleted(RowModel $object): void
{
if ($object->isDeleted()) {
if ($this->queryParam("del")) {
if ($this->assertPermission("admin", "access", -1)) {
$this->flash("warn", "Обратите внимание", "Вы просматриваете удаленный контент. Его видят только администраторы");
}
} else {
$this->notFound();
}
}
}
protected function signal(object $event): bool protected function signal(object $event): bool
{ {

View file

@ -134,8 +134,10 @@ final class PhotosPresenter extends OpenVKPresenter
{ {
$album = $this->albums->get($id); $album = $this->albums->get($id);
if(!$album) $this->notFound(); if(!$album) $this->notFound();
if($album->getPrettyId() !== $owner . "_" . $id || $album->isDeleted()) if($album->getPrettyId() !== $owner . "_" . $id)
$this->notFound(); $this->notFound();
$this->assertCanViewDeleted($album);
if($owner > 0 /* bc we currently don't have perms for clubs */) { if($owner > 0 /* bc we currently don't have perms for clubs */) {
$ownerObject = (new Users)->get($owner); $ownerObject = (new Users)->get($owner);

View file

@ -203,9 +203,11 @@ final class SupportPresenter extends OpenVKPresenter
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0); $this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
$ticket = $this->tickets->get($id); $ticket = $this->tickets->get($id);
if(!$ticket || $ticket->isDeleted() != 0) if(!$ticket)
$this->notFound(); $this->notFound();
$this->assertCanViewDeleted($ticket);
$ticketComments = $this->comments->getCommentsById($id); $ticketComments = $this->comments->getCommentsById($id);
$this->template->ticket = $ticket; $this->template->ticket = $ticket;
$this->template->comments = $ticketComments; $this->template->comments = $ticketComments;

View file

@ -343,9 +343,11 @@ final class WallPresenter extends OpenVKPresenter
function renderPost(int $wall, int $post_id): void function renderPost(int $wall, int $post_id): void
{ {
$post = $this->posts->getPostById($wall, $post_id); $post = $this->posts->getPostById($wall, $post_id);
if(!$post || $post->isDeleted()) if(!$post)
$this->notFound(); $this->notFound();
$this->assertCanViewDeleted($post);
$this->logPostView($post, $wall); $this->logPostView($post, $wall);
$this->template->post = $post; $this->template->post = $post;

View file

@ -53,7 +53,14 @@
<tr n:foreach="$logs as $log"> <tr n:foreach="$logs as $log">
<td>{$log->getId()}</td> <td>{$log->getId()}</td>
<td> <td>
<a href="/admin/chandler/user/{$log->getUser()}" target="_blank">{$log->getUser()}</a> {var $_user = (new openvk\Web\Models\Repositories\Users)->getByChandlerGUID($log->getUser())}
<span n:if="$_user->getAvatarURL('miniscule')" class="aui-avatar aui-avatar-xsmall">
<span class="aui-avatar-inner">
<img src="{$_user->getAvatarURL()}" alt="{$_user->getCanonicalName()}"
style="object-fit: cover;" role="presentation"/>
</span>
</span>
<a href="/admin/users/id{$_user->getId()}">{$_user->getCanonicalName()}</a>
</td> </td>
<td> <td>
<span n:if="$log->getObjectAvatar()" class="aui-avatar aui-avatar-xsmall"> <span n:if="$log->getObjectAvatar()" class="aui-avatar aui-avatar-xsmall">
@ -61,7 +68,11 @@
<img src="{$log->getObjectAvatar()}" alt="{$log->getObjectName()}" style="object-fit: cover;" role="presentation" /> <img src="{$log->getObjectAvatar()}" alt="{$log->getObjectName()}" style="object-fit: cover;" role="presentation" />
</span> </span>
</span> </span>
<a href="{$log->getObjectURL()}">{$log->getObjectName()}</a> <a
n:attr="href => ($log->getObjectURL()) . (($log->getTypeRaw() === 2 && $log->getObjectURL() !== '#') ? '?del=1' : '')"
>
{$log->getObjectName()}
</a>
</td> </td>
<td>{_$log->getTypeNom()}</td> <td>{_$log->getTypeNom()}</td>
<td> <td>