Skip to content

Commit

Permalink
Blacklists: Make it barely work (xd)
Browse files Browse the repository at this point in the history
  • Loading branch information
veselcraft committed Jul 19, 2023
1 parent dda86b1 commit d25c2ee
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Web/Models/Entities/BlacklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ function getCreationDate(): DateTime
{
return new DateTime($this->getRecord()->created);
}


}
9 changes: 8 additions & 1 deletion Web/Models/Repositories/Blacklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ function getList(User $user, $page = 1): \Traversable

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
Expand All @@ -37,6 +41,9 @@ function isBanned(User $author, User $target): bool
if (!$author || !$target)
return FALSE;

bdump($this->getByAuthorAndTarget($author->getId(), $target->getId()), "хуита какая-то вроде для бл*клиста");


return !is_null($this->getByAuthorAndTarget($author->getId(), $target->getId()));
}
}
10 changes: 5 additions & 5 deletions Web/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ function renderView(int $id): void

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()) {
Expand Down
2 changes: 1 addition & 1 deletion Web/Presenters/templates/User/View.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
<div class="right_big_block">
<div class="page_info">
<div n:if="$isBlacklistedByThem AND $thisUser->isAdmin() AND $thisUser->getId() !== $user->getId()" class="user-alert">
<b>{admin_privacy_warning}:</b>
<b>{_admin_privacy_warning}:</b>
<br/>
{_user_blacklisted_you}
</div>
Expand Down
2 changes: 1 addition & 1 deletion install/sqls/00038-blacklist.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit d25c2ee

Please sign in to comment.