[API] Fix null user in Likes.isLiked + requireUser in some funcs + return 1 in Polls (#801)

* Fix returning 200 response for non-existing user

* requireUser in getCounters and createComment

* return 1, where it should in Polls API
This commit is contained in:
NoPlagiarism 2023-05-30 13:41:03 +05:00 committed by GitHub
parent 803a57ef4b
commit 12c41dcdd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 7 deletions

View file

@ -66,6 +66,8 @@ final class Account extends VKAPIRequestHandler
function getCounters(string $filter = ""): object function getCounters(string $filter = ""): object
{ {
$this->requireUser();
return (object) [ return (object) [
"friends" => $this->getUser()->getFollowersCount(), "friends" => $this->getUser()->getFollowersCount(),
"notifications" => $this->getUser()->getNotificationsCount(), "notifications" => $this->getUser()->getNotificationsCount(),

View file

@ -54,11 +54,7 @@ final class Likes extends VKAPIRequestHandler
case "post": case "post":
$user = (new UsersRepo)->get($user_id); $user = (new UsersRepo)->get($user_id);
if (is_null($user)) if (is_null($user))
return (object) [ $this->fail(100, "One of the parameters specified was missing or invalid: user not found");
"liked" => 0,
"copied" => 0,
"sex" => 0
];
$post = (new PostsRepo)->getPostById($owner_id, $item_id); $post = (new PostsRepo)->getPostById($owner_id, $item_id);
if (is_null($post)) if (is_null($post))

View file

@ -75,7 +75,7 @@ final class Polls extends VKAPIRequestHandler
try { try {
$poll->vote($this->getUser(), explode(",", $answers_ids)); $poll->vote($this->getUser(), explode(",", $answers_ids));
return 0; return 1;
} catch(AlreadyVotedException $ex) { } catch(AlreadyVotedException $ex) {
return 0; return 0;
} catch(PollLockedException $ex) { } catch(PollLockedException $ex) {
@ -97,7 +97,7 @@ final class Polls extends VKAPIRequestHandler
try { try {
$poll->revokeVote($this->getUser()); $poll->revokeVote($this->getUser());
return 0; return 1;
} catch(PollLockedException $ex) { } catch(PollLockedException $ex) {
$this->fail(15, "Access denied: Poll is locked or isn't revotable"); $this->fail(15, "Access denied: Poll is locked or isn't revotable");
} catch(InvalidOptionException $ex) { } catch(InvalidOptionException $ex) {