@@ -29,27 +29,27 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Constants { |
| 31 | 31 | |
| 32 | - const SHARE_TYPE_USER = 0; |
|
| 33 | - const SHARE_TYPE_GROUP = 1; |
|
| 34 | - const SHARE_TYPE_LINK = 3; |
|
| 35 | - const SHARE_TYPE_EMAIL = 4; |
|
| 36 | - const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it |
|
| 37 | - const SHARE_TYPE_REMOTE = 6; |
|
| 38 | - const SHARE_TYPE_CIRCLE = 7; |
|
| 39 | - const SHARE_TYPE_GUEST = 8; |
|
| 40 | - const SHARE_TYPE_REMOTE_GROUP = 9; |
|
| 32 | + const SHARE_TYPE_USER = 0; |
|
| 33 | + const SHARE_TYPE_GROUP = 1; |
|
| 34 | + const SHARE_TYPE_LINK = 3; |
|
| 35 | + const SHARE_TYPE_EMAIL = 4; |
|
| 36 | + const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it |
|
| 37 | + const SHARE_TYPE_REMOTE = 6; |
|
| 38 | + const SHARE_TYPE_CIRCLE = 7; |
|
| 39 | + const SHARE_TYPE_GUEST = 8; |
|
| 40 | + const SHARE_TYPE_REMOTE_GROUP = 9; |
|
| 41 | 41 | |
| 42 | - const FORMAT_NONE = -1; |
|
| 43 | - const FORMAT_STATUSES = -2; |
|
| 44 | - const FORMAT_SOURCES = -3; // ToDo Check if it is still in use otherwise remove it |
|
| 42 | + const FORMAT_NONE = -1; |
|
| 43 | + const FORMAT_STATUSES = -2; |
|
| 44 | + const FORMAT_SOURCES = -3; // ToDo Check if it is still in use otherwise remove it |
|
| 45 | 45 | |
| 46 | - const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls |
|
| 46 | + const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls |
|
| 47 | 47 | |
| 48 | - const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility |
|
| 48 | + const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility |
|
| 49 | 49 | |
| 50 | - protected static $shareTypeUserAndGroups = -1; |
|
| 51 | - protected static $shareTypeGroupUserUnique = 2; |
|
| 52 | - protected static $backends = array(); |
|
| 53 | - protected static $backendTypes = array(); |
|
| 54 | - protected static $isResharingAllowed; |
|
| 50 | + protected static $shareTypeUserAndGroups = -1; |
|
| 51 | + protected static $shareTypeGroupUserUnique = 2; |
|
| 52 | + protected static $backends = array(); |
|
| 53 | + protected static $backendTypes = array(); |
|
| 54 | + protected static $isResharingAllowed; |
|
| 55 | 55 | } |
@@ -35,26 +35,26 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class Config { |
| 37 | 37 | |
| 38 | - /** @var ICloudFederationProviderManager */ |
|
| 39 | - private $cloudFederationProviderManager; |
|
| 40 | - |
|
| 41 | - public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) { |
|
| 42 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * get a list of supported share types |
|
| 47 | - * |
|
| 48 | - * @param string $resourceType |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getSupportedShareTypes($resourceType) { |
|
| 52 | - try { |
|
| 53 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 54 | - return $provider->getSupportedShareTypes(); |
|
| 55 | - } catch (\Exception $e) { |
|
| 56 | - return []; |
|
| 57 | - } |
|
| 58 | - } |
|
| 38 | + /** @var ICloudFederationProviderManager */ |
|
| 39 | + private $cloudFederationProviderManager; |
|
| 40 | + |
|
| 41 | + public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) { |
|
| 42 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * get a list of supported share types |
|
| 47 | + * |
|
| 48 | + * @param string $resourceType |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getSupportedShareTypes($resourceType) { |
|
| 52 | + try { |
|
| 53 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 54 | + return $provider->getSupportedShareTypes(); |
|
| 55 | + } catch (\Exception $e) { |
|
| 56 | + return []; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | script('federatedfilesharing', 'settings-admin'); |
| 5 | 5 | ?> |
| 6 | 6 | |
| 7 | -<?php if($_['internalOnly'] === false): ?> |
|
| 7 | +<?php if ($_['internalOnly'] === false): ?> |
|
| 8 | 8 | |
| 9 | 9 | <div id="fileSharingSettings" class="section"> |
| 10 | 10 | <h2> |
| 11 | - <?php p($l->t('Federated Cloud Sharing'));?> |
|
| 11 | + <?php p($l->t('Federated Cloud Sharing')); ?> |
|
| 12 | 12 | <a target="_blank" rel="noreferrer noopener" class="icon-info svg" |
| 13 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 13 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 14 | 14 | href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a> |
| 15 | 15 | </h2> |
| 16 | 16 | |
@@ -20,29 +20,29 @@ discard block |
||
| 20 | 20 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 21 | 21 | value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 22 | 22 | <label for="outgoingServer2serverShareEnabled"> |
| 23 | - <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
|
| 23 | + <?php p($l->t('Allow users on this server to send shares to other servers')); ?> |
|
| 24 | 24 | </label> |
| 25 | 25 | </p> |
| 26 | 26 | <p> |
| 27 | 27 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 28 | 28 | value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 29 | 29 | <label for="incomingServer2serverShareEnabled"> |
| 30 | - <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
|
| 30 | + <?php p($l->t('Allow users on this server to receive shares from other servers')); ?> |
|
| 31 | 31 | </label><br/> |
| 32 | 32 | </p> |
| 33 | - <?php if($_['federatedGroupSharingSupported']): ?> |
|
| 33 | + <?php if ($_['federatedGroupSharingSupported']): ?> |
|
| 34 | 34 | <p> |
| 35 | 35 | <input type="checkbox" name="outgoing_server2server_group_share_enabled" id="outgoingServer2serverGroupShareEnabled" class="checkbox" |
| 36 | 36 | value="1" <?php if ($_['outgoingServer2serverGroupShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 37 | 37 | <label for="outgoingServer2serverGroupShareEnabled"> |
| 38 | - <?php p($l->t('Allow users on this server to send shares to groups on other servers'));?> |
|
| 38 | + <?php p($l->t('Allow users on this server to send shares to groups on other servers')); ?> |
|
| 39 | 39 | </label> |
| 40 | 40 | </p> |
| 41 | 41 | <p> |
| 42 | 42 | <input type="checkbox" name="incoming_server2server_group_share_enabled" id="incomingServer2serverGroupShareEnabled" class="checkbox" |
| 43 | 43 | value="1" <?php if ($_['incomingServer2serverGroupShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 44 | 44 | <label for="incomingServer2serverGroupShareEnabled"> |
| 45 | - <?php p($l->t('Allow users on this server to receive group shares from other servers'));?> |
|
| 45 | + <?php p($l->t('Allow users on this server to receive group shares from other servers')); ?> |
|
| 46 | 46 | </label><br/> |
| 47 | 47 | </p> |
| 48 | 48 | <?php endif; ?> |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 51 | 51 | value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 52 | 52 | <label for="lookupServerEnabled"> |
| 53 | - <?php p($l->t('Search global and public address book for users'));?> |
|
| 53 | + <?php p($l->t('Search global and public address book for users')); ?> |
|
| 54 | 54 | </label><br/> |
| 55 | 55 | </p> |
| 56 | 56 | <p> |
| 57 | 57 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 58 | 58 | value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 59 | 59 | <label for="lookupServerUploadEnabled"> |
| 60 | - <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
|
| 60 | + <?php p($l->t('Allow users to publish their data to a global and public address book')); ?> |
|
| 61 | 61 | </label><br/> |
| 62 | 62 | </p> |
| 63 | 63 | |
@@ -18,14 +18,20 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | <p> |
| 20 | 20 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 21 | - value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 21 | + value="1" <?php if ($_['outgoingServer2serverShareEnabled']) { |
|
| 22 | + print_unescaped('checked="checked"'); |
|
| 23 | +} |
|
| 24 | +?> /> |
|
| 22 | 25 | <label for="outgoingServer2serverShareEnabled"> |
| 23 | 26 | <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
| 24 | 27 | </label> |
| 25 | 28 | </p> |
| 26 | 29 | <p> |
| 27 | 30 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 28 | - value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 31 | + value="1" <?php if ($_['incomingServer2serverShareEnabled']) { |
|
| 32 | + print_unescaped('checked="checked"'); |
|
| 33 | +} |
|
| 34 | +?> /> |
|
| 29 | 35 | <label for="incomingServer2serverShareEnabled"> |
| 30 | 36 | <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
| 31 | 37 | </label><br/> |
@@ -33,14 +39,20 @@ discard block |
||
| 33 | 39 | <?php if($_['federatedGroupSharingSupported']): ?> |
| 34 | 40 | <p> |
| 35 | 41 | <input type="checkbox" name="outgoing_server2server_group_share_enabled" id="outgoingServer2serverGroupShareEnabled" class="checkbox" |
| 36 | - value="1" <?php if ($_['outgoingServer2serverGroupShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 42 | + value="1" <?php if ($_['outgoingServer2serverGroupShareEnabled']) { |
|
| 43 | + print_unescaped('checked="checked"'); |
|
| 44 | +} |
|
| 45 | +?> /> |
|
| 37 | 46 | <label for="outgoingServer2serverGroupShareEnabled"> |
| 38 | 47 | <?php p($l->t('Allow users on this server to send shares to groups on other servers'));?> |
| 39 | 48 | </label> |
| 40 | 49 | </p> |
| 41 | 50 | <p> |
| 42 | 51 | <input type="checkbox" name="incoming_server2server_group_share_enabled" id="incomingServer2serverGroupShareEnabled" class="checkbox" |
| 43 | - value="1" <?php if ($_['incomingServer2serverGroupShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 52 | + value="1" <?php if ($_['incomingServer2serverGroupShareEnabled']) { |
|
| 53 | + print_unescaped('checked="checked"'); |
|
| 54 | +} |
|
| 55 | +?> /> |
|
| 44 | 56 | <label for="incomingServer2serverGroupShareEnabled"> |
| 45 | 57 | <?php p($l->t('Allow users on this server to receive group shares from other servers'));?> |
| 46 | 58 | </label><br/> |
@@ -48,14 +60,20 @@ discard block |
||
| 48 | 60 | <?php endif; ?> |
| 49 | 61 | <p> |
| 50 | 62 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 51 | - value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 63 | + value="1" <?php if ($_['lookupServerEnabled']) { |
|
| 64 | + print_unescaped('checked="checked"'); |
|
| 65 | +} |
|
| 66 | +?> /> |
|
| 52 | 67 | <label for="lookupServerEnabled"> |
| 53 | 68 | <?php p($l->t('Search global and public address book for users'));?> |
| 54 | 69 | </label><br/> |
| 55 | 70 | </p> |
| 56 | 71 | <p> |
| 57 | 72 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 58 | - value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 73 | + value="1" <?php if ($_['lookupServerUploadEnabled']) { |
|
| 74 | + print_unescaped('checked="checked"'); |
|
| 75 | +} |
|
| 76 | +?> /> |
|
| 59 | 77 | <label for="lookupServerUploadEnabled"> |
| 60 | 78 | <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
| 61 | 79 | </label><br/> |
@@ -32,58 +32,58 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Admin implements ISettings { |
| 34 | 34 | |
| 35 | - /** @var FederatedShareProvider */ |
|
| 36 | - private $fedShareProvider; |
|
| 35 | + /** @var FederatedShareProvider */ |
|
| 36 | + private $fedShareProvider; |
|
| 37 | 37 | |
| 38 | - /** @var IConfig */ |
|
| 39 | - private $gsConfig; |
|
| 38 | + /** @var IConfig */ |
|
| 39 | + private $gsConfig; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Admin constructor. |
|
| 43 | - * |
|
| 44 | - * @param FederatedShareProvider $fedShareProvider |
|
| 45 | - * @param IConfig $globalScaleConfig |
|
| 46 | - */ |
|
| 47 | - public function __construct(FederatedShareProvider $fedShareProvider, IConfig $globalScaleConfig) { |
|
| 48 | - $this->fedShareProvider = $fedShareProvider; |
|
| 49 | - $this->gsConfig = $globalScaleConfig; |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * Admin constructor. |
|
| 43 | + * |
|
| 44 | + * @param FederatedShareProvider $fedShareProvider |
|
| 45 | + * @param IConfig $globalScaleConfig |
|
| 46 | + */ |
|
| 47 | + public function __construct(FederatedShareProvider $fedShareProvider, IConfig $globalScaleConfig) { |
|
| 48 | + $this->fedShareProvider = $fedShareProvider; |
|
| 49 | + $this->gsConfig = $globalScaleConfig; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return TemplateResponse |
|
| 54 | - */ |
|
| 55 | - public function getForm() { |
|
| 52 | + /** |
|
| 53 | + * @return TemplateResponse |
|
| 54 | + */ |
|
| 55 | + public function getForm() { |
|
| 56 | 56 | |
| 57 | - $parameters = [ |
|
| 58 | - 'internalOnly' => $this->gsConfig->onlyInternalFederation(), |
|
| 59 | - 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 60 | - 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
| 61 | - 'federatedGroupSharingSupported' => $this->fedShareProvider->isFederatedGroupSharingSupported(), |
|
| 62 | - 'outgoingServer2serverGroupShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverGroupShareEnabled(), |
|
| 63 | - 'incomingServer2serverGroupShareEnabled' => $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled(), |
|
| 64 | - 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
| 65 | - 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
| 66 | - ]; |
|
| 57 | + $parameters = [ |
|
| 58 | + 'internalOnly' => $this->gsConfig->onlyInternalFederation(), |
|
| 59 | + 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 60 | + 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
| 61 | + 'federatedGroupSharingSupported' => $this->fedShareProvider->isFederatedGroupSharingSupported(), |
|
| 62 | + 'outgoingServer2serverGroupShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverGroupShareEnabled(), |
|
| 63 | + 'incomingServer2serverGroupShareEnabled' => $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled(), |
|
| 64 | + 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
| 65 | + 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
| 66 | + ]; |
|
| 67 | 67 | |
| 68 | - return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
| 69 | - } |
|
| 68 | + return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string the section ID, e.g. 'sharing' |
|
| 73 | - */ |
|
| 74 | - public function getSection() { |
|
| 75 | - return 'sharing'; |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * @return string the section ID, e.g. 'sharing' |
|
| 73 | + */ |
|
| 74 | + public function getSection() { |
|
| 75 | + return 'sharing'; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return int whether the form should be rather on the top or bottom of |
|
| 80 | - * the admin section. The forms are arranged in ascending order of the |
|
| 81 | - * priority values. It is required to return a value between 0 and 100. |
|
| 82 | - * |
|
| 83 | - * E.g.: 70 |
|
| 84 | - */ |
|
| 85 | - public function getPriority() { |
|
| 86 | - return 20; |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * @return int whether the form should be rather on the top or bottom of |
|
| 80 | + * the admin section. The forms are arranged in ascending order of the |
|
| 81 | + * priority values. It is required to return a value between 0 and 100. |
|
| 82 | + * |
|
| 83 | + * E.g.: 70 |
|
| 84 | + */ |
|
| 85 | + public function getPriority() { |
|
| 86 | + return 20; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * share received from another server |
| 151 | 151 | * |
| 152 | 152 | * @param ICloudFederationShare $share |
| 153 | - * @return string provider specific unique ID of the share |
|
| 153 | + * @return integer provider specific unique ID of the share |
|
| 154 | 154 | * |
| 155 | 155 | * @throws ProviderCouldNotAddShareException |
| 156 | 156 | * @throws \OCP\AppFramework\QueryException |
@@ -325,11 +325,11 @@ discard block |
||
| 325 | 325 | /** |
| 326 | 326 | * notify user about new federated share |
| 327 | 327 | * |
| 328 | - * @param $shareWith |
|
| 329 | - * @param $shareId |
|
| 330 | - * @param $ownerFederatedId |
|
| 331 | - * @param $sharedByFederatedId |
|
| 332 | - * @param $name |
|
| 328 | + * @param string $shareWith |
|
| 329 | + * @param integer $shareId |
|
| 330 | + * @param string $ownerFederatedId |
|
| 331 | + * @param string $sharedByFederatedId |
|
| 332 | + * @param string $name |
|
| 333 | 333 | */ |
| 334 | 334 | private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { |
| 335 | 335 | $notification = $this->notificationManager->createNotification(); |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | /** |
| 822 | 822 | * get the supported share types, e.g. "user", "group", etc. |
| 823 | 823 | * |
| 824 | - * @return array |
|
| 824 | + * @return string[] |
|
| 825 | 825 | * |
| 826 | 826 | * @since 14.0.0 |
| 827 | 827 | */ |
@@ -52,789 +52,789 @@ |
||
| 52 | 52 | |
| 53 | 53 | class CloudFederationProviderFiles implements ICloudFederationProvider { |
| 54 | 54 | |
| 55 | - /** @var IAppManager */ |
|
| 56 | - private $appManager; |
|
| 57 | - |
|
| 58 | - /** @var FederatedShareProvider */ |
|
| 59 | - private $federatedShareProvider; |
|
| 60 | - |
|
| 61 | - /** @var AddressHandler */ |
|
| 62 | - private $addressHandler; |
|
| 63 | - |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** @var IUserManager */ |
|
| 68 | - private $userManager; |
|
| 69 | - |
|
| 70 | - /** @var ICloudIdManager */ |
|
| 71 | - private $cloudIdManager; |
|
| 72 | - |
|
| 73 | - /** @var IActivityManager */ |
|
| 74 | - private $activityManager; |
|
| 75 | - |
|
| 76 | - /** @var INotificationManager */ |
|
| 77 | - private $notificationManager; |
|
| 78 | - |
|
| 79 | - /** @var IURLGenerator */ |
|
| 80 | - private $urlGenerator; |
|
| 81 | - |
|
| 82 | - /** @var ICloudFederationFactory */ |
|
| 83 | - private $cloudFederationFactory; |
|
| 84 | - |
|
| 85 | - /** @var ICloudFederationProviderManager */ |
|
| 86 | - private $cloudFederationProviderManager; |
|
| 87 | - |
|
| 88 | - /** @var IDBConnection */ |
|
| 89 | - private $connection; |
|
| 90 | - |
|
| 91 | - /** @var IGroupManager */ |
|
| 92 | - private $groupManager; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * CloudFederationProvider constructor. |
|
| 96 | - * |
|
| 97 | - * @param IAppManager $appManager |
|
| 98 | - * @param FederatedShareProvider $federatedShareProvider |
|
| 99 | - * @param AddressHandler $addressHandler |
|
| 100 | - * @param ILogger $logger |
|
| 101 | - * @param IUserManager $userManager |
|
| 102 | - * @param ICloudIdManager $cloudIdManager |
|
| 103 | - * @param IActivityManager $activityManager |
|
| 104 | - * @param INotificationManager $notificationManager |
|
| 105 | - * @param IURLGenerator $urlGenerator |
|
| 106 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
| 107 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 108 | - * @param IDBConnection $connection |
|
| 109 | - * @param IGroupManager $groupManager |
|
| 110 | - */ |
|
| 111 | - public function __construct(IAppManager $appManager, |
|
| 112 | - FederatedShareProvider $federatedShareProvider, |
|
| 113 | - AddressHandler $addressHandler, |
|
| 114 | - ILogger $logger, |
|
| 115 | - IUserManager $userManager, |
|
| 116 | - ICloudIdManager $cloudIdManager, |
|
| 117 | - IActivityManager $activityManager, |
|
| 118 | - INotificationManager $notificationManager, |
|
| 119 | - IURLGenerator $urlGenerator, |
|
| 120 | - ICloudFederationFactory $cloudFederationFactory, |
|
| 121 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 122 | - IDBConnection $connection, |
|
| 123 | - IGroupManager $groupManager |
|
| 124 | - ) { |
|
| 125 | - $this->appManager = $appManager; |
|
| 126 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 127 | - $this->addressHandler = $addressHandler; |
|
| 128 | - $this->logger = $logger; |
|
| 129 | - $this->userManager = $userManager; |
|
| 130 | - $this->cloudIdManager = $cloudIdManager; |
|
| 131 | - $this->activityManager = $activityManager; |
|
| 132 | - $this->notificationManager = $notificationManager; |
|
| 133 | - $this->urlGenerator = $urlGenerator; |
|
| 134 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 135 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 136 | - $this->connection = $connection; |
|
| 137 | - $this->groupManager = $groupManager; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function getShareType() { |
|
| 146 | - return 'file'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * share received from another server |
|
| 151 | - * |
|
| 152 | - * @param ICloudFederationShare $share |
|
| 153 | - * @return string provider specific unique ID of the share |
|
| 154 | - * |
|
| 155 | - * @throws ProviderCouldNotAddShareException |
|
| 156 | - * @throws \OCP\AppFramework\QueryException |
|
| 157 | - * @throws \OC\HintException |
|
| 158 | - * @since 14.0.0 |
|
| 159 | - */ |
|
| 160 | - public function shareReceived(ICloudFederationShare $share) { |
|
| 161 | - |
|
| 162 | - if (!$this->isS2SEnabled(true)) { |
|
| 163 | - throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $protocol = $share->getProtocol(); |
|
| 167 | - if ($protocol['name'] !== 'webdav') { |
|
| 168 | - throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 172 | - // for backward compatibility make sure that the remote url stored in the |
|
| 173 | - // database ends with a trailing slash |
|
| 174 | - if (substr($remote, -1) !== '/') { |
|
| 175 | - $remote = $remote . '/'; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $token = $share->getShareSecret(); |
|
| 179 | - $name = $share->getResourceName(); |
|
| 180 | - $owner = $share->getOwnerDisplayName(); |
|
| 181 | - $sharedBy = $share->getSharedByDisplayName(); |
|
| 182 | - $shareWith = $share->getShareWith(); |
|
| 183 | - $remoteId = $share->getProviderId(); |
|
| 184 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 185 | - $ownerFederatedId = $share->getOwner(); |
|
| 186 | - $shareType = $this->mapShareTypeToNextcloud($share->getShareType()); |
|
| 187 | - |
|
| 188 | - // if no explicit information about the person who created the share was send |
|
| 189 | - // we assume that the share comes from the owner |
|
| 190 | - if ($sharedByFederatedId === null) { |
|
| 191 | - $sharedBy = $owner; |
|
| 192 | - $sharedByFederatedId = $ownerFederatedId; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 196 | - |
|
| 197 | - if (!Util::isValidFileName($name)) { |
|
| 198 | - throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // FIXME this should be a method in the user management instead |
|
| 202 | - if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 203 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 204 | - Util::emitHook( |
|
| 205 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 206 | - 'preLoginNameUsedAsUserName', |
|
| 207 | - array('uid' => &$shareWith) |
|
| 208 | - ); |
|
| 209 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 210 | - |
|
| 211 | - if (!$this->userManager->userExists($shareWith)) { |
|
| 212 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - \OC_Util::setupFS($shareWith); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($shareType === Share::SHARE_TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) { |
|
| 219 | - throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 223 | - \OC::$server->getDatabaseConnection(), |
|
| 224 | - Filesystem::getMountManager(), |
|
| 225 | - Filesystem::getLoader(), |
|
| 226 | - \OC::$server->getHTTPClientService(), |
|
| 227 | - \OC::$server->getNotificationManager(), |
|
| 228 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 229 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 230 | - \OC::$server->getCloudFederationFactory(), |
|
| 231 | - \OC::$server->getGroupManager(), |
|
| 232 | - \OC::$server->getUserManager(), |
|
| 233 | - $shareWith |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - try { |
|
| 237 | - $externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); |
|
| 238 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 239 | - |
|
| 240 | - if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 241 | - $event = $this->activityManager->generateEvent(); |
|
| 242 | - $event->setApp('files_sharing') |
|
| 243 | - ->setType('remote_share') |
|
| 244 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 245 | - ->setAffectedUser($shareWith) |
|
| 246 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 247 | - \OC::$server->getActivityManager()->publish($event); |
|
| 248 | - $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 249 | - } else { |
|
| 250 | - $groupMembers = $this->groupManager->get($shareWith)->getUsers(); |
|
| 251 | - foreach ($groupMembers as $user) { |
|
| 252 | - $event = $this->activityManager->generateEvent(); |
|
| 253 | - $event->setApp('files_sharing') |
|
| 254 | - ->setType('remote_share') |
|
| 255 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 256 | - ->setAffectedUser($user->getUID()) |
|
| 257 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 258 | - \OC::$server->getActivityManager()->publish($event); |
|
| 259 | - $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - return $shareId; |
|
| 263 | - } catch (\Exception $e) { |
|
| 264 | - $this->logger->logException($e, [ |
|
| 265 | - 'message' => 'Server can not add remote share.', |
|
| 266 | - 'level' => ILogger::ERROR, |
|
| 267 | - 'app' => 'files_sharing' |
|
| 268 | - ]); |
|
| 269 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * notification received from another server |
|
| 279 | - * |
|
| 280 | - * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
| 281 | - * @param string $providerId id of the share |
|
| 282 | - * @param array $notification payload of the notification |
|
| 283 | - * @return array data send back to the sender |
|
| 284 | - * |
|
| 285 | - * @throws ActionNotSupportedException |
|
| 286 | - * @throws AuthenticationFailedException |
|
| 287 | - * @throws BadRequestException |
|
| 288 | - * @throws \OC\HintException |
|
| 289 | - * @since 14.0.0 |
|
| 290 | - */ |
|
| 291 | - public function notificationReceived($notificationType, $providerId, array $notification) { |
|
| 292 | - |
|
| 293 | - switch ($notificationType) { |
|
| 294 | - case 'SHARE_ACCEPTED': |
|
| 295 | - return $this->shareAccepted($providerId, $notification); |
|
| 296 | - case 'SHARE_DECLINED': |
|
| 297 | - return $this->shareDeclined($providerId, $notification); |
|
| 298 | - case 'SHARE_UNSHARED': |
|
| 299 | - return $this->unshare($providerId, $notification); |
|
| 300 | - case 'REQUEST_RESHARE': |
|
| 301 | - return $this->reshareRequested($providerId, $notification); |
|
| 302 | - case 'RESHARE_UNDO': |
|
| 303 | - return $this->undoReshare($providerId, $notification); |
|
| 304 | - case 'RESHARE_CHANGE_PERMISSION': |
|
| 305 | - return $this->updateResharePermissions($providerId, $notification); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - throw new BadRequestException([$notificationType]); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * map OCM share type (strings) to Nextcloud internal share types (integer) |
|
| 314 | - * |
|
| 315 | - * @param string $shareType |
|
| 316 | - * @return int |
|
| 317 | - */ |
|
| 318 | - private function mapShareTypeToNextcloud($shareType) { |
|
| 319 | - $result = Share::SHARE_TYPE_USER; |
|
| 320 | - if ($shareType === 'group') { |
|
| 321 | - $result = Share::SHARE_TYPE_GROUP; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $result; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * notify user about new federated share |
|
| 329 | - * |
|
| 330 | - * @param $shareWith |
|
| 331 | - * @param $shareId |
|
| 332 | - * @param $ownerFederatedId |
|
| 333 | - * @param $sharedByFederatedId |
|
| 334 | - * @param $name |
|
| 335 | - */ |
|
| 336 | - private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { |
|
| 337 | - $notification = $this->notificationManager->createNotification(); |
|
| 338 | - $notification->setApp('files_sharing') |
|
| 339 | - ->setUser($shareWith) |
|
| 340 | - ->setDateTime(new \DateTime()) |
|
| 341 | - ->setObject('remote_share', $shareId) |
|
| 342 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 343 | - |
|
| 344 | - $declineAction = $notification->createAction(); |
|
| 345 | - $declineAction->setLabel('decline') |
|
| 346 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 347 | - $notification->addAction($declineAction); |
|
| 348 | - |
|
| 349 | - $acceptAction = $notification->createAction(); |
|
| 350 | - $acceptAction->setLabel('accept') |
|
| 351 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 352 | - $notification->addAction($acceptAction); |
|
| 353 | - |
|
| 354 | - $this->notificationManager->notify($notification); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * process notification that the recipient accepted a share |
|
| 359 | - * |
|
| 360 | - * @param string $id |
|
| 361 | - * @param array $notification |
|
| 362 | - * @return array |
|
| 363 | - * @throws ActionNotSupportedException |
|
| 364 | - * @throws AuthenticationFailedException |
|
| 365 | - * @throws BadRequestException |
|
| 366 | - * @throws \OC\HintException |
|
| 367 | - */ |
|
| 368 | - private function shareAccepted($id, array $notification) { |
|
| 369 | - |
|
| 370 | - if (!$this->isS2SEnabled()) { |
|
| 371 | - throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if (!isset($notification['sharedSecret'])) { |
|
| 375 | - throw new BadRequestException(['sharedSecret']); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $token = $notification['sharedSecret']; |
|
| 379 | - |
|
| 380 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 381 | - |
|
| 382 | - $this->verifyShare($share, $token); |
|
| 383 | - $this->executeAcceptShare($share); |
|
| 384 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 385 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 386 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 387 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 388 | - $notification->setMessage( |
|
| 389 | - 'SHARE_ACCEPTED', |
|
| 390 | - 'file', |
|
| 391 | - $remoteId, |
|
| 392 | - [ |
|
| 393 | - 'sharedSecret' => $token, |
|
| 394 | - 'message' => 'Recipient accepted the re-share' |
|
| 395 | - ] |
|
| 396 | - |
|
| 397 | - ); |
|
| 398 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 399 | - |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - return []; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @param IShare $share |
|
| 407 | - * @throws ShareNotFound |
|
| 408 | - */ |
|
| 409 | - protected function executeAcceptShare(IShare $share) { |
|
| 410 | - try { |
|
| 411 | - $fileId = (int)$share->getNode()->getId(); |
|
| 412 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 413 | - } catch (\Exception $e) { |
|
| 414 | - throw new ShareNotFound(); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $event = $this->activityManager->generateEvent(); |
|
| 418 | - $event->setApp('files_sharing') |
|
| 419 | - ->setType('remote_share') |
|
| 420 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
| 421 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 422 | - ->setObject('files', $fileId, $file) |
|
| 423 | - ->setLink($link); |
|
| 424 | - $this->activityManager->publish($event); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * process notification that the recipient declined a share |
|
| 429 | - * |
|
| 430 | - * @param string $id |
|
| 431 | - * @param array $notification |
|
| 432 | - * @return array |
|
| 433 | - * @throws ActionNotSupportedException |
|
| 434 | - * @throws AuthenticationFailedException |
|
| 435 | - * @throws BadRequestException |
|
| 436 | - * @throws ShareNotFound |
|
| 437 | - * @throws \OC\HintException |
|
| 438 | - * |
|
| 439 | - */ |
|
| 440 | - protected function shareDeclined($id, array $notification) { |
|
| 441 | - |
|
| 442 | - if (!$this->isS2SEnabled()) { |
|
| 443 | - throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - if (!isset($notification['sharedSecret'])) { |
|
| 447 | - throw new BadRequestException(['sharedSecret']); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - $token = $notification['sharedSecret']; |
|
| 451 | - |
|
| 452 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 453 | - |
|
| 454 | - $this->verifyShare($share, $token); |
|
| 455 | - |
|
| 456 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 457 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 458 | - $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 459 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 460 | - $notification->setMessage( |
|
| 461 | - 'SHARE_DECLINED', |
|
| 462 | - 'file', |
|
| 463 | - $remoteId, |
|
| 464 | - [ |
|
| 465 | - 'sharedSecret' => $token, |
|
| 466 | - 'message' => 'Recipient declined the re-share' |
|
| 467 | - ] |
|
| 468 | - |
|
| 469 | - ); |
|
| 470 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - $this->executeDeclineShare($share); |
|
| 474 | - |
|
| 475 | - return []; |
|
| 476 | - |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * delete declined share and create a activity |
|
| 481 | - * |
|
| 482 | - * @param IShare $share |
|
| 483 | - * @throws ShareNotFound |
|
| 484 | - */ |
|
| 485 | - protected function executeDeclineShare(IShare $share) { |
|
| 486 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
| 487 | - |
|
| 488 | - try { |
|
| 489 | - $fileId = (int)$share->getNode()->getId(); |
|
| 490 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 491 | - } catch (\Exception $e) { |
|
| 492 | - throw new ShareNotFound(); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $event = $this->activityManager->generateEvent(); |
|
| 496 | - $event->setApp('files_sharing') |
|
| 497 | - ->setType('remote_share') |
|
| 498 | - ->setAffectedUser($this->getCorrectUid($share)) |
|
| 499 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 500 | - ->setObject('files', $fileId, $file) |
|
| 501 | - ->setLink($link); |
|
| 502 | - $this->activityManager->publish($event); |
|
| 503 | - |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * received the notification that the owner unshared a file from you |
|
| 508 | - * |
|
| 509 | - * @param string $id |
|
| 510 | - * @param array $notification |
|
| 511 | - * @return array |
|
| 512 | - * @throws AuthenticationFailedException |
|
| 513 | - * @throws BadRequestException |
|
| 514 | - */ |
|
| 515 | - private function undoReshare($id, array $notification) { |
|
| 516 | - if (!isset($notification['sharedSecret'])) { |
|
| 517 | - throw new BadRequestException(['sharedSecret']); |
|
| 518 | - } |
|
| 519 | - $token = $notification['sharedSecret']; |
|
| 520 | - |
|
| 521 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 522 | - |
|
| 523 | - $this->verifyShare($share, $token); |
|
| 524 | - $this->federatedShareProvider->removeShareFromTable($share); |
|
| 525 | - return []; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * unshare file from self |
|
| 530 | - * |
|
| 531 | - * @param string $id |
|
| 532 | - * @param array $notification |
|
| 533 | - * @return array |
|
| 534 | - * @throws ActionNotSupportedException |
|
| 535 | - * @throws BadRequestException |
|
| 536 | - */ |
|
| 537 | - private function unshare($id, array $notification) { |
|
| 538 | - |
|
| 539 | - if (!$this->isS2SEnabled(true)) { |
|
| 540 | - throw new ActionNotSupportedException("incoming shares disabled!"); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if (!isset($notification['sharedSecret'])) { |
|
| 544 | - throw new BadRequestException(['sharedSecret']); |
|
| 545 | - } |
|
| 546 | - $token = $notification['sharedSecret']; |
|
| 547 | - |
|
| 548 | - $qb = $this->connection->getQueryBuilder(); |
|
| 549 | - $qb->select('*') |
|
| 550 | - ->from('share_external') |
|
| 551 | - ->where( |
|
| 552 | - $qb->expr()->andX( |
|
| 553 | - $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 554 | - $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 555 | - ) |
|
| 556 | - ); |
|
| 557 | - |
|
| 558 | - $result = $qb->execute(); |
|
| 559 | - $share = $result->fetch(); |
|
| 560 | - $result->closeCursor(); |
|
| 561 | - |
|
| 562 | - if ($token && $id && !empty($share)) { |
|
| 563 | - |
|
| 564 | - $remote = $this->cleanupRemote($share['remote']); |
|
| 565 | - |
|
| 566 | - $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
| 567 | - $mountpoint = $share['mountpoint']; |
|
| 568 | - $user = $share['user']; |
|
| 569 | - |
|
| 570 | - $qb = $this->connection->getQueryBuilder(); |
|
| 571 | - $qb->delete('share_external') |
|
| 572 | - ->where( |
|
| 573 | - $qb->expr()->andX( |
|
| 574 | - $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 575 | - $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - |
|
| 579 | - $qb->execute(); |
|
| 580 | - |
|
| 581 | - // delete all child in case of a group share |
|
| 582 | - $qb = $this->connection->getQueryBuilder(); |
|
| 583 | - $qb->delete('share_external') |
|
| 584 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id']))); |
|
| 585 | - $qb->execute(); |
|
| 586 | - |
|
| 587 | - if ((int)$share['share_type'] === Share::SHARE_TYPE_USER) { |
|
| 588 | - if ($share['accepted']) { |
|
| 589 | - $path = trim($mountpoint, '/'); |
|
| 590 | - } else { |
|
| 591 | - $path = trim($share['name'], '/'); |
|
| 592 | - } |
|
| 593 | - $notification = $this->notificationManager->createNotification(); |
|
| 594 | - $notification->setApp('files_sharing') |
|
| 595 | - ->setUser($share['user']) |
|
| 596 | - ->setObject('remote_share', (int)$share['id']); |
|
| 597 | - $this->notificationManager->markProcessed($notification); |
|
| 598 | - |
|
| 599 | - $event = $this->activityManager->generateEvent(); |
|
| 600 | - $event->setApp('files_sharing') |
|
| 601 | - ->setType('remote_share') |
|
| 602 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) |
|
| 603 | - ->setAffectedUser($user) |
|
| 604 | - ->setObject('remote_share', (int)$share['id'], $path); |
|
| 605 | - \OC::$server->getActivityManager()->publish($event); |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - return []; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - private function cleanupRemote($remote) { |
|
| 613 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 614 | - |
|
| 615 | - return rtrim($remote, '/'); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * recipient of a share request to re-share the file with another user |
|
| 620 | - * |
|
| 621 | - * @param string $id |
|
| 622 | - * @param array $notification |
|
| 623 | - * @return array |
|
| 624 | - * @throws AuthenticationFailedException |
|
| 625 | - * @throws BadRequestException |
|
| 626 | - * @throws ProviderCouldNotAddShareException |
|
| 627 | - * @throws ShareNotFound |
|
| 628 | - */ |
|
| 629 | - protected function reshareRequested($id, array $notification) { |
|
| 630 | - |
|
| 631 | - if (!isset($notification['sharedSecret'])) { |
|
| 632 | - throw new BadRequestException(['sharedSecret']); |
|
| 633 | - } |
|
| 634 | - $token = $notification['sharedSecret']; |
|
| 635 | - |
|
| 636 | - if (!isset($notification['shareWith'])) { |
|
| 637 | - throw new BadRequestException(['shareWith']); |
|
| 638 | - } |
|
| 639 | - $shareWith = $notification['shareWith']; |
|
| 640 | - |
|
| 641 | - if (!isset($notification['senderId'])) { |
|
| 642 | - throw new BadRequestException(['senderId']); |
|
| 643 | - } |
|
| 644 | - $senderId = $notification['senderId']; |
|
| 645 | - |
|
| 646 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 647 | - // don't allow to share a file back to the owner |
|
| 648 | - try { |
|
| 649 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 650 | - $owner = $share->getShareOwner(); |
|
| 651 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 652 | - if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { |
|
| 653 | - throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); |
|
| 654 | - } |
|
| 655 | - } catch (\Exception $e) { |
|
| 656 | - throw new ProviderCouldNotAddShareException($e->getMessage()); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->verifyShare($share, $token); |
|
| 660 | - |
|
| 661 | - // check if re-sharing is allowed |
|
| 662 | - if ($share->getPermissions() & Constants::PERMISSION_SHARE) { |
|
| 663 | - // the recipient of the initial share is now the initiator for the re-share |
|
| 664 | - $share->setSharedBy($share->getSharedWith()); |
|
| 665 | - $share->setSharedWith($shareWith); |
|
| 666 | - $result = $this->federatedShareProvider->create($share); |
|
| 667 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId); |
|
| 668 | - return ['token' => $result->getToken(), 'providerId' => $result->getId()]; |
|
| 669 | - } else { |
|
| 670 | - throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * update permission of a re-share so that the share dialog shows the right |
|
| 677 | - * permission if the owner or the sender changes the permission |
|
| 678 | - * |
|
| 679 | - * @param string $id |
|
| 680 | - * @param array $notification |
|
| 681 | - * @return array |
|
| 682 | - * @throws AuthenticationFailedException |
|
| 683 | - * @throws BadRequestException |
|
| 684 | - */ |
|
| 685 | - protected function updateResharePermissions($id, array $notification) { |
|
| 686 | - |
|
| 687 | - if (!isset($notification['sharedSecret'])) { |
|
| 688 | - throw new BadRequestException(['sharedSecret']); |
|
| 689 | - } |
|
| 690 | - $token = $notification['sharedSecret']; |
|
| 691 | - |
|
| 692 | - if (!isset($notification['permission'])) { |
|
| 693 | - throw new BadRequestException(['permission']); |
|
| 694 | - } |
|
| 695 | - $ocmPermissions = $notification['permission']; |
|
| 696 | - |
|
| 697 | - $share = $this->federatedShareProvider->getShareById($id); |
|
| 698 | - |
|
| 699 | - $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions); |
|
| 700 | - |
|
| 701 | - $this->verifyShare($share, $token); |
|
| 702 | - $this->updatePermissionsInDatabase($share, $ncPermission); |
|
| 703 | - |
|
| 704 | - return []; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * translate OCM Permissions to Nextcloud permissions |
|
| 709 | - * |
|
| 710 | - * @param array $ocmPermissions |
|
| 711 | - * @return int |
|
| 712 | - * @throws BadRequestException |
|
| 713 | - */ |
|
| 714 | - protected function ocmPermissions2ncPermissions(array $ocmPermissions) { |
|
| 715 | - $ncPermissions = 0; |
|
| 716 | - foreach($ocmPermissions as $permission) { |
|
| 717 | - switch (strtolower($permission)) { |
|
| 718 | - case 'read': |
|
| 719 | - $ncPermissions += Constants::PERMISSION_READ; |
|
| 720 | - break; |
|
| 721 | - case 'write': |
|
| 722 | - $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE; |
|
| 723 | - break; |
|
| 724 | - case 'share': |
|
| 725 | - $ncPermissions += Constants::PERMISSION_SHARE; |
|
| 726 | - break; |
|
| 727 | - default: |
|
| 728 | - throw new BadRequestException(['permission']); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - return $ncPermissions; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * update permissions in database |
|
| 738 | - * |
|
| 739 | - * @param IShare $share |
|
| 740 | - * @param int $permissions |
|
| 741 | - */ |
|
| 742 | - protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
| 743 | - $query = $this->connection->getQueryBuilder(); |
|
| 744 | - $query->update('share') |
|
| 745 | - ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
| 746 | - ->set('permissions', $query->createNamedParameter($permissions)) |
|
| 747 | - ->execute(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * get file |
|
| 753 | - * |
|
| 754 | - * @param string $user |
|
| 755 | - * @param int $fileSource |
|
| 756 | - * @return array with internal path of the file and a absolute link to it |
|
| 757 | - */ |
|
| 758 | - private function getFile($user, $fileSource) { |
|
| 759 | - \OC_Util::setupFS($user); |
|
| 760 | - |
|
| 761 | - try { |
|
| 762 | - $file = Filesystem::getPath($fileSource); |
|
| 763 | - } catch (NotFoundException $e) { |
|
| 764 | - $file = null; |
|
| 765 | - } |
|
| 766 | - $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
| 767 | - $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
| 768 | - |
|
| 769 | - return [$file, $link]; |
|
| 770 | - |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * check if we are the initiator or the owner of a re-share and return the correct UID |
|
| 775 | - * |
|
| 776 | - * @param IShare $share |
|
| 777 | - * @return string |
|
| 778 | - */ |
|
| 779 | - protected function getCorrectUid(IShare $share) { |
|
| 780 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 781 | - return $share->getShareOwner(); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - return $share->getSharedBy(); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * check if we got the right share |
|
| 791 | - * |
|
| 792 | - * @param IShare $share |
|
| 793 | - * @param string $token |
|
| 794 | - * @return bool |
|
| 795 | - * @throws AuthenticationFailedException |
|
| 796 | - */ |
|
| 797 | - protected function verifyShare(IShare $share, $token) { |
|
| 798 | - if ( |
|
| 799 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
| 800 | - $share->getToken() === $token |
|
| 801 | - ) { |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - throw new AuthenticationFailedException(); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * check if server-to-server sharing is enabled |
|
| 812 | - * |
|
| 813 | - * @param bool $incoming |
|
| 814 | - * @return bool |
|
| 815 | - */ |
|
| 816 | - private function isS2SEnabled($incoming = false) { |
|
| 817 | - |
|
| 818 | - $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 819 | - |
|
| 820 | - if ($incoming) { |
|
| 821 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 822 | - } else { |
|
| 823 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - return $result; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * get the supported share types, e.g. "user", "group", etc. |
|
| 832 | - * |
|
| 833 | - * @return array |
|
| 834 | - * |
|
| 835 | - * @since 14.0.0 |
|
| 836 | - */ |
|
| 837 | - public function getSupportedShareTypes() { |
|
| 838 | - return ['user', 'group']; |
|
| 839 | - } |
|
| 55 | + /** @var IAppManager */ |
|
| 56 | + private $appManager; |
|
| 57 | + |
|
| 58 | + /** @var FederatedShareProvider */ |
|
| 59 | + private $federatedShareProvider; |
|
| 60 | + |
|
| 61 | + /** @var AddressHandler */ |
|
| 62 | + private $addressHandler; |
|
| 63 | + |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** @var IUserManager */ |
|
| 68 | + private $userManager; |
|
| 69 | + |
|
| 70 | + /** @var ICloudIdManager */ |
|
| 71 | + private $cloudIdManager; |
|
| 72 | + |
|
| 73 | + /** @var IActivityManager */ |
|
| 74 | + private $activityManager; |
|
| 75 | + |
|
| 76 | + /** @var INotificationManager */ |
|
| 77 | + private $notificationManager; |
|
| 78 | + |
|
| 79 | + /** @var IURLGenerator */ |
|
| 80 | + private $urlGenerator; |
|
| 81 | + |
|
| 82 | + /** @var ICloudFederationFactory */ |
|
| 83 | + private $cloudFederationFactory; |
|
| 84 | + |
|
| 85 | + /** @var ICloudFederationProviderManager */ |
|
| 86 | + private $cloudFederationProviderManager; |
|
| 87 | + |
|
| 88 | + /** @var IDBConnection */ |
|
| 89 | + private $connection; |
|
| 90 | + |
|
| 91 | + /** @var IGroupManager */ |
|
| 92 | + private $groupManager; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * CloudFederationProvider constructor. |
|
| 96 | + * |
|
| 97 | + * @param IAppManager $appManager |
|
| 98 | + * @param FederatedShareProvider $federatedShareProvider |
|
| 99 | + * @param AddressHandler $addressHandler |
|
| 100 | + * @param ILogger $logger |
|
| 101 | + * @param IUserManager $userManager |
|
| 102 | + * @param ICloudIdManager $cloudIdManager |
|
| 103 | + * @param IActivityManager $activityManager |
|
| 104 | + * @param INotificationManager $notificationManager |
|
| 105 | + * @param IURLGenerator $urlGenerator |
|
| 106 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
| 107 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 108 | + * @param IDBConnection $connection |
|
| 109 | + * @param IGroupManager $groupManager |
|
| 110 | + */ |
|
| 111 | + public function __construct(IAppManager $appManager, |
|
| 112 | + FederatedShareProvider $federatedShareProvider, |
|
| 113 | + AddressHandler $addressHandler, |
|
| 114 | + ILogger $logger, |
|
| 115 | + IUserManager $userManager, |
|
| 116 | + ICloudIdManager $cloudIdManager, |
|
| 117 | + IActivityManager $activityManager, |
|
| 118 | + INotificationManager $notificationManager, |
|
| 119 | + IURLGenerator $urlGenerator, |
|
| 120 | + ICloudFederationFactory $cloudFederationFactory, |
|
| 121 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 122 | + IDBConnection $connection, |
|
| 123 | + IGroupManager $groupManager |
|
| 124 | + ) { |
|
| 125 | + $this->appManager = $appManager; |
|
| 126 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 127 | + $this->addressHandler = $addressHandler; |
|
| 128 | + $this->logger = $logger; |
|
| 129 | + $this->userManager = $userManager; |
|
| 130 | + $this->cloudIdManager = $cloudIdManager; |
|
| 131 | + $this->activityManager = $activityManager; |
|
| 132 | + $this->notificationManager = $notificationManager; |
|
| 133 | + $this->urlGenerator = $urlGenerator; |
|
| 134 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 135 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 136 | + $this->connection = $connection; |
|
| 137 | + $this->groupManager = $groupManager; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function getShareType() { |
|
| 146 | + return 'file'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * share received from another server |
|
| 151 | + * |
|
| 152 | + * @param ICloudFederationShare $share |
|
| 153 | + * @return string provider specific unique ID of the share |
|
| 154 | + * |
|
| 155 | + * @throws ProviderCouldNotAddShareException |
|
| 156 | + * @throws \OCP\AppFramework\QueryException |
|
| 157 | + * @throws \OC\HintException |
|
| 158 | + * @since 14.0.0 |
|
| 159 | + */ |
|
| 160 | + public function shareReceived(ICloudFederationShare $share) { |
|
| 161 | + |
|
| 162 | + if (!$this->isS2SEnabled(true)) { |
|
| 163 | + throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $protocol = $share->getProtocol(); |
|
| 167 | + if ($protocol['name'] !== 'webdav') { |
|
| 168 | + throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 172 | + // for backward compatibility make sure that the remote url stored in the |
|
| 173 | + // database ends with a trailing slash |
|
| 174 | + if (substr($remote, -1) !== '/') { |
|
| 175 | + $remote = $remote . '/'; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $token = $share->getShareSecret(); |
|
| 179 | + $name = $share->getResourceName(); |
|
| 180 | + $owner = $share->getOwnerDisplayName(); |
|
| 181 | + $sharedBy = $share->getSharedByDisplayName(); |
|
| 182 | + $shareWith = $share->getShareWith(); |
|
| 183 | + $remoteId = $share->getProviderId(); |
|
| 184 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 185 | + $ownerFederatedId = $share->getOwner(); |
|
| 186 | + $shareType = $this->mapShareTypeToNextcloud($share->getShareType()); |
|
| 187 | + |
|
| 188 | + // if no explicit information about the person who created the share was send |
|
| 189 | + // we assume that the share comes from the owner |
|
| 190 | + if ($sharedByFederatedId === null) { |
|
| 191 | + $sharedBy = $owner; |
|
| 192 | + $sharedByFederatedId = $ownerFederatedId; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 196 | + |
|
| 197 | + if (!Util::isValidFileName($name)) { |
|
| 198 | + throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // FIXME this should be a method in the user management instead |
|
| 202 | + if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 203 | + $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 204 | + Util::emitHook( |
|
| 205 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 206 | + 'preLoginNameUsedAsUserName', |
|
| 207 | + array('uid' => &$shareWith) |
|
| 208 | + ); |
|
| 209 | + $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 210 | + |
|
| 211 | + if (!$this->userManager->userExists($shareWith)) { |
|
| 212 | + throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + \OC_Util::setupFS($shareWith); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($shareType === Share::SHARE_TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) { |
|
| 219 | + throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 223 | + \OC::$server->getDatabaseConnection(), |
|
| 224 | + Filesystem::getMountManager(), |
|
| 225 | + Filesystem::getLoader(), |
|
| 226 | + \OC::$server->getHTTPClientService(), |
|
| 227 | + \OC::$server->getNotificationManager(), |
|
| 228 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 229 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 230 | + \OC::$server->getCloudFederationFactory(), |
|
| 231 | + \OC::$server->getGroupManager(), |
|
| 232 | + \OC::$server->getUserManager(), |
|
| 233 | + $shareWith |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + try { |
|
| 237 | + $externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); |
|
| 238 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 239 | + |
|
| 240 | + if ($shareType === Share::SHARE_TYPE_USER) { |
|
| 241 | + $event = $this->activityManager->generateEvent(); |
|
| 242 | + $event->setApp('files_sharing') |
|
| 243 | + ->setType('remote_share') |
|
| 244 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 245 | + ->setAffectedUser($shareWith) |
|
| 246 | + ->setObject('remote_share', (int)$shareId, $name); |
|
| 247 | + \OC::$server->getActivityManager()->publish($event); |
|
| 248 | + $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 249 | + } else { |
|
| 250 | + $groupMembers = $this->groupManager->get($shareWith)->getUsers(); |
|
| 251 | + foreach ($groupMembers as $user) { |
|
| 252 | + $event = $this->activityManager->generateEvent(); |
|
| 253 | + $event->setApp('files_sharing') |
|
| 254 | + ->setType('remote_share') |
|
| 255 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 256 | + ->setAffectedUser($user->getUID()) |
|
| 257 | + ->setObject('remote_share', (int)$shareId, $name); |
|
| 258 | + \OC::$server->getActivityManager()->publish($event); |
|
| 259 | + $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + return $shareId; |
|
| 263 | + } catch (\Exception $e) { |
|
| 264 | + $this->logger->logException($e, [ |
|
| 265 | + 'message' => 'Server can not add remote share.', |
|
| 266 | + 'level' => ILogger::ERROR, |
|
| 267 | + 'app' => 'files_sharing' |
|
| 268 | + ]); |
|
| 269 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * notification received from another server |
|
| 279 | + * |
|
| 280 | + * @param string $notificationType (e.g. SHARE_ACCEPTED) |
|
| 281 | + * @param string $providerId id of the share |
|
| 282 | + * @param array $notification payload of the notification |
|
| 283 | + * @return array data send back to the sender |
|
| 284 | + * |
|
| 285 | + * @throws ActionNotSupportedException |
|
| 286 | + * @throws AuthenticationFailedException |
|
| 287 | + * @throws BadRequestException |
|
| 288 | + * @throws \OC\HintException |
|
| 289 | + * @since 14.0.0 |
|
| 290 | + */ |
|
| 291 | + public function notificationReceived($notificationType, $providerId, array $notification) { |
|
| 292 | + |
|
| 293 | + switch ($notificationType) { |
|
| 294 | + case 'SHARE_ACCEPTED': |
|
| 295 | + return $this->shareAccepted($providerId, $notification); |
|
| 296 | + case 'SHARE_DECLINED': |
|
| 297 | + return $this->shareDeclined($providerId, $notification); |
|
| 298 | + case 'SHARE_UNSHARED': |
|
| 299 | + return $this->unshare($providerId, $notification); |
|
| 300 | + case 'REQUEST_RESHARE': |
|
| 301 | + return $this->reshareRequested($providerId, $notification); |
|
| 302 | + case 'RESHARE_UNDO': |
|
| 303 | + return $this->undoReshare($providerId, $notification); |
|
| 304 | + case 'RESHARE_CHANGE_PERMISSION': |
|
| 305 | + return $this->updateResharePermissions($providerId, $notification); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + throw new BadRequestException([$notificationType]); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * map OCM share type (strings) to Nextcloud internal share types (integer) |
|
| 314 | + * |
|
| 315 | + * @param string $shareType |
|
| 316 | + * @return int |
|
| 317 | + */ |
|
| 318 | + private function mapShareTypeToNextcloud($shareType) { |
|
| 319 | + $result = Share::SHARE_TYPE_USER; |
|
| 320 | + if ($shareType === 'group') { |
|
| 321 | + $result = Share::SHARE_TYPE_GROUP; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $result; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * notify user about new federated share |
|
| 329 | + * |
|
| 330 | + * @param $shareWith |
|
| 331 | + * @param $shareId |
|
| 332 | + * @param $ownerFederatedId |
|
| 333 | + * @param $sharedByFederatedId |
|
| 334 | + * @param $name |
|
| 335 | + */ |
|
| 336 | + private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { |
|
| 337 | + $notification = $this->notificationManager->createNotification(); |
|
| 338 | + $notification->setApp('files_sharing') |
|
| 339 | + ->setUser($shareWith) |
|
| 340 | + ->setDateTime(new \DateTime()) |
|
| 341 | + ->setObject('remote_share', $shareId) |
|
| 342 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 343 | + |
|
| 344 | + $declineAction = $notification->createAction(); |
|
| 345 | + $declineAction->setLabel('decline') |
|
| 346 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 347 | + $notification->addAction($declineAction); |
|
| 348 | + |
|
| 349 | + $acceptAction = $notification->createAction(); |
|
| 350 | + $acceptAction->setLabel('accept') |
|
| 351 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 352 | + $notification->addAction($acceptAction); |
|
| 353 | + |
|
| 354 | + $this->notificationManager->notify($notification); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * process notification that the recipient accepted a share |
|
| 359 | + * |
|
| 360 | + * @param string $id |
|
| 361 | + * @param array $notification |
|
| 362 | + * @return array |
|
| 363 | + * @throws ActionNotSupportedException |
|
| 364 | + * @throws AuthenticationFailedException |
|
| 365 | + * @throws BadRequestException |
|
| 366 | + * @throws \OC\HintException |
|
| 367 | + */ |
|
| 368 | + private function shareAccepted($id, array $notification) { |
|
| 369 | + |
|
| 370 | + if (!$this->isS2SEnabled()) { |
|
| 371 | + throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if (!isset($notification['sharedSecret'])) { |
|
| 375 | + throw new BadRequestException(['sharedSecret']); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $token = $notification['sharedSecret']; |
|
| 379 | + |
|
| 380 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 381 | + |
|
| 382 | + $this->verifyShare($share, $token); |
|
| 383 | + $this->executeAcceptShare($share); |
|
| 384 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 385 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 386 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 387 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 388 | + $notification->setMessage( |
|
| 389 | + 'SHARE_ACCEPTED', |
|
| 390 | + 'file', |
|
| 391 | + $remoteId, |
|
| 392 | + [ |
|
| 393 | + 'sharedSecret' => $token, |
|
| 394 | + 'message' => 'Recipient accepted the re-share' |
|
| 395 | + ] |
|
| 396 | + |
|
| 397 | + ); |
|
| 398 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 399 | + |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + return []; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @param IShare $share |
|
| 407 | + * @throws ShareNotFound |
|
| 408 | + */ |
|
| 409 | + protected function executeAcceptShare(IShare $share) { |
|
| 410 | + try { |
|
| 411 | + $fileId = (int)$share->getNode()->getId(); |
|
| 412 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 413 | + } catch (\Exception $e) { |
|
| 414 | + throw new ShareNotFound(); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $event = $this->activityManager->generateEvent(); |
|
| 418 | + $event->setApp('files_sharing') |
|
| 419 | + ->setType('remote_share') |
|
| 420 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
| 421 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 422 | + ->setObject('files', $fileId, $file) |
|
| 423 | + ->setLink($link); |
|
| 424 | + $this->activityManager->publish($event); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * process notification that the recipient declined a share |
|
| 429 | + * |
|
| 430 | + * @param string $id |
|
| 431 | + * @param array $notification |
|
| 432 | + * @return array |
|
| 433 | + * @throws ActionNotSupportedException |
|
| 434 | + * @throws AuthenticationFailedException |
|
| 435 | + * @throws BadRequestException |
|
| 436 | + * @throws ShareNotFound |
|
| 437 | + * @throws \OC\HintException |
|
| 438 | + * |
|
| 439 | + */ |
|
| 440 | + protected function shareDeclined($id, array $notification) { |
|
| 441 | + |
|
| 442 | + if (!$this->isS2SEnabled()) { |
|
| 443 | + throw new ActionNotSupportedException('Server does not support federated cloud sharing'); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + if (!isset($notification['sharedSecret'])) { |
|
| 447 | + throw new BadRequestException(['sharedSecret']); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + $token = $notification['sharedSecret']; |
|
| 451 | + |
|
| 452 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 453 | + |
|
| 454 | + $this->verifyShare($share, $token); |
|
| 455 | + |
|
| 456 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
| 457 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
| 458 | + $remoteId = $this->federatedShareProvider->getRemoteId($share); |
|
| 459 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 460 | + $notification->setMessage( |
|
| 461 | + 'SHARE_DECLINED', |
|
| 462 | + 'file', |
|
| 463 | + $remoteId, |
|
| 464 | + [ |
|
| 465 | + 'sharedSecret' => $token, |
|
| 466 | + 'message' => 'Recipient declined the re-share' |
|
| 467 | + ] |
|
| 468 | + |
|
| 469 | + ); |
|
| 470 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + $this->executeDeclineShare($share); |
|
| 474 | + |
|
| 475 | + return []; |
|
| 476 | + |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * delete declined share and create a activity |
|
| 481 | + * |
|
| 482 | + * @param IShare $share |
|
| 483 | + * @throws ShareNotFound |
|
| 484 | + */ |
|
| 485 | + protected function executeDeclineShare(IShare $share) { |
|
| 486 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
| 487 | + |
|
| 488 | + try { |
|
| 489 | + $fileId = (int)$share->getNode()->getId(); |
|
| 490 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
|
| 491 | + } catch (\Exception $e) { |
|
| 492 | + throw new ShareNotFound(); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $event = $this->activityManager->generateEvent(); |
|
| 496 | + $event->setApp('files_sharing') |
|
| 497 | + ->setType('remote_share') |
|
| 498 | + ->setAffectedUser($this->getCorrectUid($share)) |
|
| 499 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]]) |
|
| 500 | + ->setObject('files', $fileId, $file) |
|
| 501 | + ->setLink($link); |
|
| 502 | + $this->activityManager->publish($event); |
|
| 503 | + |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * received the notification that the owner unshared a file from you |
|
| 508 | + * |
|
| 509 | + * @param string $id |
|
| 510 | + * @param array $notification |
|
| 511 | + * @return array |
|
| 512 | + * @throws AuthenticationFailedException |
|
| 513 | + * @throws BadRequestException |
|
| 514 | + */ |
|
| 515 | + private function undoReshare($id, array $notification) { |
|
| 516 | + if (!isset($notification['sharedSecret'])) { |
|
| 517 | + throw new BadRequestException(['sharedSecret']); |
|
| 518 | + } |
|
| 519 | + $token = $notification['sharedSecret']; |
|
| 520 | + |
|
| 521 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 522 | + |
|
| 523 | + $this->verifyShare($share, $token); |
|
| 524 | + $this->federatedShareProvider->removeShareFromTable($share); |
|
| 525 | + return []; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * unshare file from self |
|
| 530 | + * |
|
| 531 | + * @param string $id |
|
| 532 | + * @param array $notification |
|
| 533 | + * @return array |
|
| 534 | + * @throws ActionNotSupportedException |
|
| 535 | + * @throws BadRequestException |
|
| 536 | + */ |
|
| 537 | + private function unshare($id, array $notification) { |
|
| 538 | + |
|
| 539 | + if (!$this->isS2SEnabled(true)) { |
|
| 540 | + throw new ActionNotSupportedException("incoming shares disabled!"); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if (!isset($notification['sharedSecret'])) { |
|
| 544 | + throw new BadRequestException(['sharedSecret']); |
|
| 545 | + } |
|
| 546 | + $token = $notification['sharedSecret']; |
|
| 547 | + |
|
| 548 | + $qb = $this->connection->getQueryBuilder(); |
|
| 549 | + $qb->select('*') |
|
| 550 | + ->from('share_external') |
|
| 551 | + ->where( |
|
| 552 | + $qb->expr()->andX( |
|
| 553 | + $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 554 | + $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 555 | + ) |
|
| 556 | + ); |
|
| 557 | + |
|
| 558 | + $result = $qb->execute(); |
|
| 559 | + $share = $result->fetch(); |
|
| 560 | + $result->closeCursor(); |
|
| 561 | + |
|
| 562 | + if ($token && $id && !empty($share)) { |
|
| 563 | + |
|
| 564 | + $remote = $this->cleanupRemote($share['remote']); |
|
| 565 | + |
|
| 566 | + $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote); |
|
| 567 | + $mountpoint = $share['mountpoint']; |
|
| 568 | + $user = $share['user']; |
|
| 569 | + |
|
| 570 | + $qb = $this->connection->getQueryBuilder(); |
|
| 571 | + $qb->delete('share_external') |
|
| 572 | + ->where( |
|
| 573 | + $qb->expr()->andX( |
|
| 574 | + $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), |
|
| 575 | + $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) |
|
| 576 | + ) |
|
| 577 | + ); |
|
| 578 | + |
|
| 579 | + $qb->execute(); |
|
| 580 | + |
|
| 581 | + // delete all child in case of a group share |
|
| 582 | + $qb = $this->connection->getQueryBuilder(); |
|
| 583 | + $qb->delete('share_external') |
|
| 584 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id']))); |
|
| 585 | + $qb->execute(); |
|
| 586 | + |
|
| 587 | + if ((int)$share['share_type'] === Share::SHARE_TYPE_USER) { |
|
| 588 | + if ($share['accepted']) { |
|
| 589 | + $path = trim($mountpoint, '/'); |
|
| 590 | + } else { |
|
| 591 | + $path = trim($share['name'], '/'); |
|
| 592 | + } |
|
| 593 | + $notification = $this->notificationManager->createNotification(); |
|
| 594 | + $notification->setApp('files_sharing') |
|
| 595 | + ->setUser($share['user']) |
|
| 596 | + ->setObject('remote_share', (int)$share['id']); |
|
| 597 | + $this->notificationManager->markProcessed($notification); |
|
| 598 | + |
|
| 599 | + $event = $this->activityManager->generateEvent(); |
|
| 600 | + $event->setApp('files_sharing') |
|
| 601 | + ->setType('remote_share') |
|
| 602 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) |
|
| 603 | + ->setAffectedUser($user) |
|
| 604 | + ->setObject('remote_share', (int)$share['id'], $path); |
|
| 605 | + \OC::$server->getActivityManager()->publish($event); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + return []; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + private function cleanupRemote($remote) { |
|
| 613 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 614 | + |
|
| 615 | + return rtrim($remote, '/'); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * recipient of a share request to re-share the file with another user |
|
| 620 | + * |
|
| 621 | + * @param string $id |
|
| 622 | + * @param array $notification |
|
| 623 | + * @return array |
|
| 624 | + * @throws AuthenticationFailedException |
|
| 625 | + * @throws BadRequestException |
|
| 626 | + * @throws ProviderCouldNotAddShareException |
|
| 627 | + * @throws ShareNotFound |
|
| 628 | + */ |
|
| 629 | + protected function reshareRequested($id, array $notification) { |
|
| 630 | + |
|
| 631 | + if (!isset($notification['sharedSecret'])) { |
|
| 632 | + throw new BadRequestException(['sharedSecret']); |
|
| 633 | + } |
|
| 634 | + $token = $notification['sharedSecret']; |
|
| 635 | + |
|
| 636 | + if (!isset($notification['shareWith'])) { |
|
| 637 | + throw new BadRequestException(['shareWith']); |
|
| 638 | + } |
|
| 639 | + $shareWith = $notification['shareWith']; |
|
| 640 | + |
|
| 641 | + if (!isset($notification['senderId'])) { |
|
| 642 | + throw new BadRequestException(['senderId']); |
|
| 643 | + } |
|
| 644 | + $senderId = $notification['senderId']; |
|
| 645 | + |
|
| 646 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 647 | + // don't allow to share a file back to the owner |
|
| 648 | + try { |
|
| 649 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 650 | + $owner = $share->getShareOwner(); |
|
| 651 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
| 652 | + if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { |
|
| 653 | + throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); |
|
| 654 | + } |
|
| 655 | + } catch (\Exception $e) { |
|
| 656 | + throw new ProviderCouldNotAddShareException($e->getMessage()); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + $this->verifyShare($share, $token); |
|
| 660 | + |
|
| 661 | + // check if re-sharing is allowed |
|
| 662 | + if ($share->getPermissions() & Constants::PERMISSION_SHARE) { |
|
| 663 | + // the recipient of the initial share is now the initiator for the re-share |
|
| 664 | + $share->setSharedBy($share->getSharedWith()); |
|
| 665 | + $share->setSharedWith($shareWith); |
|
| 666 | + $result = $this->federatedShareProvider->create($share); |
|
| 667 | + $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId); |
|
| 668 | + return ['token' => $result->getToken(), 'providerId' => $result->getId()]; |
|
| 669 | + } else { |
|
| 670 | + throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * update permission of a re-share so that the share dialog shows the right |
|
| 677 | + * permission if the owner or the sender changes the permission |
|
| 678 | + * |
|
| 679 | + * @param string $id |
|
| 680 | + * @param array $notification |
|
| 681 | + * @return array |
|
| 682 | + * @throws AuthenticationFailedException |
|
| 683 | + * @throws BadRequestException |
|
| 684 | + */ |
|
| 685 | + protected function updateResharePermissions($id, array $notification) { |
|
| 686 | + |
|
| 687 | + if (!isset($notification['sharedSecret'])) { |
|
| 688 | + throw new BadRequestException(['sharedSecret']); |
|
| 689 | + } |
|
| 690 | + $token = $notification['sharedSecret']; |
|
| 691 | + |
|
| 692 | + if (!isset($notification['permission'])) { |
|
| 693 | + throw new BadRequestException(['permission']); |
|
| 694 | + } |
|
| 695 | + $ocmPermissions = $notification['permission']; |
|
| 696 | + |
|
| 697 | + $share = $this->federatedShareProvider->getShareById($id); |
|
| 698 | + |
|
| 699 | + $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions); |
|
| 700 | + |
|
| 701 | + $this->verifyShare($share, $token); |
|
| 702 | + $this->updatePermissionsInDatabase($share, $ncPermission); |
|
| 703 | + |
|
| 704 | + return []; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * translate OCM Permissions to Nextcloud permissions |
|
| 709 | + * |
|
| 710 | + * @param array $ocmPermissions |
|
| 711 | + * @return int |
|
| 712 | + * @throws BadRequestException |
|
| 713 | + */ |
|
| 714 | + protected function ocmPermissions2ncPermissions(array $ocmPermissions) { |
|
| 715 | + $ncPermissions = 0; |
|
| 716 | + foreach($ocmPermissions as $permission) { |
|
| 717 | + switch (strtolower($permission)) { |
|
| 718 | + case 'read': |
|
| 719 | + $ncPermissions += Constants::PERMISSION_READ; |
|
| 720 | + break; |
|
| 721 | + case 'write': |
|
| 722 | + $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE; |
|
| 723 | + break; |
|
| 724 | + case 'share': |
|
| 725 | + $ncPermissions += Constants::PERMISSION_SHARE; |
|
| 726 | + break; |
|
| 727 | + default: |
|
| 728 | + throw new BadRequestException(['permission']); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + return $ncPermissions; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * update permissions in database |
|
| 738 | + * |
|
| 739 | + * @param IShare $share |
|
| 740 | + * @param int $permissions |
|
| 741 | + */ |
|
| 742 | + protected function updatePermissionsInDatabase(IShare $share, $permissions) { |
|
| 743 | + $query = $this->connection->getQueryBuilder(); |
|
| 744 | + $query->update('share') |
|
| 745 | + ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) |
|
| 746 | + ->set('permissions', $query->createNamedParameter($permissions)) |
|
| 747 | + ->execute(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * get file |
|
| 753 | + * |
|
| 754 | + * @param string $user |
|
| 755 | + * @param int $fileSource |
|
| 756 | + * @return array with internal path of the file and a absolute link to it |
|
| 757 | + */ |
|
| 758 | + private function getFile($user, $fileSource) { |
|
| 759 | + \OC_Util::setupFS($user); |
|
| 760 | + |
|
| 761 | + try { |
|
| 762 | + $file = Filesystem::getPath($fileSource); |
|
| 763 | + } catch (NotFoundException $e) { |
|
| 764 | + $file = null; |
|
| 765 | + } |
|
| 766 | + $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); |
|
| 767 | + $link = Util::linkToAbsolute('files', 'index.php', $args); |
|
| 768 | + |
|
| 769 | + return [$file, $link]; |
|
| 770 | + |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * check if we are the initiator or the owner of a re-share and return the correct UID |
|
| 775 | + * |
|
| 776 | + * @param IShare $share |
|
| 777 | + * @return string |
|
| 778 | + */ |
|
| 779 | + protected function getCorrectUid(IShare $share) { |
|
| 780 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 781 | + return $share->getShareOwner(); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + return $share->getSharedBy(); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * check if we got the right share |
|
| 791 | + * |
|
| 792 | + * @param IShare $share |
|
| 793 | + * @param string $token |
|
| 794 | + * @return bool |
|
| 795 | + * @throws AuthenticationFailedException |
|
| 796 | + */ |
|
| 797 | + protected function verifyShare(IShare $share, $token) { |
|
| 798 | + if ( |
|
| 799 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && |
|
| 800 | + $share->getToken() === $token |
|
| 801 | + ) { |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + throw new AuthenticationFailedException(); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * check if server-to-server sharing is enabled |
|
| 812 | + * |
|
| 813 | + * @param bool $incoming |
|
| 814 | + * @return bool |
|
| 815 | + */ |
|
| 816 | + private function isS2SEnabled($incoming = false) { |
|
| 817 | + |
|
| 818 | + $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 819 | + |
|
| 820 | + if ($incoming) { |
|
| 821 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 822 | + } else { |
|
| 823 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + return $result; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * get the supported share types, e.g. "user", "group", etc. |
|
| 832 | + * |
|
| 833 | + * @return array |
|
| 834 | + * |
|
| 835 | + * @since 14.0.0 |
|
| 836 | + */ |
|
| 837 | + public function getSupportedShareTypes() { |
|
| 838 | + return ['user', 'group']; |
|
| 839 | + } |
|
| 840 | 840 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | // for backward compatibility make sure that the remote url stored in the |
| 173 | 173 | // database ends with a trailing slash |
| 174 | 174 | if (substr($remote, -1) !== '/') { |
| 175 | - $remote = $remote . '/'; |
|
| 175 | + $remote = $remote.'/'; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $token = $share->getShareSecret(); |
@@ -200,23 +200,23 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | // FIXME this should be a method in the user management instead |
| 202 | 202 | if ($shareType === Share::SHARE_TYPE_USER) { |
| 203 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 203 | + $this->logger->debug('shareWith before, '.$shareWith, ['app' => 'files_sharing']); |
|
| 204 | 204 | Util::emitHook( |
| 205 | 205 | '\OCA\Files_Sharing\API\Server2Server', |
| 206 | 206 | 'preLoginNameUsedAsUserName', |
| 207 | 207 | array('uid' => &$shareWith) |
| 208 | 208 | ); |
| 209 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 209 | + $this->logger->debug('shareWith after, '.$shareWith, ['app' => 'files_sharing']); |
|
| 210 | 210 | |
| 211 | 211 | if (!$this->userManager->userExists($shareWith)) { |
| 212 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 212 | + throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | \OC_Util::setupFS($shareWith); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | if ($shareType === Share::SHARE_TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) { |
| 219 | - throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 219 | + throw new ProviderCouldNotAddShareException('Group does not exists', '', Http::STATUS_BAD_REQUEST); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | $externalManager = new \OCA\Files_Sharing\External\Manager( |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | 236 | try { |
| 237 | - $externalManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); |
|
| 237 | + $externalManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId); |
|
| 238 | 238 | $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
| 239 | 239 | |
| 240 | 240 | if ($shareType === Share::SHARE_TYPE_USER) { |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | ->setType('remote_share') |
| 244 | 244 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
| 245 | 245 | ->setAffectedUser($shareWith) |
| 246 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 246 | + ->setObject('remote_share', (int) $shareId, $name); |
|
| 247 | 247 | \OC::$server->getActivityManager()->publish($event); |
| 248 | 248 | $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
| 249 | 249 | } else { |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ->setType('remote_share') |
| 255 | 255 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
| 256 | 256 | ->setAffectedUser($user->getUID()) |
| 257 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 257 | + ->setObject('remote_share', (int) $shareId, $name); |
|
| 258 | 258 | \OC::$server->getActivityManager()->publish($event); |
| 259 | 259 | $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); |
| 260 | 260 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | 'level' => ILogger::ERROR, |
| 267 | 267 | 'app' => 'files_sharing' |
| 268 | 268 | ]); |
| 269 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 269 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from '.$remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
@@ -343,12 +343,12 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | $declineAction = $notification->createAction(); |
| 345 | 345 | $declineAction->setLabel('decline') |
| 346 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 346 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'DELETE'); |
|
| 347 | 347 | $notification->addAction($declineAction); |
| 348 | 348 | |
| 349 | 349 | $acceptAction = $notification->createAction(); |
| 350 | 350 | $acceptAction->setLabel('accept') |
| 351 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 351 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'POST'); |
|
| 352 | 352 | $notification->addAction($acceptAction); |
| 353 | 353 | |
| 354 | 354 | $this->notificationManager->notify($notification); |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | protected function executeAcceptShare(IShare $share) { |
| 410 | 410 | try { |
| 411 | - $fileId = (int)$share->getNode()->getId(); |
|
| 411 | + $fileId = (int) $share->getNode()->getId(); |
|
| 412 | 412 | list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
| 413 | 413 | } catch (\Exception $e) { |
| 414 | 414 | throw new ShareNotFound(); |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | $this->federatedShareProvider->removeShareFromTable($share); |
| 487 | 487 | |
| 488 | 488 | try { |
| 489 | - $fileId = (int)$share->getNode()->getId(); |
|
| 489 | + $fileId = (int) $share->getNode()->getId(); |
|
| 490 | 490 | list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); |
| 491 | 491 | } catch (\Exception $e) { |
| 492 | 492 | throw new ShareNotFound(); |
@@ -581,10 +581,10 @@ discard block |
||
| 581 | 581 | // delete all child in case of a group share |
| 582 | 582 | $qb = $this->connection->getQueryBuilder(); |
| 583 | 583 | $qb->delete('share_external') |
| 584 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id']))); |
|
| 584 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int) $share['id']))); |
|
| 585 | 585 | $qb->execute(); |
| 586 | 586 | |
| 587 | - if ((int)$share['share_type'] === Share::SHARE_TYPE_USER) { |
|
| 587 | + if ((int) $share['share_type'] === Share::SHARE_TYPE_USER) { |
|
| 588 | 588 | if ($share['accepted']) { |
| 589 | 589 | $path = trim($mountpoint, '/'); |
| 590 | 590 | } else { |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | $notification = $this->notificationManager->createNotification(); |
| 594 | 594 | $notification->setApp('files_sharing') |
| 595 | 595 | ->setUser($share['user']) |
| 596 | - ->setObject('remote_share', (int)$share['id']); |
|
| 596 | + ->setObject('remote_share', (int) $share['id']); |
|
| 597 | 597 | $this->notificationManager->markProcessed($notification); |
| 598 | 598 | |
| 599 | 599 | $event = $this->activityManager->generateEvent(); |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | ->setType('remote_share') |
| 602 | 602 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) |
| 603 | 603 | ->setAffectedUser($user) |
| 604 | - ->setObject('remote_share', (int)$share['id'], $path); |
|
| 604 | + ->setObject('remote_share', (int) $share['id'], $path); |
|
| 605 | 605 | \OC::$server->getActivityManager()->publish($event); |
| 606 | 606 | } |
| 607 | 607 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | $owner = $share->getShareOwner(); |
| 651 | 651 | $currentServer = $this->addressHandler->generateRemoteURL(); |
| 652 | 652 | if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { |
| 653 | - throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); |
|
| 653 | + throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: '.$id); |
|
| 654 | 654 | } |
| 655 | 655 | } catch (\Exception $e) { |
| 656 | 656 | throw new ProviderCouldNotAddShareException($e->getMessage()); |
@@ -664,10 +664,10 @@ discard block |
||
| 664 | 664 | $share->setSharedBy($share->getSharedWith()); |
| 665 | 665 | $share->setSharedWith($shareWith); |
| 666 | 666 | $result = $this->federatedShareProvider->create($share); |
| 667 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId); |
|
| 667 | + $this->federatedShareProvider->storeRemoteId((int) $result->getId(), $senderId); |
|
| 668 | 668 | return ['token' => $result->getToken(), 'providerId' => $result->getId()]; |
| 669 | 669 | } else { |
| 670 | - throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); |
|
| 670 | + throw new ProviderCouldNotAddShareException('resharing not allowed for share: '.$id); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | } |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | */ |
| 714 | 714 | protected function ocmPermissions2ncPermissions(array $ocmPermissions) { |
| 715 | 715 | $ncPermissions = 0; |
| 716 | - foreach($ocmPermissions as $permission) { |
|
| 716 | + foreach ($ocmPermissions as $permission) { |
|
| 717 | 717 | switch (strtolower($permission)) { |
| 718 | 718 | case 'read': |
| 719 | 719 | $ncPermissions += Constants::PERMISSION_READ; |
@@ -25,332 +25,332 @@ |
||
| 25 | 25 | |
| 26 | 26 | class CloudFederationShare implements ICloudFederationShare { |
| 27 | 27 | |
| 28 | - private $share = [ |
|
| 29 | - 'shareWith' => '', |
|
| 30 | - 'shareType' => '', |
|
| 31 | - 'name' => '', |
|
| 32 | - 'resourceType' => '', |
|
| 33 | - 'description' => '', |
|
| 34 | - 'providerId' => '', |
|
| 35 | - 'owner' => '', |
|
| 36 | - 'ownerDisplayName' => '', |
|
| 37 | - 'sharedBy' => '', |
|
| 38 | - 'sharedByDisplayName' => '', |
|
| 39 | - 'protocol' => [] |
|
| 40 | - ]; |
|
| 28 | + private $share = [ |
|
| 29 | + 'shareWith' => '', |
|
| 30 | + 'shareType' => '', |
|
| 31 | + 'name' => '', |
|
| 32 | + 'resourceType' => '', |
|
| 33 | + 'description' => '', |
|
| 34 | + 'providerId' => '', |
|
| 35 | + 'owner' => '', |
|
| 36 | + 'ownerDisplayName' => '', |
|
| 37 | + 'sharedBy' => '', |
|
| 38 | + 'sharedByDisplayName' => '', |
|
| 39 | + 'protocol' => [] |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | - * |
|
| 45 | - * @param string $shareWith |
|
| 46 | - * @param string $name resource name (e.g. document.odt) |
|
| 47 | - * @param string $description share description (optional) |
|
| 48 | - * @param string $providerId resource UID on the provider side |
|
| 49 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | - * @param string $shareType ('group' or 'user' share) |
|
| 54 | - * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | - * @param string $sharedSecret |
|
| 56 | - */ |
|
| 57 | - public function __construct($shareWith = '', |
|
| 58 | - $name = '', |
|
| 59 | - $description = '', |
|
| 60 | - $providerId = '', |
|
| 61 | - $owner = '', |
|
| 62 | - $ownerDisplayName = '', |
|
| 63 | - $sharedBy = '', |
|
| 64 | - $sharedByDisplayName = '', |
|
| 65 | - $shareType = '', |
|
| 66 | - $resourceType = '', |
|
| 67 | - $sharedSecret = '' |
|
| 68 | - ) { |
|
| 69 | - $this->setShareWith($shareWith); |
|
| 70 | - $this->setResourceName($name); |
|
| 71 | - $this->setDescription($description); |
|
| 72 | - $this->setProviderId($providerId); |
|
| 73 | - $this->setOwner($owner); |
|
| 74 | - $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | - $this->setSharedBy($sharedBy); |
|
| 76 | - $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | - $this->setProtocol([ |
|
| 78 | - 'name' => 'webdav', |
|
| 79 | - 'options' => [ |
|
| 80 | - 'sharedSecret' => $sharedSecret, |
|
| 81 | - 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions' |
|
| 82 | - ] |
|
| 83 | - ]); |
|
| 84 | - $this->setShareType($shareType); |
|
| 85 | - $this->setResourceType($resourceType); |
|
| 42 | + /** |
|
| 43 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | + * |
|
| 45 | + * @param string $shareWith |
|
| 46 | + * @param string $name resource name (e.g. document.odt) |
|
| 47 | + * @param string $description share description (optional) |
|
| 48 | + * @param string $providerId resource UID on the provider side |
|
| 49 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | + * @param string $shareType ('group' or 'user' share) |
|
| 54 | + * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | + * @param string $sharedSecret |
|
| 56 | + */ |
|
| 57 | + public function __construct($shareWith = '', |
|
| 58 | + $name = '', |
|
| 59 | + $description = '', |
|
| 60 | + $providerId = '', |
|
| 61 | + $owner = '', |
|
| 62 | + $ownerDisplayName = '', |
|
| 63 | + $sharedBy = '', |
|
| 64 | + $sharedByDisplayName = '', |
|
| 65 | + $shareType = '', |
|
| 66 | + $resourceType = '', |
|
| 67 | + $sharedSecret = '' |
|
| 68 | + ) { |
|
| 69 | + $this->setShareWith($shareWith); |
|
| 70 | + $this->setResourceName($name); |
|
| 71 | + $this->setDescription($description); |
|
| 72 | + $this->setProviderId($providerId); |
|
| 73 | + $this->setOwner($owner); |
|
| 74 | + $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | + $this->setSharedBy($sharedBy); |
|
| 76 | + $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | + $this->setProtocol([ |
|
| 78 | + 'name' => 'webdav', |
|
| 79 | + 'options' => [ |
|
| 80 | + 'sharedSecret' => $sharedSecret, |
|
| 81 | + 'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions' |
|
| 82 | + ] |
|
| 83 | + ]); |
|
| 84 | + $this->setShareType($shareType); |
|
| 85 | + $this->setResourceType($resourceType); |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * set uid of the recipient |
|
| 91 | - * |
|
| 92 | - * @param string $user |
|
| 93 | - * |
|
| 94 | - * @since 14.0.0 |
|
| 95 | - */ |
|
| 96 | - public function setShareWith($user) { |
|
| 97 | - $this->share['shareWith'] = $user; |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * set uid of the recipient |
|
| 91 | + * |
|
| 92 | + * @param string $user |
|
| 93 | + * |
|
| 94 | + * @since 14.0.0 |
|
| 95 | + */ |
|
| 96 | + public function setShareWith($user) { |
|
| 97 | + $this->share['shareWith'] = $user; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * set resource name (e.g. document.odt) |
|
| 102 | - * |
|
| 103 | - * @param string $name |
|
| 104 | - * |
|
| 105 | - * @since 14.0.0 |
|
| 106 | - */ |
|
| 107 | - public function setResourceName($name) { |
|
| 108 | - $this->share['name'] = $name; |
|
| 109 | - } |
|
| 100 | + /** |
|
| 101 | + * set resource name (e.g. document.odt) |
|
| 102 | + * |
|
| 103 | + * @param string $name |
|
| 104 | + * |
|
| 105 | + * @since 14.0.0 |
|
| 106 | + */ |
|
| 107 | + public function setResourceName($name) { |
|
| 108 | + $this->share['name'] = $name; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | - * |
|
| 114 | - * @param string $resourceType |
|
| 115 | - * |
|
| 116 | - * @since 14.0.0 |
|
| 117 | - */ |
|
| 118 | - public function setResourceType($resourceType) { |
|
| 119 | - $this->share['resourceType'] = $resourceType; |
|
| 120 | - } |
|
| 111 | + /** |
|
| 112 | + * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | + * |
|
| 114 | + * @param string $resourceType |
|
| 115 | + * |
|
| 116 | + * @since 14.0.0 |
|
| 117 | + */ |
|
| 118 | + public function setResourceType($resourceType) { |
|
| 119 | + $this->share['resourceType'] = $resourceType; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * set resource description (optional) |
|
| 124 | - * |
|
| 125 | - * @param string $description |
|
| 126 | - * |
|
| 127 | - * @since 14.0.0 |
|
| 128 | - */ |
|
| 129 | - public function setDescription($description) { |
|
| 130 | - $this->share['description'] = $description; |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * set resource description (optional) |
|
| 124 | + * |
|
| 125 | + * @param string $description |
|
| 126 | + * |
|
| 127 | + * @since 14.0.0 |
|
| 128 | + */ |
|
| 129 | + public function setDescription($description) { |
|
| 130 | + $this->share['description'] = $description; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * set provider ID (e.g. file ID) |
|
| 135 | - * |
|
| 136 | - * @param string $providerId |
|
| 137 | - * |
|
| 138 | - * @since 14.0.0 |
|
| 139 | - */ |
|
| 140 | - public function setProviderId($providerId) { |
|
| 141 | - $this->share['providerId'] = $providerId; |
|
| 142 | - } |
|
| 133 | + /** |
|
| 134 | + * set provider ID (e.g. file ID) |
|
| 135 | + * |
|
| 136 | + * @param string $providerId |
|
| 137 | + * |
|
| 138 | + * @since 14.0.0 |
|
| 139 | + */ |
|
| 140 | + public function setProviderId($providerId) { |
|
| 141 | + $this->share['providerId'] = $providerId; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * set owner UID |
|
| 146 | - * |
|
| 147 | - * @param string $owner |
|
| 148 | - * |
|
| 149 | - * @since 14.0.0 |
|
| 150 | - */ |
|
| 151 | - public function setOwner($owner) { |
|
| 152 | - $this->share['owner'] = $owner; |
|
| 153 | - } |
|
| 144 | + /** |
|
| 145 | + * set owner UID |
|
| 146 | + * |
|
| 147 | + * @param string $owner |
|
| 148 | + * |
|
| 149 | + * @since 14.0.0 |
|
| 150 | + */ |
|
| 151 | + public function setOwner($owner) { |
|
| 152 | + $this->share['owner'] = $owner; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * set owner display name |
|
| 157 | - * |
|
| 158 | - * @param string $ownerDisplayName |
|
| 159 | - * |
|
| 160 | - * @since 14.0.0 |
|
| 161 | - */ |
|
| 162 | - public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | - $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | - } |
|
| 155 | + /** |
|
| 156 | + * set owner display name |
|
| 157 | + * |
|
| 158 | + * @param string $ownerDisplayName |
|
| 159 | + * |
|
| 160 | + * @since 14.0.0 |
|
| 161 | + */ |
|
| 162 | + public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | + $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * set UID of the user who sends the share |
|
| 168 | - * |
|
| 169 | - * @param string $sharedBy |
|
| 170 | - * |
|
| 171 | - * @since 14.0.0 |
|
| 172 | - */ |
|
| 173 | - public function setSharedBy($sharedBy) { |
|
| 174 | - $this->share['sharedBy'] = $sharedBy; |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * set UID of the user who sends the share |
|
| 168 | + * |
|
| 169 | + * @param string $sharedBy |
|
| 170 | + * |
|
| 171 | + * @since 14.0.0 |
|
| 172 | + */ |
|
| 173 | + public function setSharedBy($sharedBy) { |
|
| 174 | + $this->share['sharedBy'] = $sharedBy; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * set display name of the user who sends the share |
|
| 179 | - * |
|
| 180 | - * @param $sharedByDisplayName |
|
| 181 | - * |
|
| 182 | - * @since 14.0.0 |
|
| 183 | - */ |
|
| 184 | - public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | - $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * set display name of the user who sends the share |
|
| 179 | + * |
|
| 180 | + * @param $sharedByDisplayName |
|
| 181 | + * |
|
| 182 | + * @since 14.0.0 |
|
| 183 | + */ |
|
| 184 | + public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | + $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * set protocol specification |
|
| 190 | - * |
|
| 191 | - * @param array $protocol |
|
| 192 | - * |
|
| 193 | - * @since 14.0.0 |
|
| 194 | - */ |
|
| 195 | - public function setProtocol(array $protocol) { |
|
| 196 | - $this->share['protocol'] = $protocol; |
|
| 197 | - } |
|
| 188 | + /** |
|
| 189 | + * set protocol specification |
|
| 190 | + * |
|
| 191 | + * @param array $protocol |
|
| 192 | + * |
|
| 193 | + * @since 14.0.0 |
|
| 194 | + */ |
|
| 195 | + public function setProtocol(array $protocol) { |
|
| 196 | + $this->share['protocol'] = $protocol; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * share type (group or user) |
|
| 201 | - * |
|
| 202 | - * @param string $shareType |
|
| 203 | - * |
|
| 204 | - * @since 14.0.0 |
|
| 205 | - */ |
|
| 206 | - public function setShareType($shareType) { |
|
| 207 | - if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 208 | - $this->share['shareType'] = 'group'; |
|
| 209 | - } else { |
|
| 210 | - $this->share['shareType'] = 'user'; |
|
| 211 | - } |
|
| 212 | - } |
|
| 199 | + /** |
|
| 200 | + * share type (group or user) |
|
| 201 | + * |
|
| 202 | + * @param string $shareType |
|
| 203 | + * |
|
| 204 | + * @since 14.0.0 |
|
| 205 | + */ |
|
| 206 | + public function setShareType($shareType) { |
|
| 207 | + if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 208 | + $this->share['shareType'] = 'group'; |
|
| 209 | + } else { |
|
| 210 | + $this->share['shareType'] = 'user'; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * get the whole share, ready to send out |
|
| 216 | - * |
|
| 217 | - * @return array |
|
| 218 | - * |
|
| 219 | - * @since 14.0.0 |
|
| 220 | - */ |
|
| 221 | - public function getShare() { |
|
| 222 | - return $this->share; |
|
| 223 | - } |
|
| 214 | + /** |
|
| 215 | + * get the whole share, ready to send out |
|
| 216 | + * |
|
| 217 | + * @return array |
|
| 218 | + * |
|
| 219 | + * @since 14.0.0 |
|
| 220 | + */ |
|
| 221 | + public function getShare() { |
|
| 222 | + return $this->share; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * get uid of the recipient |
|
| 227 | - * |
|
| 228 | - * @return string |
|
| 229 | - * |
|
| 230 | - * @since 14.0.0 |
|
| 231 | - */ |
|
| 232 | - public function getShareWith() { |
|
| 233 | - return $this->share['shareWith']; |
|
| 234 | - } |
|
| 225 | + /** |
|
| 226 | + * get uid of the recipient |
|
| 227 | + * |
|
| 228 | + * @return string |
|
| 229 | + * |
|
| 230 | + * @since 14.0.0 |
|
| 231 | + */ |
|
| 232 | + public function getShareWith() { |
|
| 233 | + return $this->share['shareWith']; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * get resource name (e.g. file, calendar, contact,...) |
|
| 238 | - * |
|
| 239 | - * @return string |
|
| 240 | - * |
|
| 241 | - * @since 14.0.0 |
|
| 242 | - */ |
|
| 243 | - public function getResourceName() { |
|
| 244 | - return $this->share['name']; |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * get resource name (e.g. file, calendar, contact,...) |
|
| 238 | + * |
|
| 239 | + * @return string |
|
| 240 | + * |
|
| 241 | + * @since 14.0.0 |
|
| 242 | + */ |
|
| 243 | + public function getResourceName() { |
|
| 244 | + return $this->share['name']; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * get resource type (e.g. file, calendar, contact,...) |
|
| 249 | - * |
|
| 250 | - * @return string |
|
| 251 | - * |
|
| 252 | - * @since 14.0.0 |
|
| 253 | - */ |
|
| 254 | - public function getResourceType() { |
|
| 255 | - return $this->share['resourceType']; |
|
| 256 | - } |
|
| 247 | + /** |
|
| 248 | + * get resource type (e.g. file, calendar, contact,...) |
|
| 249 | + * |
|
| 250 | + * @return string |
|
| 251 | + * |
|
| 252 | + * @since 14.0.0 |
|
| 253 | + */ |
|
| 254 | + public function getResourceType() { |
|
| 255 | + return $this->share['resourceType']; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * get resource description (optional) |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - * |
|
| 263 | - * @since 14.0.0 |
|
| 264 | - */ |
|
| 265 | - public function getDescription() { |
|
| 266 | - return $this->share['description']; |
|
| 267 | - } |
|
| 258 | + /** |
|
| 259 | + * get resource description (optional) |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + * |
|
| 263 | + * @since 14.0.0 |
|
| 264 | + */ |
|
| 265 | + public function getDescription() { |
|
| 266 | + return $this->share['description']; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * get provider ID (e.g. file ID) |
|
| 271 | - * |
|
| 272 | - * @return string |
|
| 273 | - * |
|
| 274 | - * @since 14.0.0 |
|
| 275 | - */ |
|
| 276 | - public function getProviderId() { |
|
| 277 | - return $this->share['providerId']; |
|
| 278 | - } |
|
| 269 | + /** |
|
| 270 | + * get provider ID (e.g. file ID) |
|
| 271 | + * |
|
| 272 | + * @return string |
|
| 273 | + * |
|
| 274 | + * @since 14.0.0 |
|
| 275 | + */ |
|
| 276 | + public function getProviderId() { |
|
| 277 | + return $this->share['providerId']; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * get owner UID |
|
| 282 | - * |
|
| 283 | - * @return string |
|
| 284 | - * |
|
| 285 | - * @since 14.0.0 |
|
| 286 | - */ |
|
| 287 | - public function getOwner() { |
|
| 288 | - return $this->share['owner']; |
|
| 289 | - } |
|
| 280 | + /** |
|
| 281 | + * get owner UID |
|
| 282 | + * |
|
| 283 | + * @return string |
|
| 284 | + * |
|
| 285 | + * @since 14.0.0 |
|
| 286 | + */ |
|
| 287 | + public function getOwner() { |
|
| 288 | + return $this->share['owner']; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * get owner display name |
|
| 293 | - * |
|
| 294 | - * @return string |
|
| 295 | - * |
|
| 296 | - * @since 14.0.0 |
|
| 297 | - */ |
|
| 298 | - public function getOwnerDisplayName() { |
|
| 299 | - return $this->share['ownerDisplayName']; |
|
| 300 | - } |
|
| 291 | + /** |
|
| 292 | + * get owner display name |
|
| 293 | + * |
|
| 294 | + * @return string |
|
| 295 | + * |
|
| 296 | + * @since 14.0.0 |
|
| 297 | + */ |
|
| 298 | + public function getOwnerDisplayName() { |
|
| 299 | + return $this->share['ownerDisplayName']; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * get UID of the user who sends the share |
|
| 304 | - * |
|
| 305 | - * @return string |
|
| 306 | - * |
|
| 307 | - * @since 14.0.0 |
|
| 308 | - */ |
|
| 309 | - public function getSharedBy() { |
|
| 310 | - return $this->share['sharedBy']; |
|
| 311 | - } |
|
| 302 | + /** |
|
| 303 | + * get UID of the user who sends the share |
|
| 304 | + * |
|
| 305 | + * @return string |
|
| 306 | + * |
|
| 307 | + * @since 14.0.0 |
|
| 308 | + */ |
|
| 309 | + public function getSharedBy() { |
|
| 310 | + return $this->share['sharedBy']; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * get display name of the user who sends the share |
|
| 315 | - * |
|
| 316 | - * @return string |
|
| 317 | - * |
|
| 318 | - * @since 14.0.0 |
|
| 319 | - */ |
|
| 320 | - public function getSharedByDisplayName() { |
|
| 321 | - return $this->share['sharedByDisplayName']; |
|
| 322 | - } |
|
| 313 | + /** |
|
| 314 | + * get display name of the user who sends the share |
|
| 315 | + * |
|
| 316 | + * @return string |
|
| 317 | + * |
|
| 318 | + * @since 14.0.0 |
|
| 319 | + */ |
|
| 320 | + public function getSharedByDisplayName() { |
|
| 321 | + return $this->share['sharedByDisplayName']; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * get share type (group or user) |
|
| 326 | - * |
|
| 327 | - * @return string |
|
| 328 | - * |
|
| 329 | - * @since 14.0.0 |
|
| 330 | - */ |
|
| 331 | - public function getShareType() { |
|
| 332 | - return $this->share['shareType']; |
|
| 333 | - } |
|
| 324 | + /** |
|
| 325 | + * get share type (group or user) |
|
| 326 | + * |
|
| 327 | + * @return string |
|
| 328 | + * |
|
| 329 | + * @since 14.0.0 |
|
| 330 | + */ |
|
| 331 | + public function getShareType() { |
|
| 332 | + return $this->share['shareType']; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * get share Secret |
|
| 337 | - * |
|
| 338 | - * @return string |
|
| 339 | - * |
|
| 340 | - * @since 14.0.0 |
|
| 341 | - */ |
|
| 342 | - public function getShareSecret() { |
|
| 343 | - return $this->share['protocol']['options']['sharedSecret']; |
|
| 344 | - } |
|
| 335 | + /** |
|
| 336 | + * get share Secret |
|
| 337 | + * |
|
| 338 | + * @return string |
|
| 339 | + * |
|
| 340 | + * @since 14.0.0 |
|
| 341 | + */ |
|
| 342 | + public function getShareSecret() { |
|
| 343 | + return $this->share['protocol']['options']['sharedSecret']; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * get protocol specification |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - * |
|
| 351 | - * @since 14.0.0 |
|
| 352 | - */ |
|
| 353 | - public function getProtocol() { |
|
| 354 | - return $this->share['protocol']; |
|
| 355 | - } |
|
| 346 | + /** |
|
| 347 | + * get protocol specification |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + * |
|
| 351 | + * @since 14.0.0 |
|
| 352 | + */ |
|
| 353 | + public function getProtocol() { |
|
| 354 | + return $this->share['protocol']; |
|
| 355 | + } |
|
| 356 | 356 | } |
@@ -52,249 +52,249 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | class RequestHandlerController extends Controller { |
| 54 | 54 | |
| 55 | - /** @var ILogger */ |
|
| 56 | - private $logger; |
|
| 57 | - |
|
| 58 | - /** @var IUserManager */ |
|
| 59 | - private $userManager; |
|
| 60 | - |
|
| 61 | - /** @var IGroupManager */ |
|
| 62 | - private $groupManager; |
|
| 63 | - |
|
| 64 | - /** @var IURLGenerator */ |
|
| 65 | - private $urlGenerator; |
|
| 66 | - |
|
| 67 | - /** @var ICloudFederationProviderManager */ |
|
| 68 | - private $cloudFederationProviderManager; |
|
| 69 | - |
|
| 70 | - /** @var Config */ |
|
| 71 | - private $config; |
|
| 72 | - |
|
| 73 | - /** @var ICloudFederationFactory */ |
|
| 74 | - private $factory; |
|
| 75 | - |
|
| 76 | - /** @var ICloudIdManager */ |
|
| 77 | - private $cloudIdManager; |
|
| 78 | - |
|
| 79 | - public function __construct($appName, |
|
| 80 | - IRequest $request, |
|
| 81 | - ILogger $logger, |
|
| 82 | - IUserManager $userManager, |
|
| 83 | - IGroupManager $groupManager, |
|
| 84 | - IURLGenerator $urlGenerator, |
|
| 85 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 86 | - Config $config, |
|
| 87 | - ICloudFederationFactory $factory, |
|
| 88 | - ICloudIdManager $cloudIdManager |
|
| 89 | - ) { |
|
| 90 | - parent::__construct($appName, $request); |
|
| 91 | - |
|
| 92 | - $this->logger = $logger; |
|
| 93 | - $this->userManager = $userManager; |
|
| 94 | - $this->groupManager = $groupManager; |
|
| 95 | - $this->urlGenerator = $urlGenerator; |
|
| 96 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 97 | - $this->config = $config; |
|
| 98 | - $this->factory = $factory; |
|
| 99 | - $this->cloudIdManager = $cloudIdManager; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * add share |
|
| 104 | - * |
|
| 105 | - * @NoCSRFRequired |
|
| 106 | - * @PublicPage |
|
| 107 | - * @BruteForceProtection(action=receiveFederatedShare) |
|
| 108 | - * |
|
| 109 | - * @param string $shareWith |
|
| 110 | - * @param string $name resource name (e.g. document.odt) |
|
| 111 | - * @param string $description share description (optional) |
|
| 112 | - * @param string $providerId resource UID on the provider side |
|
| 113 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 114 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 115 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 116 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 117 | - * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
| 118 | - * @param string $shareType ('group' or 'user' share) |
|
| 119 | - * @param $resourceType ('file', 'calendar',...) |
|
| 120 | - * @return Http\DataResponse|JSONResponse |
|
| 121 | - * |
|
| 122 | - * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
| 123 | - */ |
|
| 124 | - public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
| 125 | - |
|
| 126 | - // check if all required parameters are set |
|
| 127 | - if ($shareWith === null || |
|
| 128 | - $name === null || |
|
| 129 | - $providerId === null || |
|
| 130 | - $owner === null || |
|
| 131 | - $resourceType === null || |
|
| 132 | - $shareType === null || |
|
| 133 | - !is_array($protocol) || |
|
| 134 | - !isset($protocol['name']) || |
|
| 135 | - !isset ($protocol['options']) || |
|
| 136 | - !is_array($protocol['options']) || |
|
| 137 | - !isset($protocol['options']['sharedSecret']) |
|
| 138 | - ) { |
|
| 139 | - return new JSONResponse( |
|
| 140 | - ['message' => 'Missing arguments'], |
|
| 141 | - Http::STATUS_BAD_REQUEST |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
| 146 | - if (!in_array($shareType, $supportedShareTypes)) { |
|
| 147 | - return new JSONResponse( |
|
| 148 | - ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
| 149 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 154 | - $shareWith = $cloudId->getUser(); |
|
| 155 | - |
|
| 156 | - if ($shareType === 'user') { |
|
| 157 | - $shareWith = $this->mapUid($shareWith); |
|
| 158 | - |
|
| 159 | - if (!$this->userManager->userExists($shareWith)) { |
|
| 160 | - return new JSONResponse( |
|
| 161 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 162 | - Http::STATUS_BAD_REQUEST |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ($shareType === 'group') { |
|
| 168 | - if(!$this->groupManager->groupExists($shareWith)) { |
|
| 169 | - return new JSONResponse( |
|
| 170 | - ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 171 | - Http::STATUS_BAD_REQUEST |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // if no explicit display name is given, we use the uid as display name |
|
| 177 | - $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
| 178 | - $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
| 179 | - |
|
| 180 | - // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
| 181 | - if ($sharedBy === null) { |
|
| 182 | - $sharedBy = $owner; |
|
| 183 | - $sharedByDisplayName = $ownerDisplayName; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - try { |
|
| 187 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 188 | - $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
| 189 | - $share->setProtocol($protocol); |
|
| 190 | - $provider->shareReceived($share); |
|
| 191 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 192 | - return new JSONResponse( |
|
| 193 | - ['message' => $e->getMessage()], |
|
| 194 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 195 | - ); |
|
| 196 | - } catch (ProviderCouldNotAddShareException $e) { |
|
| 197 | - return new JSONResponse( |
|
| 198 | - ['message' => $e->getMessage()], |
|
| 199 | - $e->getCode() |
|
| 200 | - ); |
|
| 201 | - } catch (\Exception $e) { |
|
| 202 | - return new JSONResponse( |
|
| 203 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 204 | - Http::STATUS_BAD_REQUEST |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $user = $this->userManager->get($shareWith); |
|
| 209 | - $recipientDisplayName = ''; |
|
| 210 | - if($user) { |
|
| 211 | - $recipientDisplayName = $user->getDisplayName(); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return new JSONResponse( |
|
| 215 | - ['recipientDisplayName' => $recipientDisplayName], |
|
| 216 | - Http::STATUS_CREATED); |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * receive notification about existing share |
|
| 222 | - * |
|
| 223 | - * @NoCSRFRequired |
|
| 224 | - * @PublicPage |
|
| 225 | - * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
| 226 | - * |
|
| 227 | - * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
| 228 | - * @param string $resourceType (calendar, file, contact,...) |
|
| 229 | - * @param string $providerId id of the share |
|
| 230 | - * @param array $notification the actual payload of the notification |
|
| 231 | - * @return JSONResponse |
|
| 232 | - */ |
|
| 233 | - public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
| 234 | - |
|
| 235 | - // check if all required parameters are set |
|
| 236 | - if ($notificationType === null || |
|
| 237 | - $resourceType === null || |
|
| 238 | - $providerId === null || |
|
| 239 | - !is_array($notification) |
|
| 240 | - ) { |
|
| 241 | - return new JSONResponse( |
|
| 242 | - ['message' => 'Missing arguments'], |
|
| 243 | - Http::STATUS_BAD_REQUEST |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - try { |
|
| 248 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 249 | - $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
| 250 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 251 | - return new JSONResponse( |
|
| 252 | - ['message' => $e->getMessage()], |
|
| 253 | - Http::STATUS_BAD_REQUEST |
|
| 254 | - ); |
|
| 255 | - } catch (ShareNotFound $e) { |
|
| 256 | - return new JSONResponse( |
|
| 257 | - ['message' => $e->getMessage()], |
|
| 258 | - Http::STATUS_BAD_REQUEST |
|
| 259 | - ); |
|
| 260 | - } catch (ActionNotSupportedException $e) { |
|
| 261 | - return new JSONResponse( |
|
| 262 | - ['message' => $e->getMessage()], |
|
| 263 | - Http::STATUS_NOT_IMPLEMENTED |
|
| 264 | - ); |
|
| 265 | - } catch (BadRequestException $e) { |
|
| 266 | - return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
| 267 | - } catch (AuthenticationFailedException $e) { |
|
| 268 | - return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
| 269 | - } |
|
| 270 | - catch (\Exception $e) { |
|
| 271 | - return new JSONResponse( |
|
| 272 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 273 | - Http::STATUS_BAD_REQUEST |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return new JSONResponse($result,Http::STATUS_CREATED); |
|
| 278 | - |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * map login name to internal LDAP UID if a LDAP backend is in use |
|
| 283 | - * |
|
| 284 | - * @param string $uid |
|
| 285 | - * @return string mixed |
|
| 286 | - */ |
|
| 287 | - private function mapUid($uid) { |
|
| 288 | - // FIXME this should be a method in the user management instead |
|
| 289 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
| 290 | - \OCP\Util::emitHook( |
|
| 291 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 292 | - 'preLoginNameUsedAsUserName', |
|
| 293 | - array('uid' => &$uid) |
|
| 294 | - ); |
|
| 295 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
| 296 | - |
|
| 297 | - return $uid; |
|
| 298 | - } |
|
| 55 | + /** @var ILogger */ |
|
| 56 | + private $logger; |
|
| 57 | + |
|
| 58 | + /** @var IUserManager */ |
|
| 59 | + private $userManager; |
|
| 60 | + |
|
| 61 | + /** @var IGroupManager */ |
|
| 62 | + private $groupManager; |
|
| 63 | + |
|
| 64 | + /** @var IURLGenerator */ |
|
| 65 | + private $urlGenerator; |
|
| 66 | + |
|
| 67 | + /** @var ICloudFederationProviderManager */ |
|
| 68 | + private $cloudFederationProviderManager; |
|
| 69 | + |
|
| 70 | + /** @var Config */ |
|
| 71 | + private $config; |
|
| 72 | + |
|
| 73 | + /** @var ICloudFederationFactory */ |
|
| 74 | + private $factory; |
|
| 75 | + |
|
| 76 | + /** @var ICloudIdManager */ |
|
| 77 | + private $cloudIdManager; |
|
| 78 | + |
|
| 79 | + public function __construct($appName, |
|
| 80 | + IRequest $request, |
|
| 81 | + ILogger $logger, |
|
| 82 | + IUserManager $userManager, |
|
| 83 | + IGroupManager $groupManager, |
|
| 84 | + IURLGenerator $urlGenerator, |
|
| 85 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 86 | + Config $config, |
|
| 87 | + ICloudFederationFactory $factory, |
|
| 88 | + ICloudIdManager $cloudIdManager |
|
| 89 | + ) { |
|
| 90 | + parent::__construct($appName, $request); |
|
| 91 | + |
|
| 92 | + $this->logger = $logger; |
|
| 93 | + $this->userManager = $userManager; |
|
| 94 | + $this->groupManager = $groupManager; |
|
| 95 | + $this->urlGenerator = $urlGenerator; |
|
| 96 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 97 | + $this->config = $config; |
|
| 98 | + $this->factory = $factory; |
|
| 99 | + $this->cloudIdManager = $cloudIdManager; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * add share |
|
| 104 | + * |
|
| 105 | + * @NoCSRFRequired |
|
| 106 | + * @PublicPage |
|
| 107 | + * @BruteForceProtection(action=receiveFederatedShare) |
|
| 108 | + * |
|
| 109 | + * @param string $shareWith |
|
| 110 | + * @param string $name resource name (e.g. document.odt) |
|
| 111 | + * @param string $description share description (optional) |
|
| 112 | + * @param string $providerId resource UID on the provider side |
|
| 113 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 114 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 115 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 116 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 117 | + * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]]) |
|
| 118 | + * @param string $shareType ('group' or 'user' share) |
|
| 119 | + * @param $resourceType ('file', 'calendar',...) |
|
| 120 | + * @return Http\DataResponse|JSONResponse |
|
| 121 | + * |
|
| 122 | + * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares |
|
| 123 | + */ |
|
| 124 | + public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) { |
|
| 125 | + |
|
| 126 | + // check if all required parameters are set |
|
| 127 | + if ($shareWith === null || |
|
| 128 | + $name === null || |
|
| 129 | + $providerId === null || |
|
| 130 | + $owner === null || |
|
| 131 | + $resourceType === null || |
|
| 132 | + $shareType === null || |
|
| 133 | + !is_array($protocol) || |
|
| 134 | + !isset($protocol['name']) || |
|
| 135 | + !isset ($protocol['options']) || |
|
| 136 | + !is_array($protocol['options']) || |
|
| 137 | + !isset($protocol['options']['sharedSecret']) |
|
| 138 | + ) { |
|
| 139 | + return new JSONResponse( |
|
| 140 | + ['message' => 'Missing arguments'], |
|
| 141 | + Http::STATUS_BAD_REQUEST |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
|
| 146 | + if (!in_array($shareType, $supportedShareTypes)) { |
|
| 147 | + return new JSONResponse( |
|
| 148 | + ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
| 149 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
| 154 | + $shareWith = $cloudId->getUser(); |
|
| 155 | + |
|
| 156 | + if ($shareType === 'user') { |
|
| 157 | + $shareWith = $this->mapUid($shareWith); |
|
| 158 | + |
|
| 159 | + if (!$this->userManager->userExists($shareWith)) { |
|
| 160 | + return new JSONResponse( |
|
| 161 | + ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 162 | + Http::STATUS_BAD_REQUEST |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($shareType === 'group') { |
|
| 168 | + if(!$this->groupManager->groupExists($shareWith)) { |
|
| 169 | + return new JSONResponse( |
|
| 170 | + ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 171 | + Http::STATUS_BAD_REQUEST |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // if no explicit display name is given, we use the uid as display name |
|
| 177 | + $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; |
|
| 178 | + $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; |
|
| 179 | + |
|
| 180 | + // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner |
|
| 181 | + if ($sharedBy === null) { |
|
| 182 | + $sharedBy = $owner; |
|
| 183 | + $sharedByDisplayName = $ownerDisplayName; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + try { |
|
| 187 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 188 | + $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); |
|
| 189 | + $share->setProtocol($protocol); |
|
| 190 | + $provider->shareReceived($share); |
|
| 191 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 192 | + return new JSONResponse( |
|
| 193 | + ['message' => $e->getMessage()], |
|
| 194 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 195 | + ); |
|
| 196 | + } catch (ProviderCouldNotAddShareException $e) { |
|
| 197 | + return new JSONResponse( |
|
| 198 | + ['message' => $e->getMessage()], |
|
| 199 | + $e->getCode() |
|
| 200 | + ); |
|
| 201 | + } catch (\Exception $e) { |
|
| 202 | + return new JSONResponse( |
|
| 203 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 204 | + Http::STATUS_BAD_REQUEST |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $user = $this->userManager->get($shareWith); |
|
| 209 | + $recipientDisplayName = ''; |
|
| 210 | + if($user) { |
|
| 211 | + $recipientDisplayName = $user->getDisplayName(); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return new JSONResponse( |
|
| 215 | + ['recipientDisplayName' => $recipientDisplayName], |
|
| 216 | + Http::STATUS_CREATED); |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * receive notification about existing share |
|
| 222 | + * |
|
| 223 | + * @NoCSRFRequired |
|
| 224 | + * @PublicPage |
|
| 225 | + * @BruteForceProtection(action=receiveFederatedShareNotification) |
|
| 226 | + * |
|
| 227 | + * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) |
|
| 228 | + * @param string $resourceType (calendar, file, contact,...) |
|
| 229 | + * @param string $providerId id of the share |
|
| 230 | + * @param array $notification the actual payload of the notification |
|
| 231 | + * @return JSONResponse |
|
| 232 | + */ |
|
| 233 | + public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) { |
|
| 234 | + |
|
| 235 | + // check if all required parameters are set |
|
| 236 | + if ($notificationType === null || |
|
| 237 | + $resourceType === null || |
|
| 238 | + $providerId === null || |
|
| 239 | + !is_array($notification) |
|
| 240 | + ) { |
|
| 241 | + return new JSONResponse( |
|
| 242 | + ['message' => 'Missing arguments'], |
|
| 243 | + Http::STATUS_BAD_REQUEST |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + try { |
|
| 248 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); |
|
| 249 | + $result = $provider->notificationReceived($notificationType, $providerId, $notification); |
|
| 250 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 251 | + return new JSONResponse( |
|
| 252 | + ['message' => $e->getMessage()], |
|
| 253 | + Http::STATUS_BAD_REQUEST |
|
| 254 | + ); |
|
| 255 | + } catch (ShareNotFound $e) { |
|
| 256 | + return new JSONResponse( |
|
| 257 | + ['message' => $e->getMessage()], |
|
| 258 | + Http::STATUS_BAD_REQUEST |
|
| 259 | + ); |
|
| 260 | + } catch (ActionNotSupportedException $e) { |
|
| 261 | + return new JSONResponse( |
|
| 262 | + ['message' => $e->getMessage()], |
|
| 263 | + Http::STATUS_NOT_IMPLEMENTED |
|
| 264 | + ); |
|
| 265 | + } catch (BadRequestException $e) { |
|
| 266 | + return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST); |
|
| 267 | + } catch (AuthenticationFailedException $e) { |
|
| 268 | + return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN); |
|
| 269 | + } |
|
| 270 | + catch (\Exception $e) { |
|
| 271 | + return new JSONResponse( |
|
| 272 | + ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 273 | + Http::STATUS_BAD_REQUEST |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return new JSONResponse($result,Http::STATUS_CREATED); |
|
| 278 | + |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * map login name to internal LDAP UID if a LDAP backend is in use |
|
| 283 | + * |
|
| 284 | + * @param string $uid |
|
| 285 | + * @return string mixed |
|
| 286 | + */ |
|
| 287 | + private function mapUid($uid) { |
|
| 288 | + // FIXME this should be a method in the user management instead |
|
| 289 | + $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
| 290 | + \OCP\Util::emitHook( |
|
| 291 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 292 | + 'preLoginNameUsedAsUserName', |
|
| 293 | + array('uid' => &$uid) |
|
| 294 | + ); |
|
| 295 | + $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
| 296 | + |
|
| 297 | + return $uid; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | 300 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); |
| 146 | 146 | if (!in_array($shareType, $supportedShareTypes)) { |
| 147 | 147 | return new JSONResponse( |
| 148 | - ['message' => 'Share type "' . $shareType . '" not implemented'], |
|
| 148 | + ['message' => 'Share type "'.$shareType.'" not implemented'], |
|
| 149 | 149 | Http::STATUS_NOT_IMPLEMENTED |
| 150 | 150 | ); |
| 151 | 151 | } |
@@ -158,16 +158,16 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | if (!$this->userManager->userExists($shareWith)) { |
| 160 | 160 | return new JSONResponse( |
| 161 | - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 161 | + ['message' => 'User "'.$shareWith.'" does not exists at '.$this->urlGenerator->getBaseUrl()], |
|
| 162 | 162 | Http::STATUS_BAD_REQUEST |
| 163 | 163 | ); |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | if ($shareType === 'group') { |
| 168 | - if(!$this->groupManager->groupExists($shareWith)) { |
|
| 168 | + if (!$this->groupManager->groupExists($shareWith)) { |
|
| 169 | 169 | return new JSONResponse( |
| 170 | - ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], |
|
| 170 | + ['message' => 'Group "'.$shareWith.'" does not exists at '.$this->urlGenerator->getBaseUrl()], |
|
| 171 | 171 | Http::STATUS_BAD_REQUEST |
| 172 | 172 | ); |
| 173 | 173 | } |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | ); |
| 201 | 201 | } catch (\Exception $e) { |
| 202 | 202 | return new JSONResponse( |
| 203 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 203 | + ['message' => 'Internal error at '.$this->urlGenerator->getBaseUrl()], |
|
| 204 | 204 | Http::STATUS_BAD_REQUEST |
| 205 | 205 | ); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $user = $this->userManager->get($shareWith); |
| 209 | 209 | $recipientDisplayName = ''; |
| 210 | - if($user) { |
|
| 210 | + if ($user) { |
|
| 211 | 211 | $recipientDisplayName = $user->getDisplayName(); |
| 212 | 212 | } |
| 213 | 213 | |
@@ -269,12 +269,12 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | catch (\Exception $e) { |
| 271 | 271 | return new JSONResponse( |
| 272 | - ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], |
|
| 272 | + ['message' => 'Internal error at '.$this->urlGenerator->getBaseUrl()], |
|
| 273 | 273 | Http::STATUS_BAD_REQUEST |
| 274 | 274 | ); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - return new JSONResponse($result,Http::STATUS_CREATED); |
|
| 277 | + return new JSONResponse($result, Http::STATUS_CREATED); |
|
| 278 | 278 | |
| 279 | 279 | } |
| 280 | 280 | |
@@ -286,13 +286,13 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | private function mapUid($uid) { |
| 288 | 288 | // FIXME this should be a method in the user management instead |
| 289 | - $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); |
|
| 289 | + $this->logger->debug('shareWith before, '.$uid, ['app' => $this->appName]); |
|
| 290 | 290 | \OCP\Util::emitHook( |
| 291 | 291 | '\OCA\Files_Sharing\API\Server2Server', |
| 292 | 292 | 'preLoginNameUsedAsUserName', |
| 293 | 293 | array('uid' => &$uid) |
| 294 | 294 | ); |
| 295 | - $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]); |
|
| 295 | + $this->logger->debug('shareWith after, '.$uid, ['app' => $this->appName]); |
|
| 296 | 296 | |
| 297 | 297 | return $uid; |
| 298 | 298 | } |
@@ -39,117 +39,117 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Application extends App { |
| 41 | 41 | |
| 42 | - /** @var FederatedShareProvider */ |
|
| 43 | - protected $federatedShareProvider; |
|
| 42 | + /** @var FederatedShareProvider */ |
|
| 43 | + protected $federatedShareProvider; |
|
| 44 | 44 | |
| 45 | - public function __construct() { |
|
| 46 | - parent::__construct('federatedfilesharing'); |
|
| 45 | + public function __construct() { |
|
| 46 | + parent::__construct('federatedfilesharing'); |
|
| 47 | 47 | |
| 48 | - $container = $this->getContainer(); |
|
| 49 | - $server = $container->getServer(); |
|
| 48 | + $container = $this->getContainer(); |
|
| 49 | + $server = $container->getServer(); |
|
| 50 | 50 | |
| 51 | - $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | - $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | - 'Federated Files Sharing', |
|
| 54 | - function() use ($container) { |
|
| 55 | - $server = $container->getServer(); |
|
| 56 | - return new CloudFederationProviderFiles( |
|
| 57 | - $server->getAppManager(), |
|
| 58 | - $server->query(FederatedShareProvider::class), |
|
| 59 | - $server->query(AddressHandler::class), |
|
| 60 | - $server->getLogger(), |
|
| 61 | - $server->getUserManager(), |
|
| 62 | - $server->getCloudIdManager(), |
|
| 63 | - $server->getActivityManager(), |
|
| 64 | - $server->getNotificationManager(), |
|
| 65 | - $server->getURLGenerator(), |
|
| 66 | - $server->getCloudFederationFactory(), |
|
| 67 | - $server->getCloudFederationProviderManager(), |
|
| 68 | - $server->getDatabaseConnection(), |
|
| 69 | - $server->getGroupManager() |
|
| 70 | - ); |
|
| 71 | - }); |
|
| 51 | + $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | + $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | + 'Federated Files Sharing', |
|
| 54 | + function() use ($container) { |
|
| 55 | + $server = $container->getServer(); |
|
| 56 | + return new CloudFederationProviderFiles( |
|
| 57 | + $server->getAppManager(), |
|
| 58 | + $server->query(FederatedShareProvider::class), |
|
| 59 | + $server->query(AddressHandler::class), |
|
| 60 | + $server->getLogger(), |
|
| 61 | + $server->getUserManager(), |
|
| 62 | + $server->getCloudIdManager(), |
|
| 63 | + $server->getActivityManager(), |
|
| 64 | + $server->getNotificationManager(), |
|
| 65 | + $server->getURLGenerator(), |
|
| 66 | + $server->getCloudFederationFactory(), |
|
| 67 | + $server->getCloudFederationProviderManager(), |
|
| 68 | + $server->getDatabaseConnection(), |
|
| 69 | + $server->getGroupManager() |
|
| 70 | + ); |
|
| 71 | + }); |
|
| 72 | 72 | |
| 73 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 74 | - $addressHandler = new AddressHandler( |
|
| 75 | - $server->getURLGenerator(), |
|
| 76 | - $server->getL10N('federatedfilesharing'), |
|
| 77 | - $server->getCloudIdManager() |
|
| 78 | - ); |
|
| 79 | - $notification = new Notifications( |
|
| 80 | - $addressHandler, |
|
| 81 | - $server->getHTTPClientService(), |
|
| 82 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 83 | - \OC::$server->getJobList(), |
|
| 84 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 85 | - \OC::$server->getCloudFederationFactory() |
|
| 86 | - ); |
|
| 87 | - return new RequestHandlerController( |
|
| 88 | - $c->query('AppName'), |
|
| 89 | - $server->getRequest(), |
|
| 90 | - $this->getFederatedShareProvider(), |
|
| 91 | - $server->getDatabaseConnection(), |
|
| 92 | - $server->getShareManager(), |
|
| 93 | - $notification, |
|
| 94 | - $addressHandler, |
|
| 95 | - $server->getUserManager(), |
|
| 96 | - $server->getCloudIdManager(), |
|
| 97 | - $server->getLogger(), |
|
| 98 | - $server->getCloudFederationFactory(), |
|
| 99 | - $server->getCloudFederationProviderManager() |
|
| 100 | - ); |
|
| 101 | - }); |
|
| 102 | - } |
|
| 73 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 74 | + $addressHandler = new AddressHandler( |
|
| 75 | + $server->getURLGenerator(), |
|
| 76 | + $server->getL10N('federatedfilesharing'), |
|
| 77 | + $server->getCloudIdManager() |
|
| 78 | + ); |
|
| 79 | + $notification = new Notifications( |
|
| 80 | + $addressHandler, |
|
| 81 | + $server->getHTTPClientService(), |
|
| 82 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 83 | + \OC::$server->getJobList(), |
|
| 84 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 85 | + \OC::$server->getCloudFederationFactory() |
|
| 86 | + ); |
|
| 87 | + return new RequestHandlerController( |
|
| 88 | + $c->query('AppName'), |
|
| 89 | + $server->getRequest(), |
|
| 90 | + $this->getFederatedShareProvider(), |
|
| 91 | + $server->getDatabaseConnection(), |
|
| 92 | + $server->getShareManager(), |
|
| 93 | + $notification, |
|
| 94 | + $addressHandler, |
|
| 95 | + $server->getUserManager(), |
|
| 96 | + $server->getCloudIdManager(), |
|
| 97 | + $server->getLogger(), |
|
| 98 | + $server->getCloudFederationFactory(), |
|
| 99 | + $server->getCloudFederationProviderManager() |
|
| 100 | + ); |
|
| 101 | + }); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * get instance of federated share provider |
|
| 106 | - * |
|
| 107 | - * @return FederatedShareProvider |
|
| 108 | - */ |
|
| 109 | - public function getFederatedShareProvider() { |
|
| 110 | - if ($this->federatedShareProvider === null) { |
|
| 111 | - $this->initFederatedShareProvider(); |
|
| 112 | - } |
|
| 113 | - return $this->federatedShareProvider; |
|
| 114 | - } |
|
| 104 | + /** |
|
| 105 | + * get instance of federated share provider |
|
| 106 | + * |
|
| 107 | + * @return FederatedShareProvider |
|
| 108 | + */ |
|
| 109 | + public function getFederatedShareProvider() { |
|
| 110 | + if ($this->federatedShareProvider === null) { |
|
| 111 | + $this->initFederatedShareProvider(); |
|
| 112 | + } |
|
| 113 | + return $this->federatedShareProvider; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * initialize federated share provider |
|
| 118 | - */ |
|
| 119 | - protected function initFederatedShareProvider() { |
|
| 120 | - $c = $this->getContainer(); |
|
| 121 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 122 | - \OC::$server->getURLGenerator(), |
|
| 123 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 124 | - \OC::$server->getCloudIdManager() |
|
| 125 | - ); |
|
| 126 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 127 | - $addressHandler, |
|
| 128 | - \OC::$server->getHTTPClientService(), |
|
| 129 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 130 | - \OC::$server->getJobList(), |
|
| 131 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 132 | - \OC::$server->getCloudFederationFactory() |
|
| 133 | - ); |
|
| 134 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 135 | - \OC::$server->getSecureRandom() |
|
| 136 | - ); |
|
| 116 | + /** |
|
| 117 | + * initialize federated share provider |
|
| 118 | + */ |
|
| 119 | + protected function initFederatedShareProvider() { |
|
| 120 | + $c = $this->getContainer(); |
|
| 121 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 122 | + \OC::$server->getURLGenerator(), |
|
| 123 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 124 | + \OC::$server->getCloudIdManager() |
|
| 125 | + ); |
|
| 126 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 127 | + $addressHandler, |
|
| 128 | + \OC::$server->getHTTPClientService(), |
|
| 129 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 130 | + \OC::$server->getJobList(), |
|
| 131 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 132 | + \OC::$server->getCloudFederationFactory() |
|
| 133 | + ); |
|
| 134 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 135 | + \OC::$server->getSecureRandom() |
|
| 136 | + ); |
|
| 137 | 137 | |
| 138 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 139 | - \OC::$server->getDatabaseConnection(), |
|
| 140 | - $addressHandler, |
|
| 141 | - $notifications, |
|
| 142 | - $tokenHandler, |
|
| 143 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 144 | - \OC::$server->getLogger(), |
|
| 145 | - \OC::$server->getLazyRootFolder(), |
|
| 146 | - \OC::$server->getConfig(), |
|
| 147 | - \OC::$server->getUserManager(), |
|
| 148 | - \OC::$server->getCloudIdManager(), |
|
| 149 | - $c->query(IConfig::class), |
|
| 150 | - \OC::$server->getCloudFederationProviderManager() |
|
| 138 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 139 | + \OC::$server->getDatabaseConnection(), |
|
| 140 | + $addressHandler, |
|
| 141 | + $notifications, |
|
| 142 | + $tokenHandler, |
|
| 143 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 144 | + \OC::$server->getLogger(), |
|
| 145 | + \OC::$server->getLazyRootFolder(), |
|
| 146 | + \OC::$server->getConfig(), |
|
| 147 | + \OC::$server->getUserManager(), |
|
| 148 | + \OC::$server->getCloudIdManager(), |
|
| 149 | + $c->query(IConfig::class), |
|
| 150 | + \OC::$server->getCloudFederationProviderManager() |
|
| 151 | 151 | |
| 152 | - ); |
|
| 153 | - } |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | } |
@@ -45,138 +45,138 @@ |
||
| 45 | 45 | use OCA\Files_Sharing\External\Manager; |
| 46 | 46 | |
| 47 | 47 | class Application extends App { |
| 48 | - public function __construct(array $urlParams = array()) { |
|
| 49 | - parent::__construct('files_sharing', $urlParams); |
|
| 48 | + public function __construct(array $urlParams = array()) { |
|
| 49 | + parent::__construct('files_sharing', $urlParams); |
|
| 50 | 50 | |
| 51 | - $container = $this->getContainer(); |
|
| 52 | - /** @var IServerContainer $server */ |
|
| 53 | - $server = $container->getServer(); |
|
| 51 | + $container = $this->getContainer(); |
|
| 52 | + /** @var IServerContainer $server */ |
|
| 53 | + $server = $container->getServer(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Controllers |
|
| 57 | - */ |
|
| 58 | - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
| 59 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 60 | - return new ShareController( |
|
| 61 | - $c->query('AppName'), |
|
| 62 | - $c->query('Request'), |
|
| 63 | - $server->getConfig(), |
|
| 64 | - $server->getURLGenerator(), |
|
| 65 | - $server->getUserManager(), |
|
| 66 | - $server->getLogger(), |
|
| 67 | - $server->getActivityManager(), |
|
| 68 | - $server->getShareManager(), |
|
| 69 | - $server->getSession(), |
|
| 70 | - $server->getPreviewManager(), |
|
| 71 | - $server->getRootFolder(), |
|
| 72 | - $federatedSharingApp->getFederatedShareProvider(), |
|
| 73 | - $server->getEventDispatcher(), |
|
| 74 | - $server->getL10N($c->query('AppName')), |
|
| 75 | - $server->query(Defaults::class) |
|
| 76 | - ); |
|
| 77 | - }); |
|
| 78 | - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
| 79 | - return new ExternalSharesController( |
|
| 80 | - $c->query('AppName'), |
|
| 81 | - $c->query('Request'), |
|
| 82 | - $c->query('ExternalManager'), |
|
| 83 | - $c->query('HttpClientService') |
|
| 84 | - ); |
|
| 85 | - }); |
|
| 55 | + /** |
|
| 56 | + * Controllers |
|
| 57 | + */ |
|
| 58 | + $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
| 59 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 60 | + return new ShareController( |
|
| 61 | + $c->query('AppName'), |
|
| 62 | + $c->query('Request'), |
|
| 63 | + $server->getConfig(), |
|
| 64 | + $server->getURLGenerator(), |
|
| 65 | + $server->getUserManager(), |
|
| 66 | + $server->getLogger(), |
|
| 67 | + $server->getActivityManager(), |
|
| 68 | + $server->getShareManager(), |
|
| 69 | + $server->getSession(), |
|
| 70 | + $server->getPreviewManager(), |
|
| 71 | + $server->getRootFolder(), |
|
| 72 | + $federatedSharingApp->getFederatedShareProvider(), |
|
| 73 | + $server->getEventDispatcher(), |
|
| 74 | + $server->getL10N($c->query('AppName')), |
|
| 75 | + $server->query(Defaults::class) |
|
| 76 | + ); |
|
| 77 | + }); |
|
| 78 | + $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
| 79 | + return new ExternalSharesController( |
|
| 80 | + $c->query('AppName'), |
|
| 81 | + $c->query('Request'), |
|
| 82 | + $c->query('ExternalManager'), |
|
| 83 | + $c->query('HttpClientService') |
|
| 84 | + ); |
|
| 85 | + }); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Core class wrappers |
|
| 89 | - */ |
|
| 90 | - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
| 91 | - return $server->getHTTPClientService(); |
|
| 92 | - }); |
|
| 93 | - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
| 94 | - return $server->getCloudIdManager(); |
|
| 95 | - }); |
|
| 96 | - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
| 97 | - $user = $server->getUserSession()->getUser(); |
|
| 98 | - $uid = $user ? $user->getUID() : null; |
|
| 99 | - return new \OCA\Files_Sharing\External\Manager( |
|
| 100 | - $server->getDatabaseConnection(), |
|
| 101 | - \OC\Files\Filesystem::getMountManager(), |
|
| 102 | - \OC\Files\Filesystem::getLoader(), |
|
| 103 | - $server->getHTTPClientService(), |
|
| 104 | - $server->getNotificationManager(), |
|
| 105 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 106 | - $server->getCloudFederationProviderManager(), |
|
| 107 | - $server->getCloudFederationFactory(), |
|
| 108 | - $server->getGroupManager(), |
|
| 109 | - $server->getUserManager(), |
|
| 110 | - $uid |
|
| 111 | - ); |
|
| 112 | - }); |
|
| 113 | - $container->registerAlias(Manager::class, 'ExternalManager'); |
|
| 87 | + /** |
|
| 88 | + * Core class wrappers |
|
| 89 | + */ |
|
| 90 | + $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
| 91 | + return $server->getHTTPClientService(); |
|
| 92 | + }); |
|
| 93 | + $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
| 94 | + return $server->getCloudIdManager(); |
|
| 95 | + }); |
|
| 96 | + $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
| 97 | + $user = $server->getUserSession()->getUser(); |
|
| 98 | + $uid = $user ? $user->getUID() : null; |
|
| 99 | + return new \OCA\Files_Sharing\External\Manager( |
|
| 100 | + $server->getDatabaseConnection(), |
|
| 101 | + \OC\Files\Filesystem::getMountManager(), |
|
| 102 | + \OC\Files\Filesystem::getLoader(), |
|
| 103 | + $server->getHTTPClientService(), |
|
| 104 | + $server->getNotificationManager(), |
|
| 105 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 106 | + $server->getCloudFederationProviderManager(), |
|
| 107 | + $server->getCloudFederationFactory(), |
|
| 108 | + $server->getGroupManager(), |
|
| 109 | + $server->getUserManager(), |
|
| 110 | + $uid |
|
| 111 | + ); |
|
| 112 | + }); |
|
| 113 | + $container->registerAlias(Manager::class, 'ExternalManager'); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Middleware |
|
| 117 | - */ |
|
| 118 | - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 119 | - return new SharingCheckMiddleware( |
|
| 120 | - $c->query('AppName'), |
|
| 121 | - $server->getConfig(), |
|
| 122 | - $server->getAppManager(), |
|
| 123 | - $c['ControllerMethodReflector'], |
|
| 124 | - $server->getShareManager(), |
|
| 125 | - $server->getRequest() |
|
| 126 | - ); |
|
| 127 | - }); |
|
| 115 | + /** |
|
| 116 | + * Middleware |
|
| 117 | + */ |
|
| 118 | + $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 119 | + return new SharingCheckMiddleware( |
|
| 120 | + $c->query('AppName'), |
|
| 121 | + $server->getConfig(), |
|
| 122 | + $server->getAppManager(), |
|
| 123 | + $c['ControllerMethodReflector'], |
|
| 124 | + $server->getShareManager(), |
|
| 125 | + $server->getRequest() |
|
| 126 | + ); |
|
| 127 | + }); |
|
| 128 | 128 | |
| 129 | - $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 130 | - return new OCSShareAPIMiddleware( |
|
| 131 | - $server->getShareManager(), |
|
| 132 | - $server->getL10N($c->query('AppName')) |
|
| 133 | - ); |
|
| 134 | - }); |
|
| 129 | + $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 130 | + return new OCSShareAPIMiddleware( |
|
| 131 | + $server->getShareManager(), |
|
| 132 | + $server->getL10N($c->query('AppName')) |
|
| 133 | + ); |
|
| 134 | + }); |
|
| 135 | 135 | |
| 136 | - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
| 137 | - return new ShareInfoMiddleware( |
|
| 138 | - $server->getShareManager() |
|
| 139 | - ); |
|
| 140 | - }); |
|
| 136 | + $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
| 137 | + return new ShareInfoMiddleware( |
|
| 138 | + $server->getShareManager() |
|
| 139 | + ); |
|
| 140 | + }); |
|
| 141 | 141 | |
| 142 | - // Execute middlewares |
|
| 143 | - $container->registerMiddleWare('SharingCheckMiddleware'); |
|
| 144 | - $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
| 145 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
| 142 | + // Execute middlewares |
|
| 143 | + $container->registerMiddleWare('SharingCheckMiddleware'); |
|
| 144 | + $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
| 145 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
| 146 | 146 | |
| 147 | - $container->registerService('MountProvider', function (IContainer $c) { |
|
| 148 | - /** @var \OCP\IServerContainer $server */ |
|
| 149 | - $server = $c->query('ServerContainer'); |
|
| 150 | - return new MountProvider( |
|
| 151 | - $server->getConfig(), |
|
| 152 | - $server->getShareManager(), |
|
| 153 | - $server->getLogger() |
|
| 154 | - ); |
|
| 155 | - }); |
|
| 147 | + $container->registerService('MountProvider', function (IContainer $c) { |
|
| 148 | + /** @var \OCP\IServerContainer $server */ |
|
| 149 | + $server = $c->query('ServerContainer'); |
|
| 150 | + return new MountProvider( |
|
| 151 | + $server->getConfig(), |
|
| 152 | + $server->getShareManager(), |
|
| 153 | + $server->getLogger() |
|
| 154 | + ); |
|
| 155 | + }); |
|
| 156 | 156 | |
| 157 | - $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
| 158 | - /** @var \OCP\IServerContainer $server */ |
|
| 159 | - $server = $c->query('ServerContainer'); |
|
| 160 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
| 161 | - $server->getDatabaseConnection(), |
|
| 162 | - function() use ($c) { |
|
| 163 | - return $c->query('ExternalManager'); |
|
| 164 | - }, |
|
| 165 | - $server->getCloudIdManager() |
|
| 166 | - ); |
|
| 167 | - }); |
|
| 157 | + $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
| 158 | + /** @var \OCP\IServerContainer $server */ |
|
| 159 | + $server = $c->query('ServerContainer'); |
|
| 160 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
| 161 | + $server->getDatabaseConnection(), |
|
| 162 | + function() use ($c) { |
|
| 163 | + return $c->query('ExternalManager'); |
|
| 164 | + }, |
|
| 165 | + $server->getCloudIdManager() |
|
| 166 | + ); |
|
| 167 | + }); |
|
| 168 | 168 | |
| 169 | - /* |
|
| 169 | + /* |
|
| 170 | 170 | * Register capabilities |
| 171 | 171 | */ |
| 172 | - $container->registerCapability(Capabilities::class); |
|
| 173 | - } |
|
| 172 | + $container->registerCapability(Capabilities::class); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - public function registerMountProviders() { |
|
| 176 | - /** @var \OCP\IServerContainer $server */ |
|
| 177 | - $server = $this->getContainer()->query('ServerContainer'); |
|
| 178 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
| 179 | - $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
| 180 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
| 181 | - } |
|
| 175 | + public function registerMountProviders() { |
|
| 176 | + /** @var \OCP\IServerContainer $server */ |
|
| 177 | + $server = $this->getContainer()->query('ServerContainer'); |
|
| 178 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
| 179 | + $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
| 180 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
| 181 | + } |
|
| 182 | 182 | } |