Skip to content

Commit 8ecce9d

Browse files
committed
refactor: Expose a public exception when no user is found
And use this new exception everywhere outside of where the old one was throw. Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent b54e98a commit 8ecce9d

46 files changed

Lines changed: 126 additions & 112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/dav/lib/BackgroundJob/EventReminderJob.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace OCA\DAV\BackgroundJob;
1111

12-
use OC\User\NoUserException;
1312
use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
1413
use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
1514
use OCA\DAV\CalDAV\Reminder\ReminderService;
@@ -34,7 +33,6 @@ public function __construct(
3433
/**
3534
* @throws ProviderNotAvailableException
3635
* @throws NotificationTypeDoesNotExistException
37-
* @throws NoUserException
3836
*/
3937
#[\Override]
4038
public function run($argument):void {

apps/dav/lib/BackgroundJob/UploadCleanup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace OCA\DAV\BackgroundJob;
1111

12-
use OC\User\NoUserException;
1312
use OCP\AppFramework\Utility\ITimeFactory;
1413
use OCP\BackgroundJob\IJobList;
1514
use OCP\BackgroundJob\TimedJob;
@@ -19,6 +18,7 @@
1918
use OCP\Files\NotFoundException;
2019
use OCP\IConfig;
2120
use OCP\Server;
21+
use OCP\User\Exceptions\UserNotFoundException;
2222
use Psr\Log\LoggerInterface;
2323

2424
class UploadCleanup extends TimedJob {
@@ -46,7 +46,7 @@ protected function run($argument) {
4646
/** @var Folder $uploads */
4747
$uploads = $userRoot->get('uploads');
4848
$uploadFolder = $uploads->get($folder);
49-
} catch (NotFoundException|NoUserException $e) {
49+
} catch (NotFoundException|UserNotFoundException $e) {
5050
$this->jobList->remove(self::class, $argument);
5151
return;
5252
}

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OC\AppFramework\Http\Request;
1212
use OC\FilesMetadata\Model\FilesMetadata;
13-
use OC\User\NoUserException;
1413
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
1514
use OCA\Files_Sharing\External\Mount as SharingExternalMount;
1615
use OCP\Accounts\IAccountManager;
@@ -29,6 +28,7 @@
2928
use OCP\IRequest;
3029
use OCP\IUserSession;
3130
use OCP\L10N\IFactory;
31+
use OCP\User\Exceptions\UserNotFoundException;
3232
use Sabre\DAV\Exception\Forbidden;
3333
use Sabre\DAV\Exception\NotFound;
3434
use Sabre\DAV\IFile;
@@ -382,7 +382,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
382382
// Check if the user published their display name
383383
try {
384384
$ownerAccount = $this->accountManager->getAccount($owner);
385-
} catch (NoUserException) {
385+
} catch (UserNotFoundException) {
386386
// do not lock process if owner is not local
387387
return null;
388388
}

apps/dav/lib/SystemTag/SystemTagsInUseCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
use OC\SystemTag\SystemTag;
1313
use OC\SystemTag\SystemTagsInFilesDetector;
14-
use OC\User\NoUserException;
1514
use OCP\Files\IRootFolder;
1615
use OCP\Files\NotPermittedException;
1716
use OCP\IUserSession;
1817
use OCP\SystemTag\ISystemTagManager;
1918
use OCP\SystemTag\ISystemTagObjectMapper;
19+
use OCP\User\Exceptions\UserNotFoundException;
2020
use Sabre\DAV\Exception\Forbidden;
2121
use Sabre\DAV\Exception\NotFound;
2222
use Sabre\DAV\SimpleCollection;
@@ -63,7 +63,7 @@ public function getChildren(): array {
6363
if ($user) {
6464
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
6565
}
66-
} catch (NoUserException) {
66+
} catch (UserNotFoundException) {
6767
// will throw a Sabre exception in the next step.
6868
}
6969
if ($user === null || $userFolder === null) {

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Exception;
1414
use OC\Files\Filesystem;
1515
use OC\Files\View;
16-
use OC\User\NoUserException;
1716
use OCA\Encryption\Util;
1817
use OCA\Files\Exception\TransferOwnershipException;
1918
use OCA\Files_External\Config\ConfigAdapter;
@@ -35,6 +34,7 @@
3534
use OCP\Share\Events\ShareTransferredEvent;
3635
use OCP\Share\IManager as IShareManager;
3736
use OCP\Share\IShare;
37+
use OCP\User\Exceptions\UserNotFoundException;
3838
use Symfony\Component\Console\Helper\ProgressBar;
3939
use Symfony\Component\Console\Output\NullOutput;
4040
use Symfony\Component\Console\Output\OutputInterface;
@@ -67,7 +67,7 @@ public function __construct(
6767
* @param OutputInterface|null $output
6868
* @param bool $move
6969
* @throws TransferOwnershipException
70-
* @throws NoUserException
70+
* @throws UserNotFoundException
7171
*/
7272
public function transfer(
7373
IUser $sourceUser,

apps/files_external/lib/Command/Create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OC\Core\Command\Base;
1212
use OC\Files\Filesystem;
13-
use OC\User\NoUserException;
1413
use OCA\Files_External\Lib\Auth\AuthMechanism;
1514
use OCA\Files_External\Lib\Backend\Backend;
1615
use OCA\Files_External\Lib\DefinitionParameter;
@@ -22,6 +21,7 @@
2221
use OCP\AppFramework\Http;
2322
use OCP\IUserManager;
2423
use OCP\IUserSession;
24+
use OCP\User\Exceptions\UserNotFoundException;
2525
use Symfony\Component\Console\Input\ArrayInput;
2626
use Symfony\Component\Console\Input\InputArgument;
2727
use Symfony\Component\Console\Input\InputInterface;
@@ -179,7 +179,7 @@ protected function getStorageService(string $userId): StoragesService {
179179

180180
$user = $this->userManager->get($userId);
181181
if (is_null($user)) {
182-
throw new NoUserException("user $userId not found");
182+
throw UserNotFoundException::createForUser($userId);
183183
}
184184
$this->userSession->setUser($user);
185185
return $this->userService;

apps/files_external/lib/Command/Import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace OCA\Files_External\Command;
1010

1111
use OC\Core\Command\Base;
12-
use OC\User\NoUserException;
1312
use OCA\Files_External\Lib\StorageConfig;
1413
use OCA\Files_External\Service\BackendService;
1514
use OCA\Files_External\Service\GlobalStoragesService;
@@ -18,6 +17,7 @@
1817
use OCA\Files_External\Service\UserStoragesService;
1918
use OCP\IUserManager;
2019
use OCP\IUserSession;
20+
use OCP\User\Exceptions\UserNotFoundException;
2121
use Symfony\Component\Console\Input\ArrayInput;
2222
use Symfony\Component\Console\Input\InputArgument;
2323
use Symfony\Component\Console\Input\InputInterface;
@@ -174,7 +174,7 @@ protected function getStorageService(string $userId): StoragesService {
174174

175175
$user = $this->userManager->get($userId);
176176
if (is_null($user)) {
177-
throw new NoUserException("user $userId not found");
177+
throw UserNotFoundException::createForUser($userId);
178178
}
179179
$this->userSession->setUser($user);
180180
return $this->userService;

apps/files_external/lib/Command/ListCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
namespace OCA\Files_External\Command;
1010

1111
use OC\Core\Command\Base;
12-
use OC\User\NoUserException;
1312
use OCA\Files_External\Lib\StorageConfig;
1413
use OCA\Files_External\Service\GlobalStoragesService;
1514
use OCA\Files_External\Service\StoragesService;
1615
use OCA\Files_External\Service\UserStoragesService;
1716
use OCP\IUserManager;
1817
use OCP\IUserSession;
18+
use OCP\User\Exceptions\UserNotFoundException;
1919
use Symfony\Component\Console\Helper\Table;
2020
use Symfony\Component\Console\Input\InputArgument;
2121
use Symfony\Component\Console\Input\InputInterface;
@@ -234,7 +234,7 @@ protected function getStorageService(string $userId): StoragesService {
234234

235235
$user = $this->userManager->get($userId);
236236
if (is_null($user)) {
237-
throw new NoUserException("user $userId not found");
237+
throw UserNotFoundException::createForUser($userId);
238238
}
239239
$this->userSession->setUser($user);
240240
return $this->userService;

apps/files_reminders/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
'OCA\\FilesReminders\\Db\\ReminderMapper' => $baseDir . '/../lib/Db/ReminderMapper.php',
1818
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => $baseDir . '/../lib/Exception/NodeNotFoundException.php',
1919
'OCA\\FilesReminders\\Exception\\ReminderNotFoundException' => $baseDir . '/../lib/Exception/ReminderNotFoundException.php',
20-
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => $baseDir . '/../lib/Exception/UserNotFoundException.php',
2120
'OCA\\FilesReminders\\Listener\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listener/LoadAdditionalScriptsListener.php',
2221
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => $baseDir . '/../lib/Listener/NodeDeletedListener.php',
2322
'OCA\\FilesReminders\\Listener\\SabrePluginAddListener' => $baseDir . '/../lib/Listener/SabrePluginAddListener.php',

apps/files_reminders/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ComposerStaticInitFilesReminders
3232
'OCA\\FilesReminders\\Db\\ReminderMapper' => __DIR__ . '/..' . '/../lib/Db/ReminderMapper.php',
3333
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/NodeNotFoundException.php',
3434
'OCA\\FilesReminders\\Exception\\ReminderNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/ReminderNotFoundException.php',
35-
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/UserNotFoundException.php',
3635
'OCA\\FilesReminders\\Listener\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScriptsListener.php',
3736
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/NodeDeletedListener.php',
3837
'OCA\\FilesReminders\\Listener\\SabrePluginAddListener' => __DIR__ . '/..' . '/../lib/Listener/SabrePluginAddListener.php',

0 commit comments

Comments
 (0)