Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
24 changes: 24 additions & 0 deletions Web/Presenters/AdminPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,28 @@ function renderQuickWarn(int $id): void
$user->adminNotify("⚠️ " . $this->queryParam("message"));
exit(json_encode([ "message" => $this->queryParam("message") ]));
}

function renderQuickDeactivate(int $id): void
{
$this->assertNoCSRF();

$user = $this->users->get($id);
if(!$user)
exit(json_encode([ "error" => "User does not exist" ]));

$user->deactivate($this->queryParam("reason") ?? NULL);
exit(json_encode([ "success" => true ]));
}

function renderQuickRestore(int $id): void
{
$this->assertNoCSRF();

$user = $this->users->get($id);
if(!$user)
exit(json_encode([ "error" => "User does not exist" ]));

$user->reactivate();
exit(json_encode([ "success" => true ]));
}
}
38 changes: 24 additions & 14 deletions Web/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,34 @@ function __construct(Users $users)
function renderView(int $id): void
{
$user = $this->users->get($id);
if(!$user || $user->isDeleted()) {
if($user->isDeactivated()) {
$canViewDeleted = $this->user->identity->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL) && OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["adminsCanViewDeletedUsers"];

if ($user === NULL) {
$this->template->_template = "User/deleted.xml";

return;
}

if ($user->isDeleted() AND !$canViewDeleted) {
if ($user->isDeactivated()) {
$this->template->_template = "User/deactivated.xml";

$this->template->user = $user;
} else {
$this->template->_template = "User/deleted.xml";

return;
}
} else {
$this->template->albums = (new Albums)->getUserAlbums($user);
$this->template->albumsCount = (new Albums)->getUserAlbumsCount($user);
$this->template->videos = (new Videos)->getByUser($user, 1, 2);
$this->template->videosCount = (new Videos)->getUserVideosCount($user);
$this->template->notes = (new Notes)->getUserNotes($user, 1, 4);
$this->template->notesCount = (new Notes)->getUserNotesCount($user);

$this->template->user = $user;

$this->template->_template = "User/deleted.xml";

return;
}

$this->template->albums = (new Albums)->getUserAlbums($user);
$this->template->albumsCount = (new Albums)->getUserAlbumsCount($user);
$this->template->videos = (new Videos)->getByUser($user, 1, 2);
$this->template->videosCount = (new Videos)->getUserVideosCount($user);
$this->template->notes = (new Notes)->getUserNotes($user, 1, 4);
$this->template->notesCount = (new Notes)->getUserNotesCount($user);
$this->template->user = $user;
}

function renderFriends(int $id): void
Expand Down
51 changes: 50 additions & 1 deletion Web/Presenters/templates/User/View.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
src="/assets/packages/static/openvk/img/checkmark.png"
/>
<span n:if="isset($thisUser) && $user->getId() == $thisUser->getId()"><b>({_this_is_you})</b></span>

<b n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL) AND $user->isDeactivated()" style="color: red;">
[DELETED]
</b>

<!-- DEBUG: ONLINE REPORT: static {$user->getOnline()->timestamp()}s adjusted {$user->getOnline()->timestamp() + 2505600}s real {time()}s -->
<div n:if="$user->getOnline()->timestamp() + 2505600 > time()" style="float:right;">
{if $user->isOnline()}
Expand Down Expand Up @@ -92,6 +95,12 @@
<a href="javascript:warnUser()" class="profile_link">
{_warn_user_action}
</a>
<a n:if="!$user->isDeactivated()" href="javascript:deleteUser()" class="profile_link">
Удалить
</a>
<a n:if="$user->isDeactivated()" href="javascript:restoreDeleted()" class="profile_link">
Восстановить
</a>
{/if}

{if $thisUser->getChandlerUser()->can('write')->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
Expand Down Expand Up @@ -582,6 +591,46 @@
Function.noop
]);
}

function deleteUser() {
uDeleteMsgTxt = "Вы собираетесь удалить (деактивировать) страницу пользователя " + {$user->getCanonicalName()} + ".";
uDeleteMsgTxt += "<br/><br/><b>Причина удаления: <input type='text' id='uDeleteMsgInput' placeholder='придумайте что-нибудь крутое'/>";

MessageBox("Удалить пользователя", uDeleteMsgTxt, ["Подтвердить", "Отмена"], [
(function () {
res = document.querySelector("#uDeleteMsgInput").value;
xhr = new XMLHttpRequest();
xhr.open("GET", "/admin/deactivate/" + {$user->getId()} + "?reason=" + res + "&hash=" + {rawurlencode($csrfToken)}, true);
xhr.onload = (function () {
if(xhr.responseText.indexOf("success") === -1)
MessageBox("Ошибка", "Не удалось удалить пользователя...", ["OK"], [Function.noop]);
else
MessageBox("Операция успешна", "Пользователь удалён", ["OK"], [Function.noop]);
});
xhr.send(null);
}),
Function.noop
]);
}

function restoreDeleted() {
uRestoreMsgTxt = "Вы собираетесь восстановить страницу удалённого пользователя " + {$user->getCanonicalName()} + ".";

MessageBox("Восстановить страницу", uRestoreMsgTxt, ["Подтвердить", "Отмена"], [
(function() {
xhr = new XMLHttpRequest();
xhr.open("GET", "/admin/restore/" + {$user->getId()} + "?hash=" + {rawurlencode($csrfToken)}, true);
xhr.onload = (function() {
if(xhr.responseText.indexOf("success") === -1)
MessageBox("Ошибка", "Не удалось восстановить пользователя...", ["OK"], [Function.noop]);
else
MessageBox("Операция успешна", "Пользователь восстановлен", ["OK"], [Function.noop]);
});
xhr.send(null);
}),
Function.noop
]);
}
</script>

<script n:if="isset($thisUser) && $thisUser->getChandlerUser()->can('write')->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)">
Expand Down
4 changes: 4 additions & 0 deletions Web/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ routes:
handler: "Admin->quickUnban"
- url: "/admin/warn/{num}"
handler: "Admin->quickWarn"
- url: "/admin/deactivate/{num}"
handler: "Admin->quickDeactivate"
- url: "/admin/restore/{num}"
handler: "Admin->quickRestore"
- url: "/admin/support/ban/{num}"
handler: "Support->quickBanInSupport"
- url: "/admin/support/unban/{num}"
Expand Down
1 change: 1 addition & 0 deletions openvk-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ openvk:
maxViolations: 50
maxViolationsAge: 120
autoban: true
adminsCanViewDeletedUsers: false
registration:
enable: true
reason: "" # reason for disabling registration
Expand Down