rootFolder->getUserFolder($this->userId); $file = $userFolder->getFirstNodeById($this->fileId); if ($file instanceof File && $file->getPermissions() & Constants::PERMISSION_UPDATE) { $this->file = $file; return $file; } $files = $userFolder->getById($this->fileId); if (empty($files)) { $this->logger->error('File not found', [ 'user_id' => $this->userId, 'file_id' => $this->fileId ]); throw new NotFoundException('File not found'); } usort($files, static function (Node $a, Node $b) { return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE); }); $file = $files[0]; if (!$file instanceof File) { $this->logger->error('Node is not a file', [ 'file_id' => $this->fileId, 'node_type' => get_class($file) ]); throw new NotFoundException('Not a file'); } if (!($file->getPermissions() & Constants::PERMISSION_READ)) { $this->logger->error('No read permission for file', [ 'file_id' => $this->fileId, 'permissions' => $file->getPermissions() ]); throw new NotPermittedException('No read permission'); } $this->file = $file; return $this->file; } /** * @throws NotFoundException * @throws InvalidPathException */ #[\Override] public function isFileReadOnly(): bool { if ($this->file === null) { throw new NotFoundException('File not found'); } return !($this->file->getPermissions() & Constants::PERMISSION_UPDATE); } }