From d25c2ee183d2904359169228d959b376bcfe57b4 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Thu, 20 Jul 2023 02:35:09 +0300 Subject: [PATCH] Blacklists: Make it barely work (xd) --- Web/Models/Entities/BlacklistItem.php | 2 ++ Web/Models/Repositories/Blacklists.php | 9 ++++++++- Web/Presenters/UserPresenter.php | 10 +++++----- Web/Presenters/templates/User/View.xml | 2 +- install/sqls/00038-blacklist.sql | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Web/Models/Entities/BlacklistItem.php b/Web/Models/Entities/BlacklistItem.php index fcc19452..cf147798 100644 --- a/Web/Models/Entities/BlacklistItem.php +++ b/Web/Models/Entities/BlacklistItem.php @@ -28,4 +28,6 @@ class BlacklistItem extends RowModel { return new DateTime($this->getRecord()->created); } + + } \ No newline at end of file diff --git a/Web/Models/Repositories/Blacklists.php b/Web/Models/Repositories/Blacklists.php index 66cce946..50fb9d70 100644 --- a/Web/Models/Repositories/Blacklists.php +++ b/Web/Models/Repositories/Blacklists.php @@ -24,7 +24,11 @@ class Blacklists function getByAuthorAndTarget(int $author, int $target): ?BlacklistItem { - return new BlacklistItem($this->blacklists->where(["author" => $author, "target" => $target])->fetch()); + $fetch = $this->blacklists->where(["author" => $author, "target" => $target])->fetch(); + if ($fetch) + return new BlacklistItem($fetch); + else + return null; } function getCount(User $user): int @@ -37,6 +41,9 @@ class Blacklists if (!$author || !$target) return FALSE; + bdump($this->getByAuthorAndTarget($author->getId(), $target->getId()), "хуита какая-то вроде для бл*клиста"); + + return !is_null($this->getByAuthorAndTarget($author->getId(), $target->getId())); } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 4eca5038..3dd4c9d0 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -34,14 +34,14 @@ final class UserPresenter extends OpenVKPresenter if ($this->user->identity) if ($this->blacklists->isBanned($user, $this->user->identity)) { - if ($this->user->identity->isAdmin()) { - if (OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["blacklists"]["applyToAdmins"]) { - $this->flashFail("err", tr("forbidden"), tr("user_blacklisted_you")); - } - } else { + if ($this->user->identity->isAdmin()) { + if (OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["blacklists"]["applyToAdmins"]) { $this->flashFail("err", tr("forbidden"), tr("user_blacklisted_you")); } + } else { + $this->flashFail("err", tr("forbidden"), tr("user_blacklisted_you")); } + } if(!$user || $user->isDeleted()) { if(!is_null($user) && $user->isDeactivated()) { diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index 9ab1a1eb..295825cb 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -394,7 +394,7 @@
- {admin_privacy_warning}: + {_admin_privacy_warning}:
{_user_blacklisted_you}
diff --git a/install/sqls/00038-blacklist.sql b/install/sqls/00038-blacklist.sql index b728239b..b78158ed 100644 --- a/install/sqls/00038-blacklist.sql +++ b/install/sqls/00038-blacklist.sql @@ -2,6 +2,6 @@ CREATE TABLE `blacklists` ( `index` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, `author` BIGINT UNSIGNED NOT NULL, `target` BIGINT UNSIGNED NOT NULL, - `created` DATETIME NOT NULL, + `created` BIGINT UNSIGNED NOT NULL, PRIMARY KEY (`index`) ) ENGINE = InnoDB;