88use OCA \DAV \CalDAV \Calendar ;
99use OCA \DAV \CalDAV \Publishing \Xml \Publisher ;
1010use OCP \AppFramework \Http ;
11- use OCP \IConfig ;
1211use OCP \IURLGenerator ;
1312use Sabre \CalDAV \Xml \Property \AllowedSharingModes ;
1413use Sabre \DAV \Exception \NotFound ;
@@ -29,20 +28,7 @@ class PublishPlugin extends ServerPlugin {
2928 */
3029 protected $ server ;
3130
32- /**
33- * PublishPlugin constructor.
34- *
35- * @param IConfig $config
36- * @param IURLGenerator $urlGenerator
37- */
3831 public function __construct (
39- /**
40- * Config instance to get instance secret.
41- */
42- protected IConfig $ config ,
43- /**
44- * URL Generator for absolute URLs.
45- */
4632 protected IURLGenerator $ urlGenerator ,
4733 ) {
4834 }
@@ -101,16 +87,10 @@ public function propFind(PropFind $propFind, INode $node) {
10187 }
10288 });
10389
104- $ propFind ->handle ('{ ' . self ::NS_CALENDARSERVER . '}allowed-sharing-modes ' , function () use ($ node ) {
105- $ canShare = (!$ node ->isSubscription () && $ node ->canWrite ());
106- $ canPublish = (!$ node ->isSubscription () && $ node ->canWrite ());
90+ $ propFind ->handle ('{ ' . self ::NS_CALENDARSERVER . '}allowed-sharing-modes ' , function () use ($ propFind , $ node ) {
91+ $ canShare = !$ node ->isSubscription () && $ this ->canChangeSharing ($ propFind ->getPath ());
10792
108- if ($ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ) {
109- $ canShare = $ canShare && ($ node ->getOwner () === $ node ->getPrincipalURI ());
110- $ canPublish = $ canPublish && ($ node ->getOwner () === $ node ->getPrincipalURI ());
111- }
112-
113- return new AllowedSharingModes ($ canShare , $ canPublish );
93+ return new AllowedSharingModes ($ canShare , $ canShare );
11494 });
11595 }
11696 }
@@ -162,20 +142,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
162142 }
163143 $ this ->server ->transactionType = 'post-publish-calendar ' ;
164144
165- // Getting ACL info
166- $ acl = $ this ->server ->getPlugin ('acl ' );
167-
168- // If there's no ACL support, we allow everything
169- if ($ acl ) {
170- /** @var \Sabre\DAVACL\Plugin $acl */
171- $ acl ->checkPrivileges ($ path , '{DAV:}write ' );
172-
173- $ limitSharingToOwner = $ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ;
174- $ isOwner = $ acl ->getCurrentUserPrincipal () === $ node ->getOwner ();
175- if ($ limitSharingToOwner && !$ isOwner ) {
176- return ;
177- }
178- }
145+ $ this ->canChangeSharing ($ path , true );
179146
180147 $ node ->setPublishStatus (true );
181148
@@ -197,20 +164,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
197164 }
198165 $ this ->server ->transactionType = 'post-unpublish-calendar ' ;
199166
200- // Getting ACL info
201- $ acl = $ this ->server ->getPlugin ('acl ' );
202-
203- // If there's no ACL support, we allow everything
204- if ($ acl ) {
205- /** @var \Sabre\DAVACL\Plugin $acl */
206- $ acl ->checkPrivileges ($ path , '{DAV:}write ' );
207-
208- $ limitSharingToOwner = $ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ;
209- $ isOwner = $ acl ->getCurrentUserPrincipal () === $ node ->getOwner ();
210- if ($ limitSharingToOwner && !$ isOwner ) {
211- return ;
212- }
213- }
167+ $ this ->canChangeSharing ($ path , true );
214168
215169 $ node ->setPublishStatus (false );
216170
@@ -225,4 +179,12 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
225179
226180 }
227181 }
182+
183+ private function canChangeSharing (string $ path , bool $ throwExceptions = false ): bool {
184+ $ acl = $ this ->server ->getPlugin ('acl ' );
185+ if (!$ acl instanceof \Sabre \DAVACL \Plugin) {
186+ return true ;
187+ }
188+ return $ acl ->checkPrivileges ($ path , '{DAV:}write-acl ' , \Sabre \DAVACL \Plugin::R_PARENT , $ throwExceptions );
189+ }
228190}
0 commit comments