@@ -46,157 +46,157 @@ |
||
| 46 | 46 | use Sabre\DAV\SimpleCollection; |
| 47 | 47 | |
| 48 | 48 | class RootCollection extends SimpleCollection { |
| 49 | - public function __construct() { |
|
| 50 | - $l10n = \OC::$server->getL10N('dav'); |
|
| 51 | - $random = Server::get(ISecureRandom::class); |
|
| 52 | - $logger = Server::get(LoggerInterface::class); |
|
| 53 | - $userManager = Server::get(IUserManager::class); |
|
| 54 | - $userSession = Server::get(IUserSession::class); |
|
| 55 | - $groupManager = Server::get(IGroupManager::class); |
|
| 56 | - $shareManager = Server::get(\OCP\Share\IManager::class); |
|
| 57 | - $db = Server::get(IDBConnection::class); |
|
| 58 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
| 59 | - $config = Server::get(IConfig::class); |
|
| 60 | - $proxyMapper = Server::get(ProxyMapper::class); |
|
| 61 | - $rootFolder = Server::get(IRootFolder::class); |
|
| 62 | - |
|
| 63 | - $userPrincipalBackend = new Principal( |
|
| 64 | - $userManager, |
|
| 65 | - $groupManager, |
|
| 66 | - Server::get(IAccountManager::class), |
|
| 67 | - $shareManager, |
|
| 68 | - Server::get(IUserSession::class), |
|
| 69 | - Server::get(IAppManager::class), |
|
| 70 | - $proxyMapper, |
|
| 71 | - Server::get(KnownUserService::class), |
|
| 72 | - Server::get(IConfig::class), |
|
| 73 | - \OC::$server->getL10NFactory() |
|
| 74 | - ); |
|
| 75 | - |
|
| 76 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
| 77 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 78 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 79 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 80 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 81 | - |
|
| 82 | - // setup the first level of the dav tree |
|
| 83 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 84 | - $userPrincipals->disableListing = $disableListing; |
|
| 85 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 86 | - $groupPrincipals->disableListing = $disableListing; |
|
| 87 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 88 | - $systemPrincipals->disableListing = $disableListing; |
|
| 89 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 90 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 91 | - $calendarSharingBackend = Server::get(Backend::class); |
|
| 92 | - |
|
| 93 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 94 | - $filesCollection->disableListing = $disableListing; |
|
| 95 | - $caldavBackend = new CalDavBackend( |
|
| 96 | - $db, |
|
| 97 | - $userPrincipalBackend, |
|
| 98 | - $userManager, |
|
| 99 | - $random, |
|
| 100 | - $logger, |
|
| 101 | - $dispatcher, |
|
| 102 | - $config, |
|
| 103 | - $calendarSharingBackend, |
|
| 104 | - false, |
|
| 105 | - ); |
|
| 106 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger); |
|
| 107 | - $userCalendarRoot->disableListing = $disableListing; |
|
| 108 | - |
|
| 109 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger); |
|
| 110 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
| 111 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger); |
|
| 112 | - $roomCalendarRoot->disableListing = $disableListing; |
|
| 113 | - |
|
| 114 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger); |
|
| 115 | - |
|
| 116 | - $systemTagCollection = Server::get(SystemTagsByIdCollection::class); |
|
| 117 | - $systemTagRelationsCollection = new SystemTagsRelationsCollection( |
|
| 118 | - Server::get(ISystemTagManager::class), |
|
| 119 | - Server::get(ISystemTagObjectMapper::class), |
|
| 120 | - Server::get(IUserSession::class), |
|
| 121 | - $groupManager, |
|
| 122 | - $dispatcher, |
|
| 123 | - $rootFolder, |
|
| 124 | - ); |
|
| 125 | - $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class); |
|
| 126 | - $commentsCollection = new Comments\RootCollection( |
|
| 127 | - Server::get(ICommentsManager::class), |
|
| 128 | - $userManager, |
|
| 129 | - Server::get(IUserSession::class), |
|
| 130 | - $dispatcher, |
|
| 131 | - $logger |
|
| 132 | - ); |
|
| 133 | - |
|
| 134 | - $contactsSharingBackend = Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class); |
|
| 135 | - |
|
| 136 | - $pluginManager = new PluginManager(\OC::$server, Server::get(IAppManager::class)); |
|
| 137 | - $usersCardDavBackend = new CardDavBackend( |
|
| 138 | - $db, |
|
| 139 | - $userPrincipalBackend, |
|
| 140 | - $userManager, |
|
| 141 | - $dispatcher, |
|
| 142 | - $contactsSharingBackend, |
|
| 143 | - ); |
|
| 144 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users'); |
|
| 145 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 146 | - |
|
| 147 | - $systemCardDavBackend = new CardDavBackend( |
|
| 148 | - $db, |
|
| 149 | - $userPrincipalBackend, |
|
| 150 | - $userManager, |
|
| 151 | - $dispatcher, |
|
| 152 | - $contactsSharingBackend, |
|
| 153 | - ); |
|
| 154 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system'); |
|
| 155 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 156 | - |
|
| 157 | - $uploadCollection = new Upload\RootCollection( |
|
| 158 | - $userPrincipalBackend, |
|
| 159 | - 'principals/users', |
|
| 160 | - Server::get(CleanupService::class), |
|
| 161 | - $rootFolder, |
|
| 162 | - $userSession, |
|
| 163 | - ); |
|
| 164 | - $uploadCollection->disableListing = $disableListing; |
|
| 165 | - |
|
| 166 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 167 | - $avatarCollection->disableListing = $disableListing; |
|
| 168 | - |
|
| 169 | - $appleProvisioning = new AppleProvisioningNode( |
|
| 170 | - Server::get(ITimeFactory::class)); |
|
| 171 | - |
|
| 172 | - $children = [ |
|
| 173 | - new SimpleCollection('principals', [ |
|
| 174 | - $userPrincipals, |
|
| 175 | - $groupPrincipals, |
|
| 176 | - $systemPrincipals, |
|
| 177 | - $calendarResourcePrincipals, |
|
| 178 | - $calendarRoomPrincipals]), |
|
| 179 | - $filesCollection, |
|
| 180 | - $userCalendarRoot, |
|
| 181 | - new SimpleCollection('system-calendars', [ |
|
| 182 | - $resourceCalendarRoot, |
|
| 183 | - $roomCalendarRoot, |
|
| 184 | - ]), |
|
| 185 | - $publicCalendarRoot, |
|
| 186 | - new SimpleCollection('addressbooks', [ |
|
| 187 | - $usersAddressBookRoot, |
|
| 188 | - $systemAddressBookRoot]), |
|
| 189 | - $systemTagCollection, |
|
| 190 | - $systemTagRelationsCollection, |
|
| 191 | - $systemTagInUseCollection, |
|
| 192 | - $commentsCollection, |
|
| 193 | - $uploadCollection, |
|
| 194 | - $avatarCollection, |
|
| 195 | - new SimpleCollection('provisioning', [ |
|
| 196 | - $appleProvisioning |
|
| 197 | - ]) |
|
| 198 | - ]; |
|
| 199 | - |
|
| 200 | - parent::__construct('root', $children); |
|
| 201 | - } |
|
| 49 | + public function __construct() { |
|
| 50 | + $l10n = \OC::$server->getL10N('dav'); |
|
| 51 | + $random = Server::get(ISecureRandom::class); |
|
| 52 | + $logger = Server::get(LoggerInterface::class); |
|
| 53 | + $userManager = Server::get(IUserManager::class); |
|
| 54 | + $userSession = Server::get(IUserSession::class); |
|
| 55 | + $groupManager = Server::get(IGroupManager::class); |
|
| 56 | + $shareManager = Server::get(\OCP\Share\IManager::class); |
|
| 57 | + $db = Server::get(IDBConnection::class); |
|
| 58 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
| 59 | + $config = Server::get(IConfig::class); |
|
| 60 | + $proxyMapper = Server::get(ProxyMapper::class); |
|
| 61 | + $rootFolder = Server::get(IRootFolder::class); |
|
| 62 | + |
|
| 63 | + $userPrincipalBackend = new Principal( |
|
| 64 | + $userManager, |
|
| 65 | + $groupManager, |
|
| 66 | + Server::get(IAccountManager::class), |
|
| 67 | + $shareManager, |
|
| 68 | + Server::get(IUserSession::class), |
|
| 69 | + Server::get(IAppManager::class), |
|
| 70 | + $proxyMapper, |
|
| 71 | + Server::get(KnownUserService::class), |
|
| 72 | + Server::get(IConfig::class), |
|
| 73 | + \OC::$server->getL10NFactory() |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
| 77 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 78 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 79 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 80 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 81 | + |
|
| 82 | + // setup the first level of the dav tree |
|
| 83 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 84 | + $userPrincipals->disableListing = $disableListing; |
|
| 85 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 86 | + $groupPrincipals->disableListing = $disableListing; |
|
| 87 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 88 | + $systemPrincipals->disableListing = $disableListing; |
|
| 89 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 90 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 91 | + $calendarSharingBackend = Server::get(Backend::class); |
|
| 92 | + |
|
| 93 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 94 | + $filesCollection->disableListing = $disableListing; |
|
| 95 | + $caldavBackend = new CalDavBackend( |
|
| 96 | + $db, |
|
| 97 | + $userPrincipalBackend, |
|
| 98 | + $userManager, |
|
| 99 | + $random, |
|
| 100 | + $logger, |
|
| 101 | + $dispatcher, |
|
| 102 | + $config, |
|
| 103 | + $calendarSharingBackend, |
|
| 104 | + false, |
|
| 105 | + ); |
|
| 106 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $logger); |
|
| 107 | + $userCalendarRoot->disableListing = $disableListing; |
|
| 108 | + |
|
| 109 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $logger); |
|
| 110 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
| 111 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $logger); |
|
| 112 | + $roomCalendarRoot->disableListing = $disableListing; |
|
| 113 | + |
|
| 114 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger); |
|
| 115 | + |
|
| 116 | + $systemTagCollection = Server::get(SystemTagsByIdCollection::class); |
|
| 117 | + $systemTagRelationsCollection = new SystemTagsRelationsCollection( |
|
| 118 | + Server::get(ISystemTagManager::class), |
|
| 119 | + Server::get(ISystemTagObjectMapper::class), |
|
| 120 | + Server::get(IUserSession::class), |
|
| 121 | + $groupManager, |
|
| 122 | + $dispatcher, |
|
| 123 | + $rootFolder, |
|
| 124 | + ); |
|
| 125 | + $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class); |
|
| 126 | + $commentsCollection = new Comments\RootCollection( |
|
| 127 | + Server::get(ICommentsManager::class), |
|
| 128 | + $userManager, |
|
| 129 | + Server::get(IUserSession::class), |
|
| 130 | + $dispatcher, |
|
| 131 | + $logger |
|
| 132 | + ); |
|
| 133 | + |
|
| 134 | + $contactsSharingBackend = Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class); |
|
| 135 | + |
|
| 136 | + $pluginManager = new PluginManager(\OC::$server, Server::get(IAppManager::class)); |
|
| 137 | + $usersCardDavBackend = new CardDavBackend( |
|
| 138 | + $db, |
|
| 139 | + $userPrincipalBackend, |
|
| 140 | + $userManager, |
|
| 141 | + $dispatcher, |
|
| 142 | + $contactsSharingBackend, |
|
| 143 | + ); |
|
| 144 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/users'); |
|
| 145 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 146 | + |
|
| 147 | + $systemCardDavBackend = new CardDavBackend( |
|
| 148 | + $db, |
|
| 149 | + $userPrincipalBackend, |
|
| 150 | + $userManager, |
|
| 151 | + $dispatcher, |
|
| 152 | + $contactsSharingBackend, |
|
| 153 | + ); |
|
| 154 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, $userSession->getUser(), $groupManager, 'principals/system'); |
|
| 155 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 156 | + |
|
| 157 | + $uploadCollection = new Upload\RootCollection( |
|
| 158 | + $userPrincipalBackend, |
|
| 159 | + 'principals/users', |
|
| 160 | + Server::get(CleanupService::class), |
|
| 161 | + $rootFolder, |
|
| 162 | + $userSession, |
|
| 163 | + ); |
|
| 164 | + $uploadCollection->disableListing = $disableListing; |
|
| 165 | + |
|
| 166 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 167 | + $avatarCollection->disableListing = $disableListing; |
|
| 168 | + |
|
| 169 | + $appleProvisioning = new AppleProvisioningNode( |
|
| 170 | + Server::get(ITimeFactory::class)); |
|
| 171 | + |
|
| 172 | + $children = [ |
|
| 173 | + new SimpleCollection('principals', [ |
|
| 174 | + $userPrincipals, |
|
| 175 | + $groupPrincipals, |
|
| 176 | + $systemPrincipals, |
|
| 177 | + $calendarResourcePrincipals, |
|
| 178 | + $calendarRoomPrincipals]), |
|
| 179 | + $filesCollection, |
|
| 180 | + $userCalendarRoot, |
|
| 181 | + new SimpleCollection('system-calendars', [ |
|
| 182 | + $resourceCalendarRoot, |
|
| 183 | + $roomCalendarRoot, |
|
| 184 | + ]), |
|
| 185 | + $publicCalendarRoot, |
|
| 186 | + new SimpleCollection('addressbooks', [ |
|
| 187 | + $usersAddressBookRoot, |
|
| 188 | + $systemAddressBookRoot]), |
|
| 189 | + $systemTagCollection, |
|
| 190 | + $systemTagRelationsCollection, |
|
| 191 | + $systemTagInUseCollection, |
|
| 192 | + $commentsCollection, |
|
| 193 | + $uploadCollection, |
|
| 194 | + $avatarCollection, |
|
| 195 | + new SimpleCollection('provisioning', [ |
|
| 196 | + $appleProvisioning |
|
| 197 | + ]) |
|
| 198 | + ]; |
|
| 199 | + |
|
| 200 | + parent::__construct('root', $children); |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | |
| 17 | 17 | class RootCollection extends AbstractPrincipalCollection { |
| 18 | 18 | |
| 19 | - public function __construct( |
|
| 20 | - PrincipalBackend\BackendInterface $principalBackend, |
|
| 21 | - string $principalPrefix, |
|
| 22 | - private CleanupService $cleanupService, |
|
| 23 | - private IRootFolder $rootFolder, |
|
| 24 | - private IUserSession $userSession, |
|
| 25 | - ) { |
|
| 26 | - parent::__construct($principalBackend, $principalPrefix); |
|
| 27 | - } |
|
| 19 | + public function __construct( |
|
| 20 | + PrincipalBackend\BackendInterface $principalBackend, |
|
| 21 | + string $principalPrefix, |
|
| 22 | + private CleanupService $cleanupService, |
|
| 23 | + private IRootFolder $rootFolder, |
|
| 24 | + private IUserSession $userSession, |
|
| 25 | + ) { |
|
| 26 | + parent::__construct($principalBackend, $principalPrefix); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @inheritdoc |
|
| 31 | - */ |
|
| 32 | - public function getChildForPrincipal(array $principalInfo): UploadHome { |
|
| 33 | - return new UploadHome($principalInfo, $this->cleanupService, $this->rootFolder, $this->userSession); |
|
| 34 | - } |
|
| 29 | + /** |
|
| 30 | + * @inheritdoc |
|
| 31 | + */ |
|
| 32 | + public function getChildForPrincipal(array $principalInfo): UploadHome { |
|
| 33 | + return new UploadHome($principalInfo, $this->cleanupService, $this->rootFolder, $this->userSession); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @inheritdoc |
|
| 38 | - */ |
|
| 39 | - public function getName(): string { |
|
| 40 | - return 'uploads'; |
|
| 41 | - } |
|
| 36 | + /** |
|
| 37 | + * @inheritdoc |
|
| 38 | + */ |
|
| 39 | + public function getName(): string { |
|
| 40 | + return 'uploads'; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -17,85 +17,85 @@ |
||
| 17 | 17 | use Sabre\DAV\ICollection; |
| 18 | 18 | |
| 19 | 19 | class UploadHome implements ICollection { |
| 20 | - private ?Folder $uploadFolder = null; |
|
| 21 | - |
|
| 22 | - public function __construct( |
|
| 23 | - private readonly array $principalInfo, |
|
| 24 | - private readonly CleanupService $cleanupService, |
|
| 25 | - private readonly IRootFolder $rootFolder, |
|
| 26 | - private readonly IUserSession $userSession, |
|
| 27 | - ) { |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function createFile($name, $data = null) { |
|
| 31 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function createDirectory($name) { |
|
| 35 | - $this->impl()->createDirectory($name); |
|
| 36 | - |
|
| 37 | - // Add a cleanup job |
|
| 38 | - $this->cleanupService->addJob($name); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function getChild($name): UploadFolder { |
|
| 42 | - return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage()); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getChildren(): array { |
|
| 46 | - return array_map(function ($node) { |
|
| 47 | - return new UploadFolder($node, $this->cleanupService, $this->getStorage()); |
|
| 48 | - }, $this->impl()->getChildren()); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function childExists($name): bool { |
|
| 52 | - return !is_null($this->getChild($name)); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function delete() { |
|
| 56 | - $this->impl()->delete(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function getName() { |
|
| 60 | - [,$name] = \Sabre\Uri\split($this->principalInfo['uri']); |
|
| 61 | - return $name; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function setName($name) { |
|
| 65 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function getLastModified() { |
|
| 69 | - return $this->impl()->getLastModified(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - private function getUploadFolder(): Folder { |
|
| 73 | - if ($this->uploadFolder === null) { |
|
| 74 | - $user = $this->userSession->getUser(); |
|
| 75 | - if (!$user) { |
|
| 76 | - throw new Forbidden('Not logged in'); |
|
| 77 | - } |
|
| 78 | - $path = '/' . $user->getUID() . '/uploads'; |
|
| 79 | - try { |
|
| 80 | - $folder = $this->rootFolder->get($path); |
|
| 81 | - if (!$folder instanceof Folder) { |
|
| 82 | - throw new \Exception('Upload folder is a file'); |
|
| 83 | - } |
|
| 84 | - $this->uploadFolder = $folder; |
|
| 85 | - } catch (NotFoundException $e) { |
|
| 86 | - $this->uploadFolder = $this->rootFolder->newFolder($path); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - return $this->uploadFolder; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - private function impl(): Directory { |
|
| 93 | - $folder = $this->getUploadFolder(); |
|
| 94 | - $view = new View($folder->getPath()); |
|
| 95 | - return new Directory($view, $folder); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - private function getStorage() { |
|
| 99 | - return $this->getUploadFolder()->getStorage(); |
|
| 100 | - } |
|
| 20 | + private ?Folder $uploadFolder = null; |
|
| 21 | + |
|
| 22 | + public function __construct( |
|
| 23 | + private readonly array $principalInfo, |
|
| 24 | + private readonly CleanupService $cleanupService, |
|
| 25 | + private readonly IRootFolder $rootFolder, |
|
| 26 | + private readonly IUserSession $userSession, |
|
| 27 | + ) { |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function createFile($name, $data = null) { |
|
| 31 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function createDirectory($name) { |
|
| 35 | + $this->impl()->createDirectory($name); |
|
| 36 | + |
|
| 37 | + // Add a cleanup job |
|
| 38 | + $this->cleanupService->addJob($name); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function getChild($name): UploadFolder { |
|
| 42 | + return new UploadFolder($this->impl()->getChild($name), $this->cleanupService, $this->getStorage()); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getChildren(): array { |
|
| 46 | + return array_map(function ($node) { |
|
| 47 | + return new UploadFolder($node, $this->cleanupService, $this->getStorage()); |
|
| 48 | + }, $this->impl()->getChildren()); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function childExists($name): bool { |
|
| 52 | + return !is_null($this->getChild($name)); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function delete() { |
|
| 56 | + $this->impl()->delete(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function getName() { |
|
| 60 | + [,$name] = \Sabre\Uri\split($this->principalInfo['uri']); |
|
| 61 | + return $name; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function setName($name) { |
|
| 65 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function getLastModified() { |
|
| 69 | + return $this->impl()->getLastModified(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + private function getUploadFolder(): Folder { |
|
| 73 | + if ($this->uploadFolder === null) { |
|
| 74 | + $user = $this->userSession->getUser(); |
|
| 75 | + if (!$user) { |
|
| 76 | + throw new Forbidden('Not logged in'); |
|
| 77 | + } |
|
| 78 | + $path = '/' . $user->getUID() . '/uploads'; |
|
| 79 | + try { |
|
| 80 | + $folder = $this->rootFolder->get($path); |
|
| 81 | + if (!$folder instanceof Folder) { |
|
| 82 | + throw new \Exception('Upload folder is a file'); |
|
| 83 | + } |
|
| 84 | + $this->uploadFolder = $folder; |
|
| 85 | + } catch (NotFoundException $e) { |
|
| 86 | + $this->uploadFolder = $this->rootFolder->newFolder($path); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + return $this->uploadFolder; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + private function impl(): Directory { |
|
| 93 | + $folder = $this->getUploadFolder(); |
|
| 94 | + $view = new View($folder->getPath()); |
|
| 95 | + return new Directory($view, $folder); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + private function getStorage() { |
|
| 99 | + return $this->getUploadFolder()->getStorage(); |
|
| 100 | + } |
|
| 101 | 101 | } |