From af6eeb882ce01dfdf41828a4fcbc7e86e8040876 Mon Sep 17 00:00:00 2001 From: Alma Armas Date: Fri, 17 Jul 2020 16:26:59 +0000 Subject: [PATCH] Add quickban button for admins --- Web/Models/Entities/User.php | 15 +++++++++++++ Web/Presenters/AdminPresenter.php | 14 +++++++++++- Web/Presenters/templates/User/View.xml | 30 ++++++++++++++++++++++++++ Web/routes.yml | 2 ++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index af6d443a..07ca6dee 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -517,6 +517,21 @@ class User extends RowModel return !is_null($this->getPendingPhoneVerification()); } + function ban(string $reason): void + { + $subs = DatabaseConnection::i()->getContext()->table("subscriptions"); + $subs = $subs->where( + "follower = ? OR (target = ? AND model = ?)", + $this->getId(), + $this->getId(), + get_class($this), + ); + $subs->delete(); + + $this->setBlock_Reason($reason); + $this->save(); + } + function verifyNumber(string $code): bool { $ver = $this->getPendingPhoneVerification(); diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index 61f79659..808c64aa 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -27,7 +27,9 @@ final class AdminPresenter extends OpenVKPresenter function onStartup(): void { - exit("Не реализовано..."); + parent::onStartup(); + + $this->assertPermission("admin", "access", -1); } function renderIndex(): void @@ -82,4 +84,14 @@ final class AdminPresenter extends OpenVKPresenter { } + + function renderQuickBan(int $id): void + { + $user = $this->users->get($id); + if(!$user) + exit(json_encode([ "error" => "User does not exist" ])); + + $user->ban($this->queryParam("reason")); + exit(json_encode([ "reason" => $this->queryParam("reason") ])); + } } diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index bc5f99e4..3b884011 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -72,6 +72,12 @@ {/if} + {if $thisUser->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL)} + + Забанить пользователя + + {/if} + {var subStatus = $user->getSubscriptionStatus($thisUser)} {if $subStatus === 0}
@@ -445,6 +451,30 @@ {presenter "openvk!Wall->wall", $user->getId()} + + {/if} diff --git a/Web/routes.yml b/Web/routes.yml index 3409ba1c..8d1c440f 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -191,6 +191,8 @@ routes: handler: "Admin->clubs" - url: "/admin/clubs/id{num}" handler: "Admin->club" + - url: "/admin/ban.pl/{num}" + handler: "Admin->quickBan" - url: "/sandbox_cocksex" handler: "About->sandbox" - url: "/{?shortCode}"