Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions lib/DAV/WorkspacePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace OCA\Text\DAV;

use Exception;
use OC\Files\Node\File;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Files\FilesHome;
use OCA\Text\Service\ConfigService;
use OCA\Text\Service\FileService;
use OCA\Text\Service\WorkspaceService;
use OCP\Files\File;
use OCP\Files\GenericFileException;
use OCP\Files\NotPermittedException;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function propFind(PropFind $propFind, INode $node) {
$cachedContent = '';
if ($file instanceof File && $this->fileService->canSeeContent($file)) {
$cache = $this->cacheFactory->createDistributed('text_workspace');
$cacheKey = $file->getFileInfo()->getId() . '_' . $file->getFileInfo()->getEtag();
$cacheKey = $file->getId() . '_' . $file->getEtag();
if (($cachedContent = $cache->get($cacheKey)) !== null) {
return $cachedContent;
}
Expand All @@ -130,7 +130,7 @@ public function propFind(PropFind $propFind, INode $node) {

$workspaceFileCallback = function () use ($file) {
if ($file instanceof File) {
return $file->getFileInfo()->getId();
return $file->getId();
}
return '';
};
Expand Down
4 changes: 2 additions & 2 deletions lib/Middleware/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace OCA\Text\Middleware;

use OC\User\NoUserException;
use OCA\Text\Controller\ISessionAwareController;
use OCA\Text\Db\Document;
use OCA\Text\Exception\AccountDisabledException;
Expand All @@ -30,6 +29,7 @@
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use ReflectionException;

class SessionMiddleware extends Middleware {
Expand Down Expand Up @@ -134,7 +134,7 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
* Fallback for loading attachments without a session.
*
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
* @throws InvalidSessionException
*/
private function assertUserOrShareToken(ISessionAwareController $controller): void {
Expand Down
4 changes: 2 additions & 2 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OCA\Text\Notification;

use OC\User\NoUserException;
use OCA\Text\Event\MentionEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
Expand All @@ -22,6 +21,7 @@
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;
use OCP\User\Exceptions\UserNotFoundException;

class Notifier implements INotifier {
public const string TYPE_MENTIONED = 'mentioned';
Expand Down Expand Up @@ -86,7 +86,7 @@ public function prepare(INotification $notification, string $languageCode): INot

try {
$userFolder = $this->rootFolder->getUserFolder($targetUser);
} catch (NotPermittedException|NoUserException) {
} catch (NotPermittedException|UserNotFoundException) {
throw new UnknownNotificationException();
}
$node = $userFolder->getFirstNodeById($fileId);
Expand Down
34 changes: 17 additions & 17 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OCA\Text\Service;

use OC\User\NoUserException;
use OCA\DAV\Connector\Sabre\PublicAuth;
use OCA\Text\Context\IContext;
use OCA\Text\Controller\AttachmentController;
Expand All @@ -32,6 +31,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;

readonly class AttachmentService {
Expand All @@ -52,7 +52,7 @@ public function __construct(
* Get image content or preview from file name
*
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand All @@ -64,7 +64,7 @@ public function getImageFile(IContext $context, string $imageFileName, bool $pre

/**
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand Down Expand Up @@ -95,7 +95,7 @@ private function getImageFileContent(string $imageFileName, File $textFile, bool
* @throws NotFoundException
* @throws InvalidPathException
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function getMediaFile(IContext $context, string $mediaFileName, IShare|IUser $auth): ?File {
$textFile = $this->getTextFile($context);
Expand All @@ -116,7 +116,7 @@ private function canDownload(File $textFile, IShare|IUser $auth): bool {
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
private function getMediaFullFile(string $mediaFileName, File $textFile): ?File {
$attachmentFolder = $this->getAttachmentDirectoryForFile($textFile, true);
Expand All @@ -131,7 +131,7 @@ private function getMediaFullFile(string $mediaFileName, File $textFile): ?File
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function getMediaFilePreview(IContext $context, string $mediaFileName): ?array {
$textFile = $this->getTextFile($context);
Expand All @@ -144,7 +144,7 @@ public function getMediaFilePreview(IContext $context, string $mediaFileName): ?
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
private function getMediaFilePreviewFile(string $mediaFileName, File $textFile): ?array {
$attachmentFolder = $this->getAttachmentDirectoryForFile($textFile, true);
Expand All @@ -171,7 +171,7 @@ private function getMediaFilePreviewFile(string $mediaFileName, File $textFile):

/**
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand Down Expand Up @@ -247,7 +247,7 @@ public function getAttachmentList(IContext $context, IShare|IUser $auth, ?Sessio
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function uploadAttachment(IContext $context, string $newFileName, $newFileResource, IShare|IUser $auth): array {
if ($auth instanceof IShare && $auth->getPassword() !== null) {
Expand Down Expand Up @@ -293,7 +293,7 @@ public function uploadAttachment(IContext $context, string $newFileName, $newFil
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function insertAttachmentFile(IContext $context, string $path, IUser $user): array {
$textFile = $this->getTextFile($context);
Expand All @@ -319,7 +319,7 @@ public function insertAttachmentFile(IContext $context, string $path, IUser $use
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function createAttachmentFile(IContext $context, string $newFileName, IUser $user): array {
$textFile = $this->getTextFile($context);
Expand Down Expand Up @@ -364,7 +364,7 @@ public static function getUniqueFileName(Folder $dir, string $fileName): string
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
private function getAttachmentDirectoryForFile(File $textFile, bool $create = false): Folder {
$owner = $textFile->getOwner();
Expand Down Expand Up @@ -394,7 +394,7 @@ private function getAttachmentDirectoryForFile(File $textFile, bool $create = fa
*
* @throws NotFoundException
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
*/
private function getFileFromPath(string $filePath, string $userId): File {
$userFolder = $this->rootFolder->getUserFolder($userId);
Expand All @@ -410,7 +410,7 @@ private function getFileFromPath(string $filePath, string $userId): File {
/**
* Get a user file from file ID
*
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand Down Expand Up @@ -459,7 +459,7 @@ private function getShareFolder(string $shareToken): ?Folder {
* @throws NotPermittedException
* @throws InvalidPathException
* @throws LockedException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function cleanupAttachments(int $fileId): int {
$textFile = $this->rootFolder->getFirstNodeById($fileId);
Expand Down Expand Up @@ -526,7 +526,7 @@ public static function getAttachmentNamesFromContent(string $content, int $fileI

/**
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
* @throws LockedException
Expand Down Expand Up @@ -625,7 +625,7 @@ public function moveAttachments(File $source, File $target): void {
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function deleteAttachments(File $source): void {
// if there is an attachment dir for this file
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;

class FileService {
Expand Down Expand Up @@ -57,8 +58,7 @@ public function getFileById(int $fileId, string $userId): File {

try {
$userFolder = $this->rootFolder->getUserFolder($userId);
} catch (\OC\User\NoUserException) {
// It is a bit hacky to depend on internal exceptions here. But it is the best we can do for now
} catch (UserNotFoundException) {
throw new NotFoundException();
}

Expand Down
5 changes: 0 additions & 5 deletions tests/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ abstract public function getShare(): \OCP\Share\IShare;
}
}

namespace OC\User {
class NoUserException extends \Exception {
}
}

namespace OCA\Files_Sharing {
abstract class SharedStorage implements \OCP\Files\Storage\IStorage {
abstract public function getShare(): \OCP\Share\IShare;
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/DAV/WorkspacePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@

namespace OCA\Text\Tests\DAV;

use OC\Files\Node\File;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\Text\DAV\WorkspacePlugin;
use OCA\Text\Service\ConfigService;
use OCA\Text\Service\FileService;
use OCA\Text\Service\WorkspaceService;
use OCP\Files\FileInfo;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\ICache;
use OCP\ICacheFactory;
Expand All @@ -31,11 +30,9 @@ class WorkspacePluginTest extends TestCase {
private WorkspacePlugin $plugin;

protected function setUp(): void {
$fileInfo = $this->createMock(FileInfo::class);
$fileInfo->method('getId')->willReturn(42);
$fileInfo->method('getEtag')->willReturn('etag');
$file = $this->createMock(File::class);
$file->method('getFileInfo')->willReturn($fileInfo);
$file->method('getId')->willReturn(42);
$file->method('getEtag')->willReturn('etag');
$file->method('getContent')->willReturn('## Readme');

$workspaceService = $this->createMock(WorkspaceService::class);
Expand Down
Loading