Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): allow admin to view deleted content #957

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Web/Models/Entities/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ function toVkApiStruct(?User $user = NULL, bool $need_covers = false, bool $phot

return $res;
}

function getURL(): string
{
return "/album" . $this->getPrettyId();
}
}
5 changes: 5 additions & 0 deletions Web/Models/Entities/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,9 @@ function toVkApiStruct(): object

return $res;
}

function getURL(): string
{
return "/note" . $this->getPrettyId();
}
}
5 changes: 5 additions & 0 deletions Web/Models/Entities/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ function deletePost(): void
$this->unwire();
$this->save();
}

function getURL(): string
{
return "/wall" . $this->getPrettyId();
}

use Traits\TRichText;
}
5 changes: 5 additions & 0 deletions Web/Models/Entities/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ function isAd(): bool /* Эх, костыли... */
return false;
}

function getURL(): string
{
return "/support/reply/" . $this->getId();
}

use Traits\TRichText;
}
5 changes: 5 additions & 0 deletions Web/Models/Entities/TicketComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,10 @@ function isDeleted(): bool
return (bool) $this->getRecord()->deleted;
}

function getURL(): string
{
return "/support/reply/" . $this->getTicket()->getId();
}

use Traits\TRichText;
}
3 changes: 3 additions & 0 deletions Web/Models/Entities/Video.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php declare(strict_types=1);
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\Exceptions\{ShellUnavailableException, UnknownCommandException};
use openvk\Web\Models\VideoDrivers\VideoDriver;
Expand Down Expand Up @@ -197,6 +199,7 @@ function isDeleted(): bool

function deleteVideo(): void
{
(new Logs)->create(CurrentUser::i()->getUser()->getChandlerGUID(), "videos", get_class($this), 2, $this, ["deleted" => 1]);
$this->setDeleted(1);
$this->unwire();
$this->save();
Expand Down
5 changes: 5 additions & 0 deletions Web/Models/Repositories/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function getByChandlerUser(?ChandlerUser $user): ?User
{
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
{
Expand Down
5 changes: 4 additions & 1 deletion Web/Presenters/NotesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ function renderList(int $owner): void
function renderView(int $owner, int $note_id): void
{
$note = $this->notes->getNoteById($owner, $note_id);
if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted())
if(!$note || $note->getOwner()->getId() !== $owner)
$this->notFound();

$this->assertCanViewDeleted($note);

if(!$note->getOwner()->getPrivacyPermission('notes.read', $this->user->identity ?? NULL))
$this->flashFail("err", tr("forbidden"), tr("forbidden_comment"));

Expand Down
14 changes: 14 additions & 0 deletions Web/Presenters/OpenVKPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Chandler\Security\Authenticator;
use Latte\Engine as TemplatingEngine;
use openvk\Web\Models\Entities\IP;
use openvk\Web\Models\RowModel;
use openvk\Web\Themes\Themepacks;
use openvk\Web\Models\Repositories\{IPs, Users, APITokens, Tickets, Reports, CurrentUser};
use WhichBrowser;
Expand Down Expand Up @@ -148,6 +149,19 @@ protected function willExecuteWriteAction(bool $json = false): void
$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", "Обратите внимание", "Вы просматриваете удаленный контент. Его видят только администраторы");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n?

}
} else {
$this->notFound();
}
}
}

protected function signal(object $event): bool
{
Expand Down
4 changes: 3 additions & 1 deletion Web/Presenters/PhotosPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ function renderAlbum(int $owner, int $id): void
{
$album = $this->albums->get($id);
if(!$album) $this->notFound();
if($album->getPrettyId() !== $owner . "_" . $id || $album->isDeleted())
if($album->getPrettyId() !== $owner . "_" . $id)
$this->notFound();

$this->assertCanViewDeleted($album);

if($owner > 0 /* bc we currently don't have perms for clubs */) {
$ownerObject = (new Users)->get($owner);
Expand Down
4 changes: 3 additions & 1 deletion Web/Presenters/SupportPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ function renderAnswerTicket(int $id): void
$this->assertPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0);
$ticket = $this->tickets->get($id);

if(!$ticket || $ticket->isDeleted() != 0)
if(!$ticket)
$this->notFound();

$this->assertCanViewDeleted($ticket);

$ticketComments = $this->comments->getCommentsById($id);
$this->template->ticket = $ticket;
$this->template->comments = $ticketComments;
Expand Down
6 changes: 4 additions & 2 deletions Web/Presenters/WallPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ function renderMakePost(int $wall): void
function renderPost(int $wall, int $post_id): void
{
$post = $this->posts->getPostById($wall, $post_id);
if(!$post || $post->isDeleted())
if(!$post)
$this->notFound();


$this->assertCanViewDeleted($post);

$this->logPostView($post, $wall);

$this->template->post = $post;
Expand Down
15 changes: 13 additions & 2 deletions Web/Presenters/templates/Admin/Logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,26 @@
<tr n:foreach="$logs as $log">
<td>{$log->getId()}</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>
<span n:if="$log->getObjectAvatar()" class="aui-avatar aui-avatar-xsmall">
<span class="aui-avatar-inner">
<img src="{$log->getObjectAvatar()}" alt="{$log->getObjectName()}" style="object-fit: cover;" role="presentation" />
</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>{_$log->getTypeNom()}</td>
<td>
Expand Down