Added restrictions in the users.get method

This commit is contained in:
n1rwana 2022-08-28 19:08:54 +03:00
parent 82a5aaf8b8
commit 0c65856108

View file

@ -2,6 +2,7 @@
namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Repositories\Users as UsersRepo;
use openvk\Web\Models\Repositories\Blacklists;
final class Users extends VKAPIRequestHandler
{
@ -40,13 +41,14 @@ final class Users extends VKAPIRequestHandler
"id" => $usr->getId(),
"first_name" => $usr->getFirstName(),
"last_name" => $usr->getLastName(),
"is_closed" => false,
"can_access_closed" => true,
"is_closed" => (new Blacklists)->isBanned($usr, $authuser),
"can_access_closed" => !(new Blacklists)->isBanned($usr, $authuser),
];
$flds = explode(',', $fields);
foreach($flds as $field) {
if (!(new Blacklists)->isBanned($usr, $authuser))
foreach($flds as $field) {
switch($field) {
case "verified":
$response[$i]->verified = intval($usr->isVerified());
@ -134,6 +136,7 @@ final class Users extends VKAPIRequestHandler
}
}
if (!(new Blacklists)->isBanned($usr, $authuser))
if($usr->getOnline()->timestamp() + 300 > time())
$response[$i]->online = 1;
else
@ -154,7 +157,13 @@ final class Users extends VKAPIRequestHandler
$this->requireUser();
foreach($users->get($user_id)->getFollowers($offset, $count) as $follower)
$authuser = $this->getUser();
$target = $users->get($user_id);
if ((new Blacklists)->isBanned($target, $authuser))
$this->fail(15, "Access denied: User is blacklisted");
foreach($target->getFollowers($offset, $count) as $follower)
$followers[] = $follower->getId();
$response = $followers;
@ -163,7 +172,7 @@ final class Users extends VKAPIRequestHandler
$response = $this->get(implode(',', $followers), $fields, 0, $count);
return (object) [
"count" => $users->get($user_id)->getFollowersCount(),
"count" => $target->getFollowersCount(),
"items" => $response
];
}