From 82a5aaf8b8a10f96fbc3b5a4268778feac20ab07 Mon Sep 17 00:00:00 2001 From: n1rwana <93197434+n1rwana@users.noreply.github.com> Date: Sun, 28 Aug 2022 15:04:10 +0300 Subject: [PATCH] upd --- Web/Models/Repositories/Blacklists.php | 9 +++++++-- Web/Presenters/BlacklistPresenter.php | 5 +++-- Web/Presenters/NotesPresenter.php | 6 +----- Web/Presenters/PhotosPresenter.php | 13 +++---------- Web/Presenters/UserPresenter.php | 21 +++++++-------------- Web/Presenters/VideosPresenter.php | 6 +----- 6 files changed, 22 insertions(+), 38 deletions(-) diff --git a/Web/Models/Repositories/Blacklists.php b/Web/Models/Repositories/Blacklists.php index cf267afe..66cce946 100644 --- a/Web/Models/Repositories/Blacklists.php +++ b/Web/Models/Repositories/Blacklists.php @@ -22,6 +22,11 @@ class Blacklists yield new BlacklistItem($blacklistItem); } + function getByAuthorAndTarget(int $author, int $target): ?BlacklistItem + { + return new BlacklistItem($this->blacklists->where(["author" => $author, "target" => $target])->fetch()); + } + function getCount(User $user): int { return sizeof($this->blacklists->where("author", $user->getId())->fetch()); @@ -32,6 +37,6 @@ class Blacklists if (!$author || !$target) return FALSE; - return sizeof(DB::i()->getContext()->table("blacklists")->where(["author" => $author->getId(), "target" => $target->getId()])->fetch()) > 0; + return !is_null($this->getByAuthorAndTarget($author->getId(), $target->getId())); } -} \ No newline at end of file +} diff --git a/Web/Presenters/BlacklistPresenter.php b/Web/Presenters/BlacklistPresenter.php index 74ec4a37..a9cb3752 100644 --- a/Web/Presenters/BlacklistPresenter.php +++ b/Web/Presenters/BlacklistPresenter.php @@ -34,9 +34,10 @@ final class BlacklistPresenter extends OpenVKPresenter $this->willExecuteWriteAction(); $this->assertUserLoggedIn(); - $record = new BlacklistItem(DB::i()->getContext()->table("blacklists")->where([ "author" => $this->user->identity->getId(), "target" => $this->postParam("id") ])->fetch()); + $record = $this->blacklists->getByAuthorAndTarget($this->user->identity->getId(), $this->postParam("id")); + //$record = new BlacklistItem(DB::i()->getContext()->table("blacklists")->where([ "author" => $this->user->identity->getId(), "target" => ])->fetch()); $name = $record->getTarget()->getCanonicalName(); - $record->delete(FALSE); + $record->delete(false); $this->flashFail("succ", "Успех", "$name удалён из чёрного списка."); } diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index d634631f..9cfc067f 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -18,12 +18,8 @@ final class NotesPresenter extends OpenVKPresenter { $user = (new Users)->get($owner); if(!$user) $this->notFound(); - if(!$user->getPrivacyPermission('notes.read', $this->user->identity ?? NULL)) { - if ((new Blacklists)->isBanned($user, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + if(!$user->getPrivacyPermission('notes.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } $this->template->notes = $this->notes->getUserNotes($user, (int)($this->queryParam("p") ?? 1)); $this->template->count = $this->notes->getUserNotesCount($user); diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 729b94a4..a3f482e5 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -24,12 +24,9 @@ final class PhotosPresenter extends OpenVKPresenter if($owner > 0) { $user = $this->users->get($owner); if(!$user) $this->notFound(); - if (!$user->getPrivacyPermission('photos.read', $this->user->identity ?? NULL)) { - if ((new Blacklists)->isBanned($user, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + if (!$user->getPrivacyPermission('photos.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } + $this->template->albums = $this->albums->getUserAlbums($user, $this->queryParam("p") ?? 1); $this->template->count = $this->albums->getUserAlbumsCount($user); $this->template->owner = $user; @@ -147,12 +144,8 @@ final class PhotosPresenter extends OpenVKPresenter if($owner > 0 /* bc we currently don't have perms for clubs */) { $ownerObject = (new Users)->get($owner); - if(!$ownerObject->getPrivacyPermission('photos.read', $this->user->identity ?? NULL)) { - if ((new Blacklists)->isBanned($ownerObject, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + if(!$ownerObject->getPrivacyPermission('photos.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } } $this->template->album = $album; diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 40231677..1d8223f1 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -34,8 +34,9 @@ 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"]) + if (OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["blacklists"]["applyToAdmins"]) { $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); + } } else { $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); } @@ -56,11 +57,11 @@ final class UserPresenter extends OpenVKPresenter $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->blacklists = $this->blacklists; + $this->template->blacklists = (new Blacklists); $this->template->user = $user; - $this->template->isBlacklistedThem = $this->blacklists->isBanned($this->user->identity, $user); - $this->template->isBlacklistedByThem = $this->blacklists->isBanned($user, $this->user->identity); + $this->template->isBlacklistedThem = $this->template->blacklists->isBanned($this->user->identity, $user); + $this->template->isBlacklistedByThem = $this->template->blacklists->isBanned($user, $this->user->identity); } } @@ -72,12 +73,8 @@ final class UserPresenter extends OpenVKPresenter $page = abs($this->queryParam("p") ?? 1); if(!$user) $this->notFound(); - elseif (!$user->getPrivacyPermission('friends.read', $this->user->identity ?? NULL)) { - if ($this->blacklists->isBanned($user, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + elseif (!$user->getPrivacyPermission('friends.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } else $this->template->user = $user; @@ -104,12 +101,8 @@ final class UserPresenter extends OpenVKPresenter $user = $this->users->get($id); if(!$user) $this->notFound(); - elseif (!$user->getPrivacyPermission('groups.read', $this->user->identity ?? NULL)) { - if ($this->blacklists->isBanned($user, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + elseif (!$user->getPrivacyPermission('groups.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } else { if($this->queryParam("act") === "managed" && $this->user->id !== $user->getId()) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php index dd4586a9..b2f40bd1 100644 --- a/Web/Presenters/VideosPresenter.php +++ b/Web/Presenters/VideosPresenter.php @@ -21,12 +21,8 @@ final class VideosPresenter extends OpenVKPresenter { $user = $this->users->get($id); if(!$user) $this->notFound(); - if(!$user->getPrivacyPermission('videos.read', $this->user->identity ?? NULL)) { - if ((new Blacklists)->isBanned($user, $this->user->identity)) - $this->flashFail("err", tr("forbidden"), "Пользователь внёс Вас в чёрный список."); - + if(!$user->getPrivacyPermission('videos.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - } $this->template->user = $user; $this->template->videos = $this->videos->getByUser($user, (int) ($this->queryParam("p") ?? 1));