Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ServiceAPI/Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getNote(int $noteId, callable $resolve, callable $reject): void
$resolve([
"title" => $note->getName(),
"link" => "/note" . $note->getPrettyId(),
"html" => $note->getText(),
"html" => $note->getText($this->user),
"created" => (string) $note->getPublicationTime(),
"author" => [
"name" => $noteOwner->getCanonicalName(),
Expand Down
83 changes: 28 additions & 55 deletions VKAPI/Handlers/Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use openvk\Web\Models\Repositories\Comments as CommentsRepo;
use openvk\Web\Models\Repositories\Photos as PhotosRepo;
use openvk\Web\Models\Repositories\Videos as VideosRepo;
use openvk\Web\Models\Entities\{Note, Comment};
use openvk\Web\Models\Entities\{Note, Comment, User};

final class Notes extends VKAPIRequestHandler
{
Expand Down Expand Up @@ -45,24 +45,9 @@ public function createComment(int $note_id, int $owner_id, string $message, stri
}

$note = (new NotesRepo())->getNoteById($owner_id, $note_id);
$this->assertNoteAccessible($note);

if (!$note) {
$this->fail(15, "Access denied");
}

if ($note->isDeleted()) {
$this->fail(15, "Access denied");
}

if ($note->getOwner()->isDeleted()) {
$this->fail(15, "Access denied");
}

if (!$note->canBeViewedBy($this->getUser())) {
$this->fail(15, "Access denied");
}

if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
if (!$note->canBeCommentedBy($this->getUser())) {
$this->fail(15, "Access denied");
}

Expand Down Expand Up @@ -186,26 +171,7 @@ public function getById(int $note_id, int $owner_id, bool $need_wiki = false)
$this->requireUser();

$note = (new NotesRepo())->getNoteById($owner_id, $note_id);

if (!$note) {
$this->fail(15, "Access denied");
}

if ($note->isDeleted()) {
$this->fail(15, "Access denied");
}

if (!$note->getOwner() || $note->getOwner()->isDeleted()) {
$this->fail(15, "Access denied");
}

if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
$this->fail(15, "Access denied");
}

if (!$note->canBeViewedBy($this->getUser())) {
$this->fail(15, "Access denied");
}
$this->assertNoteAccessible($note);

return $note->toVkApiStruct();
}
Expand All @@ -215,36 +181,43 @@ public function getComments(int $note_id, int $owner_id, int $sort = 1, int $off
$this->requireUser();

$note = (new NotesRepo())->getNoteById($owner_id, $note_id);
$this->assertNoteAccessible($note);

if (!$note) {
$this->fail(15, "Access denied");
}
$arr = (object) [
"count" => $note->getCommentsCount(),
"items" => []];
$comments = array_slice(iterator_to_array($note->getComments(1, $count + $offset)), $offset);

if ($note->isDeleted()) {
$this->fail(15, "Access denied");
foreach ($comments as $comment) {
$arr->items[] = $comment->toVkApiStruct($this->getUser(), false, false, $note);
}

if (!$note->getOwner()) {
$this->fail(15, "Access denied");
}
return $arr;
}

if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
private function assertNoteAccessible(?Note $note): void
{
if (!$note || $note->isDeleted()) {
$this->fail(15, "Access denied");
}

if (!$note->canBeViewedBy($this->getUser())) {
$owner = $note->getOwner();
if (!$owner) {
$this->fail(15, "Access denied");
}

$arr = (object) [
"count" => $note->getCommentsCount(),
"items" => []];
$comments = array_slice(iterator_to_array($note->getComments(1, $count + $offset)), $offset);
if ($owner instanceof User) {
if ($owner->isDeleted()) {
$this->fail(15, "Access denied");
}

foreach ($comments as $comment) {
$arr->items[] = $comment->toVkApiStruct($this->getUser(), false, false, $note);
if (!$owner->getPrivacyPermission("notes.read", $this->getUser())) {
$this->fail(15, "Access denied");
}
}

return $arr;
if (!$note->canBeViewedBy($this->getUser())) {
$this->fail(15, "Access denied");
}
}
}
49 changes: 49 additions & 0 deletions Web/Models/Entities/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Club extends RowModel
public const WALL_OPEN = 1;
public const WALL_LIMITED = 2;

public const PAGES_DISABLED = 0;
public const PAGES_OPEN = 1;
public const PAGES_LIMITED = 2;

public function getId(): int
{
return $this->getRecord()->id;
Expand Down Expand Up @@ -524,6 +528,51 @@ public function canUploadDocs(?User $user): bool
return $this->canBeModifiedBy($user);
}

public function getPagesType(): int
{
return (int) ($this->getRecord()->pages ?? 0);
}

public function isPagesEnabled(): bool
{
return $this->getPagesType() !== self::PAGES_DISABLED;
}

public function setPages(int $type): void
{
if ($type > 2 || $type < 0) {
throw new \LogicException("Invalid pages");
}

$this->stateChanges("pages", $type);
}

public function canManagePages(?User $user): bool
{
if (!$user) {
return false;
}

return $this->isPagesEnabled() && $this->canBeModifiedBy($user);
}

public function canCreatePages(?User $user): bool
{
if (!$user || !$this->isPagesEnabled()) {
return false;
}

if ($this->canBeModifiedBy($user)) {
return true;
}

if ($this->getPagesType() === self::PAGES_OPEN) {
return (bool) $this->getSubscriptionStatus($user);
}

return false;
}

public function getAudiosCollectionSize()
{
return (new \openvk\Web\Models\Repositories\Audios())->getClubCollectionSize($this);
Expand Down
Loading