88namespace OCA \DAV \Connector \Sabre ;
99
1010use OC \Files \View ;
11+ use OC \KnownUser \KnownUserService ;
1112use OCA \DAV \AppInfo \PluginManager ;
1213use OCA \DAV \CalDAV \DefaultCalendarValidator ;
14+ use OCA \DAV \CalDAV \Proxy \ProxyMapper ;
1315use OCA \DAV \DAV \CustomPropertiesBackend ;
1416use OCA \DAV \DAV \ViewOnlyPlugin ;
1517use OCA \DAV \Files \BrowserErrorPagePlugin ;
18+ use OCA \DAV \Upload \CleanupService ;
1619use OCA \Theming \ThemingDefaults ;
1720use OCP \Accounts \IAccountManager ;
1821use OCP \App \IAppManager ;
1922use OCP \Comments \ICommentsManager ;
2023use OCP \EventDispatcher \IEventDispatcher ;
2124use OCP \Files \Folder ;
2225use OCP \Files \IFilenameValidator ;
26+ use OCP \Files \IRootFolder ;
2327use OCP \Files \Mount \IMountManager ;
2428use OCP \IConfig ;
2529use OCP \IDBConnection ;
2832use OCP \IPreview ;
2933use OCP \IRequest ;
3034use OCP \ITagManager ;
35+ use OCP \IUserManager ;
3136use OCP \IUserSession ;
3237use OCP \SabrePluginEvent ;
3338use OCP \SystemTag \ISystemTagManager ;
3439use OCP \SystemTag \ISystemTagObjectMapper ;
3540use Psr \Log \LoggerInterface ;
3641use Sabre \DAV \Auth \Plugin ;
42+ use Sabre \DAV \SimpleCollection ;
3743
3844class ServerFactory {
3945
@@ -54,13 +60,22 @@ public function __construct(
5460 /**
5561 * @param callable $viewCallBack callback that should return the view for the dav endpoint
5662 */
57- public function createServer (string $ baseUri ,
63+ public function createServer (
64+ bool $ isPublicShare ,
65+ string $ baseUri ,
5866 string $ requestUri ,
5967 Plugin $ authPlugin ,
60- callable $ viewCallBack ): Server {
68+ callable $ viewCallBack ,
69+ ): Server {
6170 // Fire up server
62- $ objectTree = new ObjectTree ();
63- $ server = new Server ($ objectTree );
71+ if ($ isPublicShare ) {
72+ $ rootCollection = new SimpleCollection ('root ' );
73+ $ tree = new CachingTree ($ rootCollection );
74+ } else {
75+ $ rootCollection = null ;
76+ $ tree = new ObjectTree ();
77+ }
78+ $ server = new Server ($ tree );
6479 // Set URL explicitly due to reverse-proxy situations
6580 $ server ->httpRequest ->setUrl ($ requestUri );
6681 $ server ->setBaseUri ($ baseUri );
@@ -81,7 +96,7 @@ public function createServer(string $baseUri,
8196 $ server ->addPlugin (new RequestIdHeaderPlugin ($ this ->request ));
8297
8398 $ server ->addPlugin (new ZipFolderPlugin (
84- $ objectTree ,
99+ $ tree ,
85100 $ this ->logger ,
86101 $ this ->eventDispatcher ,
87102 ));
@@ -101,7 +116,7 @@ public function createServer(string $baseUri,
101116 }
102117
103118 // wait with registering these until auth is handled and the filesystem is setup
104- $ server ->on ('beforeMethod:* ' , function () use ($ server , $ objectTree , $ viewCallBack ): void {
119+ $ server ->on ('beforeMethod:* ' , function () use ($ server , $ tree , $ viewCallBack, $ isPublicShare , $ rootCollection ): void {
105120 // ensure the skeleton is copied
106121 $ userFolder = \OC ::$ server ->getUserFolder ();
107122
@@ -115,15 +130,49 @@ public function createServer(string $baseUri,
115130
116131 // Create Nextcloud Dir
117132 if ($ rootInfo ->getType () === 'dir ' ) {
118- $ root = new Directory ($ view , $ rootInfo , $ objectTree );
133+ $ root = new Directory ($ view , $ rootInfo , $ tree );
119134 } else {
120135 $ root = new File ($ view , $ rootInfo );
121136 }
122- $ objectTree ->init ($ root , $ view , $ this ->mountManager );
137+
138+ if ($ isPublicShare ) {
139+ $ userPrincipalBackend = new Principal (
140+ \OCP \Server::get (IUserManager::class),
141+ \OCP \Server::get (IGroupManager::class),
142+ \OCP \Server::get (IAccountManager::class),
143+ \OCP \Server::get (\OCP \Share \IManager::class),
144+ \OCP \Server::get (IUserSession::class),
145+ \OCP \Server::get (IAppManager::class),
146+ \OCP \Server::get (ProxyMapper::class),
147+ \OCP \Server::get (KnownUserService::class),
148+ \OCP \Server::get (IConfig::class),
149+ \OC ::$ server ->getL10NFactory (),
150+ );
151+
152+ // Mount the share collection at /public.php/dav/shares/<share token>
153+ $ rootCollection ->addChild (new \OCA \DAV \Files \Sharing \RootCollection (
154+ $ root ,
155+ $ userPrincipalBackend ,
156+ 'principals/shares ' ,
157+ ));
158+
159+ // Mount the upload collection at /public.php/dav/uploads/<share token>
160+ $ rootCollection ->addChild (new \OCA \DAV \Upload \RootCollection (
161+ $ userPrincipalBackend ,
162+ 'principals/shares ' ,
163+ \OCP \Server::get (CleanupService::class),
164+ \OCP \Server::get (IRootFolder::class),
165+ \OCP \Server::get (IUserSession::class),
166+ \OCP \Server::get (\OCP \Share \IManager::class),
167+ ));
168+ } else {
169+ /** @var ObjectTree $tree */
170+ $ tree ->init ($ root , $ view , $ this ->mountManager );
171+ }
123172
124173 $ server ->addPlugin (
125174 new FilesPlugin (
126- $ objectTree ,
175+ $ tree ,
127176 $ this ->config ,
128177 $ this ->request ,
129178 $ this ->previewManager ,
@@ -143,16 +192,16 @@ public function createServer(string $baseUri,
143192 ));
144193
145194 if ($ this ->userSession ->isLoggedIn ()) {
146- $ server ->addPlugin (new TagsPlugin ($ objectTree , $ this ->tagManager , $ this ->eventDispatcher , $ this ->userSession ));
195+ $ server ->addPlugin (new TagsPlugin ($ tree , $ this ->tagManager , $ this ->eventDispatcher , $ this ->userSession ));
147196 $ server ->addPlugin (new SharesPlugin (
148- $ objectTree ,
197+ $ tree ,
149198 $ this ->userSession ,
150199 $ userFolder ,
151200 \OCP \Server::get (\OCP \Share \IManager::class)
152201 ));
153202 $ server ->addPlugin (new CommentPropertiesPlugin (\OCP \Server::get (ICommentsManager::class), $ this ->userSession ));
154203 $ server ->addPlugin (new FilesReportPlugin (
155- $ objectTree ,
204+ $ tree ,
156205 $ view ,
157206 \OCP \Server::get (ISystemTagManager::class),
158207 \OCP \Server::get (ISystemTagObjectMapper::class),
@@ -167,7 +216,7 @@ public function createServer(string $baseUri,
167216 new \Sabre \DAV \PropertyStorage \Plugin (
168217 new CustomPropertiesBackend (
169218 $ server ,
170- $ objectTree ,
219+ $ tree ,
171220 $ this ->databaseConnection ,
172221 $ this ->userSession ->getUser (),
173222 \OCP \Server::get (DefaultCalendarValidator::class),
0 commit comments