Users: Allow admins to easily unban users

This commit is contained in:
Ilya Prokopenko 2022-03-27 09:41:48 +03:00
parent 6588734caa
commit 6538f0ccd2
No known key found for this signature in database
GPG key ID: 7736BBBB05F14A56
6 changed files with 44 additions and 2 deletions

View file

@ -346,7 +346,20 @@ final class AdminPresenter extends OpenVKPresenter
exit(json_encode([ "error" => "User does not exist" ])); exit(json_encode([ "error" => "User does not exist" ]));
$user->ban($this->queryParam("reason")); $user->ban($this->queryParam("reason"));
exit(json_encode([ "reason" => $this->queryParam("reason") ])); exit(json_encode([ "success" => true, "reason" => $this->queryParam("reason") ]));
}
function renderQuickUnban(int $id): void
{
$this->assertNoCSRF();
$user = $this->users->get($id);
if(!$user)
exit(json_encode([ "error" => "User does not exist" ]));
$user->setBlock_Reason(null);
$user->save();
exit(json_encode([ "success" => true ]));
} }
function renderQuickWarn(int $id): void function renderQuickWarn(int $id): void

View file

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

View file

@ -4,4 +4,29 @@
{tr("user_banned", htmlentities($user->getFirstName()))|noescape}<br/> {tr("user_banned", htmlentities($user->getFirstName()))|noescape}<br/>
{_"user_banned_comment"} <b>{$user->getBanReason()}</b>. {_"user_banned_comment"} <b>{$user->getBanReason()}</b>.
</p> </p>
<p n:if="isset($thisUser) && $thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL)">
<br/><a href="javascript:toggleUnbanUser()" class="button">{_unban_user_action}</a>
</p>
</center> </center>
<script n:if="isset($thisUser) && $thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL)">
function toggleUnbanUser() {
uUnbanMsgTxt = "Вы собираетесь разбанить пользователя " + {$user->getCanonicalName()} + ".";
uUnbanMsgTxt += "<br/>Сейчас он заблокирован по причине: <strong>" + {$user->getBanReason()} + "</strong>.";
MessageBox("Разбанить " + {$user->getFirstName()}, uUnbanMsgTxt, ["Подтвердить", "Отмена"], [
(function() {
xhr = new XMLHttpRequest();
xhr.open("GET", "/admin/unban/" + {$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>

View file

@ -271,6 +271,8 @@ routes:
handler: "Admin->gifts" handler: "Admin->gifts"
- url: "/admin/ban/{num}" - url: "/admin/ban/{num}"
handler: "Admin->quickBan" handler: "Admin->quickBan"
- url: "/admin/unban/{num}"
handler: "Admin->quickUnban"
- url: "/admin/warn/{num}" - url: "/admin/warn/{num}"
handler: "Admin->quickWarn" handler: "Admin->quickWarn"
- url: "/admin/support/ban/{num}" - url: "/admin/support/ban/{num}"

View file

@ -834,6 +834,7 @@
"manage_user_action" = "Manage user"; "manage_user_action" = "Manage user";
"manage_group_action" = "Manage group"; "manage_group_action" = "Manage group";
"ban_user_action" = "Ban user"; "ban_user_action" = "Ban user";
"unban_user_action" = "Unban user";
"warn_user_action" = "Warn user"; "warn_user_action" = "Warn user";
"ban_in_support_user_action" = "Ban in support"; "ban_in_support_user_action" = "Ban in support";
"unban_in_support_user_action" = "Unban in support"; "unban_in_support_user_action" = "Unban in support";

View file

@ -877,6 +877,7 @@
"manage_user_action" = "Управление пользователем"; "manage_user_action" = "Управление пользователем";
"manage_group_action" = "Управление группой"; "manage_group_action" = "Управление группой";
"ban_user_action" = "Заблокировать пользователя"; "ban_user_action" = "Заблокировать пользователя";
"unban_user_action" = "Разблокировать пользователя";
"warn_user_action" = "Предупредить пользователя"; "warn_user_action" = "Предупредить пользователя";
"ban_in_support_user_action" = "Заблокировать в поддержке"; "ban_in_support_user_action" = "Заблокировать в поддержке";
"unban_in_support_user_action" = "Разблокировать в поддержке"; "unban_in_support_user_action" = "Разблокировать в поддержке";