From 6588734caae0bbeecd583afa2870b320e19e1454 Mon Sep 17 00:00:00 2001
From: Maxim Leshchenko
Date: Sat, 26 Mar 2022 21:48:42 +0100
Subject: [PATCH 1/4] Support: Allow agents to prevent users from creating
tickets
---
Web/Models/Entities/User.php | 10 ++++
Web/Presenters/SupportPresenter.php | 38 ++++++++++++++-
Web/Presenters/templates/Support/Index.xml | 30 ++++++++----
Web/Presenters/templates/User/View.xml | 57 +++++++++++++++++++++-
Web/routes.yml | 4 ++
install/sqls/00019-block-in-support.sql | 1 +
locales/en.strings | 5 ++
locales/ru.strings | 5 ++
8 files changed, 137 insertions(+), 13 deletions(-)
create mode 100644 install/sqls/00019-block-in-support.sql
diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php
index 64b689e4..c4888d75 100644
--- a/Web/Models/Entities/User.php
+++ b/Web/Models/Entities/User.php
@@ -214,6 +214,11 @@ class User extends RowModel
{
return $this->getRecord()->block_reason;
}
+
+ function getBanInSupportReason(): ?string
+ {
+ return $this->getRecord()->block_in_support_reason;
+ }
function getType(): int
{
@@ -673,6 +678,11 @@ class User extends RowModel
{
return !is_null($this->getBanReason());
}
+
+ function isBannedInSupport(): bool
+ {
+ return !is_null($this->getBanInSupportReason());
+ }
function isOnline(): bool
{
diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php
index a96ac465..9c2bcc8e 100644
--- a/Web/Presenters/SupportPresenter.php
+++ b/Web/Presenters/SupportPresenter.php
@@ -1,7 +1,7 @@
template->tickets = $this->tickets->getTicketsByUserId($this->user->id, $this->template->page);
}
+ if($this->template->mode === "new")
+ $this->template->banReason = $this->user->identity->getBanInSupportReason();
+
if($_SERVER["REQUEST_METHOD"] === "POST") {
+ if($this->user->identity->isBannedInSupport())
+ $this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment"));
+
if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) {
$this->willExecuteWriteAction();
@@ -268,4 +274,32 @@ final class SupportPresenter extends OpenVKPresenter
exit(header("HTTP/1.1 200 OK"));
}
-}
\ No newline at end of file
+
+ function renderQuickBanInSupport(int $id): void
+ {
+ $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0);
+ $this->assertNoCSRF();
+
+ $user = (new Users)->get($id);
+ if(!$user)
+ exit(json_encode([ "error" => "User does not exist" ]));
+
+ $user->setBlock_In_Support_Reason($this->queryParam("reason"));
+ $user->save();
+ $this->returnJson([ "success" => true, "reason" => $this->queryParam("reason") ]);
+ }
+
+ function renderQuickUnbanInSupport(int $id): void
+ {
+ $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0);
+ $this->assertNoCSRF();
+
+ $user = (new Users)->get($id);
+ if(!$user)
+ exit(json_encode([ "error" => "User does not exist" ]));
+
+ $user->setBlock_In_Support_Reason(null);
+ $user->save();
+ $this->returnJson([ "success" => true ]);
+ }
+}
diff --git a/Web/Presenters/templates/Support/Index.xml b/Web/Presenters/templates/Support/Index.xml
index 8f0f8737..133cf073 100644
--- a/Web/Presenters/templates/Support/Index.xml
+++ b/Web/Presenters/templates/Support/Index.xml
@@ -26,16 +26,26 @@
{if $isNew}
-
-
-
+ {if !is_null($banReason)}
+
+
+
+
+ {tr("banned_in_support_1", htmlentities($thisUser->getCanonicalName()))|noescape}
+ {tr("banned_in_support_2", htmlentities($banReason))|noescape}
+
+ {else}
+
+
+
+ {/if}
{/if}
{/if}
diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml
index f421925c..c9457cba 100644
--- a/Web/Presenters/templates/User/View.xml
+++ b/Web/Presenters/templates/User/View.xml
@@ -93,6 +93,16 @@
{_warn_user_action}
{/if}
+
+ {if $thisUser->getChandlerUser()->can('write')->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
+
+ {if $user->isBannedInSupport()}
+ {_unban_in_support_user_action}
+ {else}
+ {_ban_in_support_user_action}
+ {/if}
+
+ {/if}
{_send_gift}
{_"send_message"}
@@ -526,7 +536,7 @@
function warnUser() {
uBanMsgTxt = "Вы собираетесь предупредить пользователя " + {$user->getCanonicalName()} + ".";
uBanMsgTxt += "
Мы отправим уведомление пользователю в личные сообщения от имени аккаунта администратора.";
- uBanMsgTxt += "
Текст предупреждения: "
+ uBanMsgTxt += "
Текст предупреждения: ";
MessageBox("Выдать предупреждение " + {$user->getFirstName()}, uBanMsgTxt, ["Подтвердить", "Отмена"], [
(function() {
@@ -546,6 +556,51 @@
}
+
+
diff --git a/Web/routes.yml b/Web/routes.yml
index 2c22687f..a31bffad 100644
--- a/Web/routes.yml
+++ b/Web/routes.yml
@@ -271,6 +271,8 @@ routes:
handler: "Admin->gifts"
- url: "/admin/ban/{num}"
handler: "Admin->quickBan"
+ - url: "/admin/unban/{num}"
+ handler: "Admin->quickUnban"
- url: "/admin/warn/{num}"
handler: "Admin->quickWarn"
- url: "/admin/support/ban/{num}"
diff --git a/locales/en.strings b/locales/en.strings
index 5d138899..a305cbdd 100644
--- a/locales/en.strings
+++ b/locales/en.strings
@@ -834,6 +834,7 @@
"manage_user_action" = "Manage user";
"manage_group_action" = "Manage group";
"ban_user_action" = "Ban user";
+"unban_user_action" = "Unban user";
"warn_user_action" = "Warn user";
"ban_in_support_user_action" = "Ban in support";
"unban_in_support_user_action" = "Unban in support";
diff --git a/locales/ru.strings b/locales/ru.strings
index cc98e2d8..0c71d919 100644
--- a/locales/ru.strings
+++ b/locales/ru.strings
@@ -877,6 +877,7 @@
"manage_user_action" = "Управление пользователем";
"manage_group_action" = "Управление группой";
"ban_user_action" = "Заблокировать пользователя";
+"unban_user_action" = "Разблокировать пользователя";
"warn_user_action" = "Предупредить пользователя";
"ban_in_support_user_action" = "Заблокировать в поддержке";
"unban_in_support_user_action" = "Разблокировать в поддержке";
From f1d923f5806455b067d407c93e137b07d1c51def Mon Sep 17 00:00:00 2001
From: Maxim Leshchenko
Date: Sun, 27 Mar 2022 11:58:29 +0200
Subject: [PATCH 3/4] Support: Allow agents to prevent banned users from
creating tickets
---
Web/Presenters/templates/User/banned.xml | 59 ++++++++++++++++++++++--
1 file changed, 56 insertions(+), 3 deletions(-)
diff --git a/Web/Presenters/templates/User/banned.xml b/Web/Presenters/templates/User/banned.xml
index f1e6f8c1..f0e7e661 100644
--- a/Web/Presenters/templates/User/banned.xml
+++ b/Web/Presenters/templates/User/banned.xml
@@ -4,13 +4,21 @@
{tr("user_banned", htmlentities($user->getFirstName()))|noescape}
{_"user_banned_comment"} {$user->getBanReason()}.
-
-
{_unban_user_action}
+
+
+ {_unban_user_action}
+
+ {if $user->isBannedInSupport()}
+ {_unban_in_support_user_action}
+ {else}
+ {_ban_in_support_user_action}
+ {/if}
+
+
+
From c55bb779ccfe36d47f5927d4f72c5fef1a955568 Mon Sep 17 00:00:00 2001
From: Maxim Leshchenko
Date: Sun, 27 Mar 2022 12:11:29 +0200
Subject: [PATCH 4/4] Users: Hide button to increase rating if display of
rating is disabled in settings Closes #504
---
Web/Presenters/templates/User/View.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml
index 7af04225..aaac140c 100644
--- a/Web/Presenters/templates/User/View.xml
+++ b/Web/Presenters/templates/User/View.xml
@@ -72,7 +72,7 @@
-