88
99use OCA \DAV \CalDAV \Calendar ;
1010use OCA \DAV \CalDAV \Publishing \Xml \Publisher ;
11- use OCP \IConfig ;
1211use OCP \IURLGenerator ;
1312use Sabre \CalDAV \Xml \Property \AllowedSharingModes ;
1413use Sabre \DAV \Exception \NotFound ;
@@ -29,13 +28,6 @@ class PublishPlugin extends ServerPlugin {
2928 */
3029 protected $ server ;
3130
32- /**
33- * Config instance to get instance secret.
34- *
35- * @var IConfig
36- */
37- protected $ config ;
38-
3931 /**
4032 * URL Generator for absolute URLs.
4133 *
@@ -46,11 +38,9 @@ class PublishPlugin extends ServerPlugin {
4638 /**
4739 * PublishPlugin constructor.
4840 *
49- * @param IConfig $config
5041 * @param IURLGenerator $urlGenerator
5142 */
52- public function __construct (IConfig $ config , IURLGenerator $ urlGenerator ) {
53- $ this ->config = $ config ;
43+ public function __construct (IURLGenerator $ urlGenerator ) {
5444 $ this ->urlGenerator = $ urlGenerator ;
5545 }
5646
@@ -108,16 +98,10 @@ public function propFind(PropFind $propFind, INode $node) {
10898 }
10999 });
110100
111- $ propFind ->handle ('{ ' .self ::NS_CALENDARSERVER .'}allowed-sharing-modes ' , function () use ($ node ) {
112- $ canShare = (!$ node ->isSubscription () && $ node ->canWrite ());
113- $ canPublish = (!$ node ->isSubscription () && $ node ->canWrite ());
101+ $ propFind ->handle ('{ ' . self ::NS_CALENDARSERVER . '}allowed-sharing-modes ' , function () use ($ propFind , $ node ) {
102+ $ canShare = !$ node ->isSubscription () && $ this ->canChangeSharing ($ propFind ->getPath ());
114103
115- if ($ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ) {
116- $ canShare = $ canShare && ($ node ->getOwner () === $ node ->getPrincipalURI ());
117- $ canPublish = $ canPublish && ($ node ->getOwner () === $ node ->getPrincipalURI ());
118- }
119-
120- return new AllowedSharingModes ($ canShare , $ canPublish );
104+ return new AllowedSharingModes ($ canShare , $ canShare );
121105 });
122106 }
123107 }
@@ -169,20 +153,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
169153 }
170154 $ this ->server ->transactionType = 'post-publish-calendar ' ;
171155
172- // Getting ACL info
173- $ acl = $ this ->server ->getPlugin ('acl ' );
174-
175- // If there's no ACL support, we allow everything
176- if ($ acl ) {
177- /** @var \Sabre\DAVACL\Plugin $acl */
178- $ acl ->checkPrivileges ($ path , '{DAV:}write ' );
179-
180- $ limitSharingToOwner = $ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ;
181- $ isOwner = $ acl ->getCurrentUserPrincipal () === $ node ->getOwner ();
182- if ($ limitSharingToOwner && !$ isOwner ) {
183- return ;
184- }
185- }
156+ $ this ->canChangeSharing ($ path , true );
186157
187158 $ node ->setPublishStatus (true );
188159
@@ -204,20 +175,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
204175 }
205176 $ this ->server ->transactionType = 'post-unpublish-calendar ' ;
206177
207- // Getting ACL info
208- $ acl = $ this ->server ->getPlugin ('acl ' );
209-
210- // If there's no ACL support, we allow everything
211- if ($ acl ) {
212- /** @var \Sabre\DAVACL\Plugin $acl */
213- $ acl ->checkPrivileges ($ path , '{DAV:}write ' );
214-
215- $ limitSharingToOwner = $ this ->config ->getAppValue ('dav ' , 'limitAddressBookAndCalendarSharingToOwner ' , 'no ' ) === 'yes ' ;
216- $ isOwner = $ acl ->getCurrentUserPrincipal () === $ node ->getOwner ();
217- if ($ limitSharingToOwner && !$ isOwner ) {
218- return ;
219- }
220- }
178+ $ this ->canChangeSharing ($ path , true );
221179
222180 $ node ->setPublishStatus (false );
223181
@@ -232,4 +190,12 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
232190
233191 }
234192 }
193+
194+ private function canChangeSharing (string $ path , bool $ throwExceptions = false ): bool {
195+ $ acl = $ this ->server ->getPlugin ('acl ' );
196+ if (!$ acl instanceof \Sabre \DAVACL \Plugin) {
197+ return true ;
198+ }
199+ return $ acl ->checkPrivileges ($ path , '{DAV:}write-acl ' , \Sabre \DAVACL \Plugin::R_PARENT , $ throwExceptions );
200+ }
235201}
0 commit comments