mirror of
https://github.com/openvk/openvk
synced 2025-04-23 00:23:01 +03:00
Fix getting voters in anonymous posts and use c...
...anBeEditedBy instead of checking user's id
This commit is contained in:
parent
b700627123
commit
cb7d491413
4 changed files with 31 additions and 5 deletions
|
@ -114,6 +114,9 @@ final class Polls extends VKAPIRequestHandler
|
|||
if(!$poll)
|
||||
$this->fail(251, "Invalid poll");
|
||||
|
||||
if($poll->isAnonymous())
|
||||
$this->fail(251, "Access denied: poll is anonymous.");
|
||||
|
||||
$voters = array_slice($poll->getVoters($answer_ids, 1, $offset + $count), $offset);
|
||||
$res = (object)[
|
||||
"answer_id" => $answer_ids,
|
||||
|
|
|
@ -120,7 +120,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
"post_type" => "post",
|
||||
"text" => $post->getText(false),
|
||||
"copy_history" => $repost,
|
||||
"can_edit" => $post->getOwner(false)->getId() == $this->getUser()->getId(),
|
||||
"can_edit" => $post->canBeEditedBy($this->getUser()),
|
||||
"can_delete" => $post->canBeDeletedBy($this->getUser()),
|
||||
"can_pin" => $post->canBePinnedBy($this->getUser()),
|
||||
"can_archive" => false, # TODO MAYBE
|
||||
|
@ -295,7 +295,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
"post_type" => "post",
|
||||
"text" => $post->getText(false),
|
||||
"copy_history" => $repost,
|
||||
"can_edit" => $post->getOwner(false)->getId() == $this->getUser()->getId(),
|
||||
"can_edit" => $post->canBeEditedBy($this->getUser()),
|
||||
"can_delete" => $post->canBeDeletedBy($user),
|
||||
"can_pin" => $post->canBePinnedBy($user),
|
||||
"can_archive" => false, # TODO MAYBE
|
||||
|
@ -805,7 +805,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
if(empty($message) && empty($attachments))
|
||||
$this->fail(100, "Required parameter 'message' missing.");
|
||||
|
||||
if($post->getOwner(false)->getId() != $this->getUser()->getId())
|
||||
if(!$post->canBeEditedBy($this->getUser()))
|
||||
$this->fail(7, "Access to editing denied");
|
||||
|
||||
if(!empty($message))
|
||||
|
@ -814,6 +814,7 @@ final class Wall extends VKAPIRequestHandler
|
|||
$post->setEdited(time());
|
||||
$post->save(true);
|
||||
|
||||
# todo добавить такое в веб версию
|
||||
if(!empty($attachments)) {
|
||||
$attachs = parseAttachments($attachments);
|
||||
$newAttachmentsCount = sizeof($attachs);
|
||||
|
@ -849,8 +850,8 @@ final class Wall extends VKAPIRequestHandler
|
|||
if(!$comment || $comment->isDeleted())
|
||||
$this->fail(102, "Invalid comment");
|
||||
|
||||
if($comment->getOwner()->getId() != $this->getUser()->getId())
|
||||
$this->fail(15, "Access to comment denied");
|
||||
if(!$comment->canBeEditedBy($this->getUser()))
|
||||
$this->fail(15, "Access to editing comment denied");
|
||||
|
||||
if(!empty($message))
|
||||
$comment->setContent($message);
|
||||
|
|
|
@ -103,4 +103,12 @@ class Comment extends Post
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function canBeEditedBy(?User $user = NULL): bool
|
||||
{
|
||||
if(!$user)
|
||||
return false;
|
||||
|
||||
return $user->getId() == $this->getOwner(false)->getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,6 +262,20 @@ class Post extends Postable
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function canBeEditedBy(?User $user = NULL): bool
|
||||
{
|
||||
if(!$user)
|
||||
return false;
|
||||
|
||||
if($this->isDeactivationMessage() || $this->isUpdateAvatarMessage())
|
||||
return false;
|
||||
|
||||
if($this->getTargetWall() > 0)
|
||||
return $this->getPublicationTime()->timestamp() + WEEK > time() && $user->getId() == $this->getOwner(false)->getId();
|
||||
|
||||
return $user->getId() == $this->getOwner(false)->getId();
|
||||
}
|
||||
|
||||
use Traits\TRichText;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue