@@ -113,6 +113,8 @@ class ShareAPIController extends OCSController {
113113 /** @var IPreview */
114114 private $ previewManager ;
115115
116+ private $ dynamicShareTypes ;
117+
116118 /**
117119 * Share20OCS constructor.
118120 *
@@ -161,6 +163,33 @@ public function __construct(
161163 $ this ->serverContainer = $ serverContainer ;
162164 $ this ->userStatusManager = $ userStatusManager ;
163165 $ this ->previewManager = $ previewManager ;
166+ $ this ->dynamicShareTypes = [];
167+ // FIXME: Move this line into the sciencemesh app:
168+ $ this ->registerHelper (IShare::TYPE_SCIENCEMESH , 'sciencemesh ' , '\OCA\ScienceMesh\ShareProvider\ShareAPIHelper ' );
169+ }
170+
171+ public function registerHelper ($ shareType , $ identifier , $ helperClassName ) {
172+ $ this ->dynamicShareTypes [$ shareType ] = [
173+ "identifier " => $ identifier ,
174+ "helperClass " => $ helperClassName
175+ ];
176+ }
177+
178+ private function haveHelperFor ($ shareType ) {
179+ return isset ($ this ->dynamicShareTypes [$ shareType ]);
180+ }
181+
182+ private function getIdentifierFor ($ shareType ) {
183+ return $ this ->dynamicShareTypes [$ shareType ]["identifier " ];
184+ }
185+
186+ private function getHelperFor ($ shareType ) {
187+ $ identifier = $ this ->getIdentifierFor ($ shareType );
188+ if (!$ this ->appManager ->isEnabledForUser ($ identifier )) {
189+ throw new QueryException ();
190+ }
191+
192+ return $ this ->serverContainer ->get ($ this ->dynamicShareTypes [$ shareType ]["helperClass " ]);
164193 }
165194
166195 /**
@@ -318,6 +347,14 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
318347 $ result = array_merge ($ result , $ this ->getDeckShareHelper ()->formatShare ($ share ));
319348 } catch (QueryException $ e ) {
320349 }
350+ } elseif ($ this ->haveHelperFor ($ share ->getShareType ())) {
351+ $ result ['share_with ' ] = $ share ->getSharedWith ();
352+ $ result ['share_with_displayname ' ] = '' ;
353+
354+ try {
355+ $ result = array_merge ($ result , $ this ->getHelperFor ($ share ->getShareType ())->formatShare ($ share ));
356+ } catch (QueryException $ e ) {
357+ }
321358 }
322359
323360
@@ -663,6 +700,12 @@ public function createShare(
663700 } catch (QueryException $ e ) {
664701 throw new OCSForbiddenException ($ this ->l ->t ('Sharing %s failed because the back end does not support room shares ' , [$ node ->getPath ()]));
665702 }
703+ } elseif ($ this ->haveHelperFor ($ shareType )) {
704+ try {
705+ $ this ->getHelperFor ($ shareType )->createShare ($ share , $ shareWith , $ permissions , $ expireDate );
706+ } catch (QueryException $ e ) {
707+ throw new OCSForbiddenException ($ this ->l ->t ('Sharing %s failed because the back end does not support this type of shares ' , [$ node ->getPath ()]));
708+ }
666709 } else {
667710 throw new OCSBadRequestException ($ this ->l ->t ('Unknown share type ' ));
668711 }
@@ -1568,6 +1611,17 @@ private function getShareById(string $id): IShare {
15681611 // Do nothing, just try the other share type
15691612 }
15701613
1614+ foreach ($ this ->dynamicShareTypes as $ shareType => $ details ) {
1615+ try {
1616+ if ($ this ->shareManager ->shareProviderExists ($ shareType )) {
1617+ $ share = $ this ->shareManager ->getShareById ($ details ["identifier " ] . ": " . $ id , $ this ->currentUser );
1618+ return $ share ;
1619+ }
1620+ } catch (ShareNotFound $ e ) {
1621+ // Do nothing, just try the other share type
1622+ }
1623+ }
1624+
15711625 if (!$ this ->shareManager ->outgoingServer2ServerSharesAllowed ()) {
15721626 throw new ShareNotFound ();
15731627 }
@@ -1631,14 +1685,7 @@ private function getDeckShareHelper() {
16311685 return $ this ->serverContainer ->get ('\OCA\Deck\Sharing\ShareAPIHelper ' );
16321686 }
16331687
1634- /**
1635- * @param string $viewer
1636- * @param Node $node
1637- * @param bool $reShares
1638- *
1639- * @return IShare[]
1640- */
1641- private function getSharesFromNode (string $ viewer , $ node , bool $ reShares ): array {
1688+ private function getProvidersExceptOutgoing () {
16421689 $ providers = [
16431690 IShare::TYPE_USER ,
16441691 IShare::TYPE_GROUP ,
@@ -1648,6 +1695,23 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
16481695 IShare::TYPE_ROOM ,
16491696 IShare::TYPE_DECK
16501697 ];
1698+ foreach ($ this ->dynamicShareTypes as $ shareType => $ details ) {
1699+ if ($ this ->shareManager ->shareProviderExists ($ shareType )) {
1700+ array_push ($ providers , $ shareType );
1701+ }
1702+ }
1703+ return $ providers ;
1704+ }
1705+
1706+ /**
1707+ * @param string $viewer
1708+ * @param Node $node
1709+ * @param bool $reShares
1710+ *
1711+ * @return IShare[]
1712+ */
1713+ private function getSharesFromNode (string $ viewer , $ node , bool $ reShares ): array {
1714+ $ providers = $ this ->getProvidersExceptOutgoing ();
16511715
16521716 // Should we assume that the (currentUser) viewer is the owner of the node !?
16531717 $ shares = [];
@@ -1785,21 +1849,13 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no
17851849 * @return IShare[]
17861850 */
17871851 private function getAllShares (?Node $ path = null , bool $ reshares = false ) {
1788- // Get all shares
1789- $ userShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_USER , $ path , $ reshares , -1 , 0 );
1790- $ groupShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_GROUP , $ path , $ reshares , -1 , 0 );
1791- $ linkShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_LINK , $ path , $ reshares , -1 , 0 );
1792-
1793- // EMAIL SHARES
1794- $ mailShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_EMAIL , $ path , $ reshares , -1 , 0 );
1795-
1796- // CIRCLE SHARES
1797- $ circleShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_CIRCLE , $ path , $ reshares , -1 , 0 );
1798-
1799- // TALK SHARES
1800- $ roomShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_ROOM , $ path , $ reshares , -1 , 0 );
1801-
1802- $ deckShares = $ this ->shareManager ->getSharesBy ($ this ->currentUser , IShare::TYPE_DECK , $ path , $ reshares , -1 , 0 );
1852+ $ providers = $ this ->getProvidersExceptOutgoing ();
1853+ $ shares = [];
1854+ foreach ($ providers as $ provider ) {
1855+ $ providerShares =
1856+ $ this ->shareManager ->getSharesBy ($ this ->currentUser , $ provider , $ path , $ reshares , -1 , 0 );
1857+ $ shares = array_merge ($ shares , $ providerShares );
1858+ }
18031859
18041860 // FEDERATION
18051861 if ($ this ->shareManager ->outgoingServer2ServerSharesAllowed ()) {
@@ -1813,7 +1869,7 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
18131869 $ federatedGroupShares = [];
18141870 }
18151871
1816- return array_merge ($ userShares , $ groupShares , $ linkShares , $ mailShares , $ circleShares , $ roomShares , $ deckShares , $ federatedShares , $ federatedGroupShares );
1872+ return array_merge ($ shares , $ federatedShares , $ federatedGroupShares );
18171873 }
18181874
18191875
0 commit comments