Completed
Pull Request — master (#9345)
by Björn
21:23
created
lib/public/Federation/Exceptions/BadRequestException.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,42 +25,42 @@
 block discarded – undo
25 25
 
26 26
 class BadRequestException extends HintException {
27 27
 
28
-	private $parameterList;
28
+    private $parameterList;
29 29
 
30
-	/**
31
-	 * BadRequestException constructor.
32
-	 *
33
-	 * @param array $missingParameters
34
-	 */
35
-	public function __construct(array $missingParameters) {
36
-		$l = \OC::$server->getL10N('federation');
37
-		$this->parameterList = $missingParameters;
38
-		$parameterList = implode(',', $missingParameters);
39
-		$message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList;
40
-		$hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]);
41
-		parent::__construct($message, $hint);
42
-	}
30
+    /**
31
+     * BadRequestException constructor.
32
+     *
33
+     * @param array $missingParameters
34
+     */
35
+    public function __construct(array $missingParameters) {
36
+        $l = \OC::$server->getL10N('federation');
37
+        $this->parameterList = $missingParameters;
38
+        $parameterList = implode(',', $missingParameters);
39
+        $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList;
40
+        $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]);
41
+        parent::__construct($message, $hint);
42
+    }
43 43
 
44
-	/**
45
-	 * get array with the return message as defined in the OCM API
46
-	 *
47
-	 * @return array
48
-	 */
49
-	public function getReturnMessage() {
50
-		$result = [
51
-			'message' => 'RESOURCE_NOT_FOUND',
52
-			'validationErrors' =>[
53
-			]
54
-		];
44
+    /**
45
+     * get array with the return message as defined in the OCM API
46
+     *
47
+     * @return array
48
+     */
49
+    public function getReturnMessage() {
50
+        $result = [
51
+            'message' => 'RESOURCE_NOT_FOUND',
52
+            'validationErrors' =>[
53
+            ]
54
+        ];
55 55
 
56
-		foreach ($this->parameterList as $missingParameter) {
57
-			$result['validationErrors'] = [
58
-				'name' => $missingParameter,
59
-				'message' => 'NOT_FOUND'
60
-			];
61
-		}
56
+        foreach ($this->parameterList as $missingParameter) {
57
+            $result['validationErrors'] = [
58
+                'name' => $missingParameter,
59
+                'message' => 'NOT_FOUND'
60
+            ];
61
+        }
62 62
 
63
-		return $result;
64
-	}
63
+        return $result;
64
+    }
65 65
 
66 66
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/AuthenticationFailedException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@
 block discarded – undo
25 25
 
26 26
 class AuthenticationFailedException extends HintException {
27 27
 
28
-	/**
29
-	 * BadRequestException constructor.
30
-	 *
31
-	 * @param array $missingParameters
32
-	 */
33
-	public function __construct() {
34
-		$l = \OC::$server->getL10N('federation');
35
-		$message = 'Authentication failed, wrong token or provider ID given';
36
-		$hint = $l->t('Authentication failed, wrong token or provider ID given');
37
-		parent::__construct($message, $hint);
38
-	}
28
+    /**
29
+     * BadRequestException constructor.
30
+     *
31
+     * @param array $missingParameters
32
+     */
33
+    public function __construct() {
34
+        $l = \OC::$server->getL10N('federation');
35
+        $message = 'Authentication failed, wrong token or provider ID given';
36
+        $hint = $l->t('Authentication failed, wrong token or provider ID given');
37
+        parent::__construct($message, $hint);
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
lib/public/Share/IShareProvider.php 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -36,172 +36,172 @@
 block discarded – undo
36 36
  */
37 37
 interface IShareProvider {
38 38
 
39
-	/**
40
-	 * Return the identifier of this provider.
41
-	 *
42
-	 * @return string Containing only [a-zA-Z0-9]
43
-	 * @since 9.0.0
44
-	 */
45
-	public function identifier();
46
-
47
-	/**
48
-	 * Create a share
49
-	 *
50
-	 * @param \OCP\Share\IShare $share
51
-	 * @return \OCP\Share\IShare The share object
52
-	 * @since 9.0.0
53
-	 */
54
-	public function create(\OCP\Share\IShare $share);
55
-
56
-	/**
57
-	 * Update a share
58
-	 *
59
-	 * @param \OCP\Share\IShare $share
60
-	 * @return \OCP\Share\IShare The share object
61
-	 * @since 9.0.0
62
-	 */
63
-	public function update(\OCP\Share\IShare $share);
64
-
65
-	/**
66
-	 * Delete a share
67
-	 *
68
-	 * @param \OCP\Share\IShare $share
69
-	 * @since 9.0.0
70
-	 */
71
-	public function delete(\OCP\Share\IShare $share);
72
-
73
-	/**
74
-	 * Unshare a file from self as recipient.
75
-	 * This may require special handling. If a user unshares a group
76
-	 * share from their self then the original group share should still exist.
77
-	 *
78
-	 * @param \OCP\Share\IShare $share
79
-	 * @param string $recipient UserId of the recipient
80
-	 * @since 9.0.0
81
-	 */
82
-	public function deleteFromSelf(\OCP\Share\IShare $share, $recipient);
83
-
84
-	/**
85
-	 * Move a share as a recipient.
86
-	 * This is updating the share target. Thus the mount point of the recipient.
87
-	 * This may require special handling. If a user moves a group share
88
-	 * the target should only be changed for them.
89
-	 *
90
-	 * @param \OCP\Share\IShare $share
91
-	 * @param string $recipient userId of recipient
92
-	 * @return \OCP\Share\IShare
93
-	 * @since 9.0.0
94
-	 */
95
-	public function move(\OCP\Share\IShare $share, $recipient);
96
-
97
-	/**
98
-	 * Get all shares by the given user in a folder
99
-	 *
100
-	 * @param string $userId
101
-	 * @param Folder $node
102
-	 * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
103
-	 * @return \OCP\Share\IShare[]
104
-	 * @since 11.0.0
105
-	 */
106
-	public function getSharesInFolder($userId, Folder $node, $reshares);
107
-
108
-	/**
109
-	 * Get all shares by the given user
110
-	 *
111
-	 * @param string $userId
112
-	 * @param int $shareType
113
-	 * @param Node|null $node
114
-	 * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
115
-	 * @param int $limit The maximum number of shares to be returned, -1 for all shares
116
-	 * @param int $offset
117
-	 * @return \OCP\Share\IShare[]
118
-	 * @since 9.0.0
119
-	 */
120
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset);
121
-
122
-	/**
123
-	 * Get share by id
124
-	 *
125
-	 * @param int $id
126
-	 * @param string|null $recipientId
127
-	 * @return \OCP\Share\IShare
128
-	 * @throws ShareNotFoundException
129
-	 * @since 9.0.0
130
-	 */
131
-	public function getShareById($id, $recipientId = null);
132
-
133
-	/**
134
-	 * Get shares for a given path
135
-	 *
136
-	 * @param Node $path
137
-	 * @return \OCP\Share\IShare[]
138
-	 * @since 9.0.0
139
-	 */
140
-	public function getSharesByPath(Node $path);
141
-
142
-	/**
143
-	 * Get shared with the given user
144
-	 *
145
-	 * @param string $userId get shares where this user is the recipient
146
-	 * @param int $shareType
147
-	 * @param Node|null $node
148
-	 * @param int $limit The max number of entries returned, -1 for all
149
-	 * @param int $offset
150
-	 * @return \OCP\Share\IShare[]
151
-	 * @since 9.0.0
152
-	 */
153
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset);
154
-
155
-	/**
156
-	 * Get a share by token
157
-	 *
158
-	 * @param string $token
159
-	 * @return \OCP\Share\IShare
160
-	 * @throws ShareNotFound
161
-	 * @since 9.0.0
162
-	 */
163
-	public function getShareByToken($token);
164
-
165
-	/**
166
-	 * A user is deleted from the system
167
-	 * So clean up the relevant shares.
168
-	 *
169
-	 * @param string $uid
170
-	 * @param int $shareType
171
-	 * @since 9.1.0
172
-	 */
173
-	public function userDeleted($uid, $shareType);
174
-
175
-	/**
176
-	 * A group is deleted from the system.
177
-	 * We have to clean up all shares to this group.
178
-	 * Providers not handling group shares should just return
179
-	 *
180
-	 * @param string $gid
181
-	 * @since 9.1.0
182
-	 */
183
-	public function groupDeleted($gid);
184
-
185
-	/**
186
-	 * A user is deleted from a group
187
-	 * We have to clean up all the related user specific group shares
188
-	 * Providers not handling group shares should just return
189
-	 *
190
-	 * @param string $uid
191
-	 * @param string $gid
192
-	 * @since 9.1.0
193
-	 */
194
-	public function userDeletedFromGroup($uid, $gid);
195
-
196
-	/**
197
-	 * Get the access list to the array of provided nodes.
198
-	 *
199
-	 * @see IManager::getAccessList() for sample docs
200
-	 *
201
-	 * @param Node[] $nodes The list of nodes to get access for
202
-	 * @param bool $currentAccess If current access is required (like for removed shares that might get revived later)
203
-	 * @return array
204
-	 * @since 12
205
-	 */
206
-	public function getAccessList($nodes, $currentAccess);
39
+    /**
40
+     * Return the identifier of this provider.
41
+     *
42
+     * @return string Containing only [a-zA-Z0-9]
43
+     * @since 9.0.0
44
+     */
45
+    public function identifier();
46
+
47
+    /**
48
+     * Create a share
49
+     *
50
+     * @param \OCP\Share\IShare $share
51
+     * @return \OCP\Share\IShare The share object
52
+     * @since 9.0.0
53
+     */
54
+    public function create(\OCP\Share\IShare $share);
55
+
56
+    /**
57
+     * Update a share
58
+     *
59
+     * @param \OCP\Share\IShare $share
60
+     * @return \OCP\Share\IShare The share object
61
+     * @since 9.0.0
62
+     */
63
+    public function update(\OCP\Share\IShare $share);
64
+
65
+    /**
66
+     * Delete a share
67
+     *
68
+     * @param \OCP\Share\IShare $share
69
+     * @since 9.0.0
70
+     */
71
+    public function delete(\OCP\Share\IShare $share);
72
+
73
+    /**
74
+     * Unshare a file from self as recipient.
75
+     * This may require special handling. If a user unshares a group
76
+     * share from their self then the original group share should still exist.
77
+     *
78
+     * @param \OCP\Share\IShare $share
79
+     * @param string $recipient UserId of the recipient
80
+     * @since 9.0.0
81
+     */
82
+    public function deleteFromSelf(\OCP\Share\IShare $share, $recipient);
83
+
84
+    /**
85
+     * Move a share as a recipient.
86
+     * This is updating the share target. Thus the mount point of the recipient.
87
+     * This may require special handling. If a user moves a group share
88
+     * the target should only be changed for them.
89
+     *
90
+     * @param \OCP\Share\IShare $share
91
+     * @param string $recipient userId of recipient
92
+     * @return \OCP\Share\IShare
93
+     * @since 9.0.0
94
+     */
95
+    public function move(\OCP\Share\IShare $share, $recipient);
96
+
97
+    /**
98
+     * Get all shares by the given user in a folder
99
+     *
100
+     * @param string $userId
101
+     * @param Folder $node
102
+     * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
103
+     * @return \OCP\Share\IShare[]
104
+     * @since 11.0.0
105
+     */
106
+    public function getSharesInFolder($userId, Folder $node, $reshares);
107
+
108
+    /**
109
+     * Get all shares by the given user
110
+     *
111
+     * @param string $userId
112
+     * @param int $shareType
113
+     * @param Node|null $node
114
+     * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
115
+     * @param int $limit The maximum number of shares to be returned, -1 for all shares
116
+     * @param int $offset
117
+     * @return \OCP\Share\IShare[]
118
+     * @since 9.0.0
119
+     */
120
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset);
121
+
122
+    /**
123
+     * Get share by id
124
+     *
125
+     * @param int $id
126
+     * @param string|null $recipientId
127
+     * @return \OCP\Share\IShare
128
+     * @throws ShareNotFoundException
129
+     * @since 9.0.0
130
+     */
131
+    public function getShareById($id, $recipientId = null);
132
+
133
+    /**
134
+     * Get shares for a given path
135
+     *
136
+     * @param Node $path
137
+     * @return \OCP\Share\IShare[]
138
+     * @since 9.0.0
139
+     */
140
+    public function getSharesByPath(Node $path);
141
+
142
+    /**
143
+     * Get shared with the given user
144
+     *
145
+     * @param string $userId get shares where this user is the recipient
146
+     * @param int $shareType
147
+     * @param Node|null $node
148
+     * @param int $limit The max number of entries returned, -1 for all
149
+     * @param int $offset
150
+     * @return \OCP\Share\IShare[]
151
+     * @since 9.0.0
152
+     */
153
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset);
154
+
155
+    /**
156
+     * Get a share by token
157
+     *
158
+     * @param string $token
159
+     * @return \OCP\Share\IShare
160
+     * @throws ShareNotFound
161
+     * @since 9.0.0
162
+     */
163
+    public function getShareByToken($token);
164
+
165
+    /**
166
+     * A user is deleted from the system
167
+     * So clean up the relevant shares.
168
+     *
169
+     * @param string $uid
170
+     * @param int $shareType
171
+     * @since 9.1.0
172
+     */
173
+    public function userDeleted($uid, $shareType);
174
+
175
+    /**
176
+     * A group is deleted from the system.
177
+     * We have to clean up all shares to this group.
178
+     * Providers not handling group shares should just return
179
+     *
180
+     * @param string $gid
181
+     * @since 9.1.0
182
+     */
183
+    public function groupDeleted($gid);
184
+
185
+    /**
186
+     * A user is deleted from a group
187
+     * We have to clean up all the related user specific group shares
188
+     * Providers not handling group shares should just return
189
+     *
190
+     * @param string $uid
191
+     * @param string $gid
192
+     * @since 9.1.0
193
+     */
194
+    public function userDeletedFromGroup($uid, $gid);
195
+
196
+    /**
197
+     * Get the access list to the array of provided nodes.
198
+     *
199
+     * @see IManager::getAccessList() for sample docs
200
+     *
201
+     * @param Node[] $nodes The list of nodes to get access for
202
+     * @param bool $currentAccess If current access is required (like for removed shares that might get revived later)
203
+     * @return array
204
+     * @since 12
205
+     */
206
+    public function getAccessList($nodes, $currentAccess);
207 207
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Capabilities.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -28,37 +28,37 @@
 block discarded – undo
28 28
 
29 29
 class Capabilities implements ICapability {
30 30
 
31
-	/** @var IURLGenerator */
32
-	private $urlGenerator;
31
+    /** @var IURLGenerator */
32
+    private $urlGenerator;
33 33
 
34
-	public function __construct(IURLGenerator $urlGenerator) {
35
-		$this->urlGenerator = $urlGenerator;
36
-	}
34
+    public function __construct(IURLGenerator $urlGenerator) {
35
+        $this->urlGenerator = $urlGenerator;
36
+    }
37 37
 
38
-	/**
39
-	 * Function an app uses to return the capabilities
40
-	 *
41
-	 * @return array Array containing the apps capabilities
42
-	 * @since 8.2.0
43
-	 */
44
-	public function getCapabilities() {
45
-		$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
46
-		$capabilities = ['ocm' =>
47
-			[
48
-				'enabled' => true,
49
-				'apiVersion' => '1.0-proposal1',
50
-				'endPoint' => substr($url, 0, strrpos($url, '/')),
51
-				'shareTypes' => [
52
-					[
53
-						'name' => 'file',
54
-						'protocols' => [
55
-							'webdav' => '/public.php/webdav/',
56
-						]
57
-					],
58
-				]
59
-			]
60
-		];
38
+    /**
39
+     * Function an app uses to return the capabilities
40
+     *
41
+     * @return array Array containing the apps capabilities
42
+     * @since 8.2.0
43
+     */
44
+    public function getCapabilities() {
45
+        $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
46
+        $capabilities = ['ocm' =>
47
+            [
48
+                'enabled' => true,
49
+                'apiVersion' => '1.0-proposal1',
50
+                'endPoint' => substr($url, 0, strrpos($url, '/')),
51
+                'shareTypes' => [
52
+                    [
53
+                        'name' => 'file',
54
+                        'protocols' => [
55
+                            'webdav' => '/public.php/webdav/',
56
+                        ]
57
+                    ],
58
+                ]
59
+            ]
60
+        ];
61 61
 
62
-		return $capabilities;
63
-	}
62
+        return $capabilities;
63
+    }
64 64
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/External/Manager.php 1 patch
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -44,512 +44,512 @@
 block discarded – undo
44 44
 use OCP\Share;
45 45
 
46 46
 class Manager {
47
-	const STORAGE = '\OCA\Files_Sharing\External\Storage';
48
-
49
-	/**
50
-	 * @var string
51
-	 */
52
-	private $uid;
53
-
54
-	/**
55
-	 * @var IDBConnection
56
-	 */
57
-	private $connection;
58
-
59
-	/**
60
-	 * @var \OC\Files\Mount\Manager
61
-	 */
62
-	private $mountManager;
63
-
64
-	/**
65
-	 * @var IStorageFactory
66
-	 */
67
-	private $storageLoader;
68
-
69
-	/**
70
-	 * @var IClientService
71
-	 */
72
-	private $clientService;
73
-
74
-	/**
75
-	 * @var IManager
76
-	 */
77
-	private $notificationManager;
78
-
79
-	/**
80
-	 * @var IDiscoveryService
81
-	 */
82
-	private $discoveryService;
83
-
84
-	/** @var ICloudFederationProviderManager */
85
-	private $cloudFederationProviderManager;
86
-
87
-	/** @var ICloudFederationFactory */
88
-	private $cloudFederationFactory;
89
-
90
-	/**
91
-	 * @param IDBConnection $connection
92
-	 * @param \OC\Files\Mount\Manager $mountManager
93
-	 * @param IStorageFactory $storageLoader
94
-	 * @param IClientService $clientService
95
-	 * @param IManager $notificationManager
96
-	 * @param IDiscoveryService $discoveryService
97
-	 * @param ICloudFederationProviderManager $cloudFederationProviderManager
98
-	 * @param ICloudFederationFactory $cloudFederationFactory
99
-	 * @param string $uid
100
-	 */
101
-	public function __construct(IDBConnection $connection,
102
-								\OC\Files\Mount\Manager $mountManager,
103
-								IStorageFactory $storageLoader,
104
-								IClientService $clientService,
105
-								IManager $notificationManager,
106
-								IDiscoveryService $discoveryService,
107
-								ICloudFederationProviderManager $cloudFederationProviderManager,
108
-								ICloudFederationFactory $cloudFederationFactory,
109
-								$uid) {
110
-		$this->connection = $connection;
111
-		$this->mountManager = $mountManager;
112
-		$this->storageLoader = $storageLoader;
113
-		$this->clientService = $clientService;
114
-		$this->uid = $uid;
115
-		$this->notificationManager = $notificationManager;
116
-		$this->discoveryService = $discoveryService;
117
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
118
-		$this->cloudFederationFactory = $cloudFederationFactory;
119
-	}
120
-
121
-	/**
122
-	 * add new server-to-server share
123
-	 *
124
-	 * @param string $remote
125
-	 * @param string $token
126
-	 * @param string $password
127
-	 * @param string $name
128
-	 * @param string $owner
129
-	 * @param boolean $accepted
130
-	 * @param string $user
131
-	 * @param int $remoteId
132
-	 * @return Mount|null
133
-	 */
134
-	public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
135
-
136
-		$user = $user ? $user : $this->uid;
137
-		$accepted = $accepted ? 1 : 0;
138
-		$name = Filesystem::normalizePath('/' . $name);
139
-
140
-		if (!$accepted) {
141
-			// To avoid conflicts with the mount point generation later,
142
-			// we only use a temporary mount point name here. The real
143
-			// mount point name will be generated when accepting the share,
144
-			// using the original share item name.
145
-			$tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}';
146
-			$mountPoint = $tmpMountPointName;
147
-			$hash = md5($tmpMountPointName);
148
-			$data = [
149
-				'remote'		=> $remote,
150
-				'share_token'	=> $token,
151
-				'password'		=> $password,
152
-				'name'			=> $name,
153
-				'owner'			=> $owner,
154
-				'user'			=> $user,
155
-				'mountpoint'	=> $mountPoint,
156
-				'mountpoint_hash'	=> $hash,
157
-				'accepted'		=> $accepted,
158
-				'remote_id'		=> $remoteId,
159
-			];
160
-
161
-			$i = 1;
162
-			while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) {
163
-				// The external share already exists for the user
164
-				$data['mountpoint'] = $tmpMountPointName . '-' . $i;
165
-				$data['mountpoint_hash'] = md5($data['mountpoint']);
166
-				$i++;
167
-			}
168
-			return null;
169
-		}
170
-
171
-		$mountPoint = Files::buildNotExistingFileName('/', $name);
172
-		$mountPoint = Filesystem::normalizePath('/' . $mountPoint);
173
-		$hash = md5($mountPoint);
174
-
175
-		$query = $this->connection->prepare('
47
+    const STORAGE = '\OCA\Files_Sharing\External\Storage';
48
+
49
+    /**
50
+     * @var string
51
+     */
52
+    private $uid;
53
+
54
+    /**
55
+     * @var IDBConnection
56
+     */
57
+    private $connection;
58
+
59
+    /**
60
+     * @var \OC\Files\Mount\Manager
61
+     */
62
+    private $mountManager;
63
+
64
+    /**
65
+     * @var IStorageFactory
66
+     */
67
+    private $storageLoader;
68
+
69
+    /**
70
+     * @var IClientService
71
+     */
72
+    private $clientService;
73
+
74
+    /**
75
+     * @var IManager
76
+     */
77
+    private $notificationManager;
78
+
79
+    /**
80
+     * @var IDiscoveryService
81
+     */
82
+    private $discoveryService;
83
+
84
+    /** @var ICloudFederationProviderManager */
85
+    private $cloudFederationProviderManager;
86
+
87
+    /** @var ICloudFederationFactory */
88
+    private $cloudFederationFactory;
89
+
90
+    /**
91
+     * @param IDBConnection $connection
92
+     * @param \OC\Files\Mount\Manager $mountManager
93
+     * @param IStorageFactory $storageLoader
94
+     * @param IClientService $clientService
95
+     * @param IManager $notificationManager
96
+     * @param IDiscoveryService $discoveryService
97
+     * @param ICloudFederationProviderManager $cloudFederationProviderManager
98
+     * @param ICloudFederationFactory $cloudFederationFactory
99
+     * @param string $uid
100
+     */
101
+    public function __construct(IDBConnection $connection,
102
+                                \OC\Files\Mount\Manager $mountManager,
103
+                                IStorageFactory $storageLoader,
104
+                                IClientService $clientService,
105
+                                IManager $notificationManager,
106
+                                IDiscoveryService $discoveryService,
107
+                                ICloudFederationProviderManager $cloudFederationProviderManager,
108
+                                ICloudFederationFactory $cloudFederationFactory,
109
+                                $uid) {
110
+        $this->connection = $connection;
111
+        $this->mountManager = $mountManager;
112
+        $this->storageLoader = $storageLoader;
113
+        $this->clientService = $clientService;
114
+        $this->uid = $uid;
115
+        $this->notificationManager = $notificationManager;
116
+        $this->discoveryService = $discoveryService;
117
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
118
+        $this->cloudFederationFactory = $cloudFederationFactory;
119
+    }
120
+
121
+    /**
122
+     * add new server-to-server share
123
+     *
124
+     * @param string $remote
125
+     * @param string $token
126
+     * @param string $password
127
+     * @param string $name
128
+     * @param string $owner
129
+     * @param boolean $accepted
130
+     * @param string $user
131
+     * @param int $remoteId
132
+     * @return Mount|null
133
+     */
134
+    public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
135
+
136
+        $user = $user ? $user : $this->uid;
137
+        $accepted = $accepted ? 1 : 0;
138
+        $name = Filesystem::normalizePath('/' . $name);
139
+
140
+        if (!$accepted) {
141
+            // To avoid conflicts with the mount point generation later,
142
+            // we only use a temporary mount point name here. The real
143
+            // mount point name will be generated when accepting the share,
144
+            // using the original share item name.
145
+            $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}';
146
+            $mountPoint = $tmpMountPointName;
147
+            $hash = md5($tmpMountPointName);
148
+            $data = [
149
+                'remote'		=> $remote,
150
+                'share_token'	=> $token,
151
+                'password'		=> $password,
152
+                'name'			=> $name,
153
+                'owner'			=> $owner,
154
+                'user'			=> $user,
155
+                'mountpoint'	=> $mountPoint,
156
+                'mountpoint_hash'	=> $hash,
157
+                'accepted'		=> $accepted,
158
+                'remote_id'		=> $remoteId,
159
+            ];
160
+
161
+            $i = 1;
162
+            while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) {
163
+                // The external share already exists for the user
164
+                $data['mountpoint'] = $tmpMountPointName . '-' . $i;
165
+                $data['mountpoint_hash'] = md5($data['mountpoint']);
166
+                $i++;
167
+            }
168
+            return null;
169
+        }
170
+
171
+        $mountPoint = Files::buildNotExistingFileName('/', $name);
172
+        $mountPoint = Filesystem::normalizePath('/' . $mountPoint);
173
+        $hash = md5($mountPoint);
174
+
175
+        $query = $this->connection->prepare('
176 176
 				INSERT INTO `*PREFIX*share_external`
177 177
 					(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
178 178
 				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
179 179
 			');
180
-		$query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
181
-
182
-		$options = array(
183
-			'remote'	=> $remote,
184
-			'token'		=> $token,
185
-			'password'	=> $password,
186
-			'mountpoint'	=> $mountPoint,
187
-			'owner'		=> $owner
188
-		);
189
-		return $this->mountShare($options);
190
-	}
191
-
192
-	/**
193
-	 * get share
194
-	 *
195
-	 * @param int $id share id
196
-	 * @return mixed share of false
197
-	 */
198
-	public function getShare($id) {
199
-		$getShare = $this->connection->prepare('
180
+        $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
181
+
182
+        $options = array(
183
+            'remote'	=> $remote,
184
+            'token'		=> $token,
185
+            'password'	=> $password,
186
+            'mountpoint'	=> $mountPoint,
187
+            'owner'		=> $owner
188
+        );
189
+        return $this->mountShare($options);
190
+    }
191
+
192
+    /**
193
+     * get share
194
+     *
195
+     * @param int $id share id
196
+     * @return mixed share of false
197
+     */
198
+    public function getShare($id) {
199
+        $getShare = $this->connection->prepare('
200 200
 			SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
201 201
 			FROM  `*PREFIX*share_external`
202 202
 			WHERE `id` = ? AND `user` = ?');
203
-		$result = $getShare->execute(array($id, $this->uid));
204
-
205
-		return $result ? $getShare->fetch() : false;
206
-	}
207
-
208
-	/**
209
-	 * accept server-to-server share
210
-	 *
211
-	 * @param int $id
212
-	 * @return bool True if the share could be accepted, false otherwise
213
-	 */
214
-	public function acceptShare($id) {
215
-
216
-		$share = $this->getShare($id);
217
-		$result = false;
218
-
219
-		if ($share) {
220
-			\OC_Util::setupFS($this->uid);
221
-			$shareFolder = Helper::getShareFolder();
222
-			$mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']);
223
-			$mountPoint = Filesystem::normalizePath($mountPoint);
224
-			$hash = md5($mountPoint);
225
-
226
-			$acceptShare = $this->connection->prepare('
203
+        $result = $getShare->execute(array($id, $this->uid));
204
+
205
+        return $result ? $getShare->fetch() : false;
206
+    }
207
+
208
+    /**
209
+     * accept server-to-server share
210
+     *
211
+     * @param int $id
212
+     * @return bool True if the share could be accepted, false otherwise
213
+     */
214
+    public function acceptShare($id) {
215
+
216
+        $share = $this->getShare($id);
217
+        $result = false;
218
+
219
+        if ($share) {
220
+            \OC_Util::setupFS($this->uid);
221
+            $shareFolder = Helper::getShareFolder();
222
+            $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']);
223
+            $mountPoint = Filesystem::normalizePath($mountPoint);
224
+            $hash = md5($mountPoint);
225
+
226
+            $acceptShare = $this->connection->prepare('
227 227
 				UPDATE `*PREFIX*share_external`
228 228
 				SET `accepted` = ?,
229 229
 					`mountpoint` = ?,
230 230
 					`mountpoint_hash` = ?
231 231
 				WHERE `id` = ? AND `user` = ?');
232
-			$updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
233
-			if ($updated === true) {
234
-				$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
235
-				\OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]);
236
-				$result = true;
237
-			}
238
-		}
239
-
240
-		// Make sure the user has no notification for something that does not exist anymore.
241
-		$this->processNotification($id);
242
-
243
-		return $result;
244
-	}
245
-
246
-	/**
247
-	 * decline server-to-server share
248
-	 *
249
-	 * @param int $id
250
-	 * @return bool True if the share could be declined, false otherwise
251
-	 */
252
-	public function declineShare($id) {
253
-
254
-		$share = $this->getShare($id);
255
-
256
-		if ($share) {
257
-			$removeShare = $this->connection->prepare('
232
+            $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid));
233
+            if ($updated === true) {
234
+                $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
235
+                \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]);
236
+                $result = true;
237
+            }
238
+        }
239
+
240
+        // Make sure the user has no notification for something that does not exist anymore.
241
+        $this->processNotification($id);
242
+
243
+        return $result;
244
+    }
245
+
246
+    /**
247
+     * decline server-to-server share
248
+     *
249
+     * @param int $id
250
+     * @return bool True if the share could be declined, false otherwise
251
+     */
252
+    public function declineShare($id) {
253
+
254
+        $share = $this->getShare($id);
255
+
256
+        if ($share) {
257
+            $removeShare = $this->connection->prepare('
258 258
 				DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?');
259
-			$removeShare->execute(array($id, $this->uid));
260
-			$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
261
-
262
-			$this->processNotification($id);
263
-			return true;
264
-		}
265
-
266
-		return false;
267
-	}
268
-
269
-	/**
270
-	 * @param int $remoteShare
271
-	 */
272
-	public function processNotification($remoteShare) {
273
-		$filter = $this->notificationManager->createNotification();
274
-		$filter->setApp('files_sharing')
275
-			->setUser($this->uid)
276
-			->setObject('remote_share', (int) $remoteShare);
277
-		$this->notificationManager->markProcessed($filter);
278
-	}
279
-
280
-	/**
281
-	 * inform remote server whether server-to-server share was accepted/declined
282
-	 *
283
-	 * @param string $remote
284
-	 * @param string $token
285
-	 * @param int $remoteId Share id on the remote host
286
-	 * @param string $feedback
287
-	 * @return boolean
288
-	 */
289
-	private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {
290
-
291
-		$result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback);
292
-
293
-		if($result === true) {
294
-			return true;
295
-		}
296
-
297
-		$federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING');
298
-		$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
299
-
300
-		$url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
301
-		$fields = array('token' => $token);
302
-
303
-		$client = $this->clientService->newClient();
304
-
305
-		try {
306
-			$response = $client->post(
307
-				$url,
308
-				[
309
-					'body' => $fields,
310
-					'connect_timeout' => 10,
311
-				]
312
-			);
313
-		} catch (\Exception $e) {
314
-			return false;
315
-		}
316
-
317
-		$status = json_decode($response->getBody(), true);
318
-
319
-		return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
320
-	}
321
-
322
-	/**
323
-	 * try send accept message to ocm end-point
324
-	 *
325
-	 * @param string $remoteDomain
326
-	 * @param string $token
327
-	 * @param $remoteId id of the share
328
-	 * @param string $feedback
329
-	 * @return bool
330
-	 */
331
-	protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) {
332
-		switch ($feedback) {
333
-			case 'accept':
334
-				$notification = $this->cloudFederationFactory->getCloudFederationNotification();
335
-				$notification->setMessage(
336
-					'SHARE_ACCEPTED',
337
-					'file',
338
-					$remoteId,
339
-					[
340
-						'sharedSecret' => $token,
341
-						'message' => 'Recipient accept the share'
342
-					]
343
-
344
-				);
345
-				return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
346
-			case 'decline':
347
-				$notification = $this->cloudFederationFactory->getCloudFederationNotification();
348
-				$notification->setMessage(
349
-					'SHARE_DECLINED',
350
-					'file',
351
-					$remoteId,
352
-					[
353
-						'sharedSecret' => $token,
354
-						'message' => 'Recipient declined the share'
355
-					]
356
-
357
-				);
358
-				return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
359
-		}
360
-
361
-		return false;
362
-
363
-	}
364
-
365
-
366
-	/**
367
-	 * remove '/user/files' from the path and trailing slashes
368
-	 *
369
-	 * @param string $path
370
-	 * @return string
371
-	 */
372
-	protected function stripPath($path) {
373
-		$prefix = '/' . $this->uid . '/files';
374
-		return rtrim(substr($path, strlen($prefix)), '/');
375
-	}
376
-
377
-	public function getMount($data) {
378
-		$data['manager'] = $this;
379
-		$mountPoint = '/' . $this->uid . '/files' . $data['mountpoint'];
380
-		$data['mountpoint'] = $mountPoint;
381
-		$data['certificateManager'] = \OC::$server->getCertificateManager($this->uid);
382
-		return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
383
-	}
384
-
385
-	/**
386
-	 * @param array $data
387
-	 * @return Mount
388
-	 */
389
-	protected function mountShare($data) {
390
-		$mount = $this->getMount($data);
391
-		$this->mountManager->addMount($mount);
392
-		return $mount;
393
-	}
394
-
395
-	/**
396
-	 * @return \OC\Files\Mount\Manager
397
-	 */
398
-	public function getMountManager() {
399
-		return $this->mountManager;
400
-	}
401
-
402
-	/**
403
-	 * @param string $source
404
-	 * @param string $target
405
-	 * @return bool
406
-	 */
407
-	public function setMountPoint($source, $target) {
408
-		$source = $this->stripPath($source);
409
-		$target = $this->stripPath($target);
410
-		$sourceHash = md5($source);
411
-		$targetHash = md5($target);
412
-
413
-		$query = $this->connection->prepare('
259
+            $removeShare->execute(array($id, $this->uid));
260
+            $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
261
+
262
+            $this->processNotification($id);
263
+            return true;
264
+        }
265
+
266
+        return false;
267
+    }
268
+
269
+    /**
270
+     * @param int $remoteShare
271
+     */
272
+    public function processNotification($remoteShare) {
273
+        $filter = $this->notificationManager->createNotification();
274
+        $filter->setApp('files_sharing')
275
+            ->setUser($this->uid)
276
+            ->setObject('remote_share', (int) $remoteShare);
277
+        $this->notificationManager->markProcessed($filter);
278
+    }
279
+
280
+    /**
281
+     * inform remote server whether server-to-server share was accepted/declined
282
+     *
283
+     * @param string $remote
284
+     * @param string $token
285
+     * @param int $remoteId Share id on the remote host
286
+     * @param string $feedback
287
+     * @return boolean
288
+     */
289
+    private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {
290
+
291
+        $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback);
292
+
293
+        if($result === true) {
294
+            return true;
295
+        }
296
+
297
+        $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING');
298
+        $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
299
+
300
+        $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
301
+        $fields = array('token' => $token);
302
+
303
+        $client = $this->clientService->newClient();
304
+
305
+        try {
306
+            $response = $client->post(
307
+                $url,
308
+                [
309
+                    'body' => $fields,
310
+                    'connect_timeout' => 10,
311
+                ]
312
+            );
313
+        } catch (\Exception $e) {
314
+            return false;
315
+        }
316
+
317
+        $status = json_decode($response->getBody(), true);
318
+
319
+        return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
320
+    }
321
+
322
+    /**
323
+     * try send accept message to ocm end-point
324
+     *
325
+     * @param string $remoteDomain
326
+     * @param string $token
327
+     * @param $remoteId id of the share
328
+     * @param string $feedback
329
+     * @return bool
330
+     */
331
+    protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) {
332
+        switch ($feedback) {
333
+            case 'accept':
334
+                $notification = $this->cloudFederationFactory->getCloudFederationNotification();
335
+                $notification->setMessage(
336
+                    'SHARE_ACCEPTED',
337
+                    'file',
338
+                    $remoteId,
339
+                    [
340
+                        'sharedSecret' => $token,
341
+                        'message' => 'Recipient accept the share'
342
+                    ]
343
+
344
+                );
345
+                return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
346
+            case 'decline':
347
+                $notification = $this->cloudFederationFactory->getCloudFederationNotification();
348
+                $notification->setMessage(
349
+                    'SHARE_DECLINED',
350
+                    'file',
351
+                    $remoteId,
352
+                    [
353
+                        'sharedSecret' => $token,
354
+                        'message' => 'Recipient declined the share'
355
+                    ]
356
+
357
+                );
358
+                return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification);
359
+        }
360
+
361
+        return false;
362
+
363
+    }
364
+
365
+
366
+    /**
367
+     * remove '/user/files' from the path and trailing slashes
368
+     *
369
+     * @param string $path
370
+     * @return string
371
+     */
372
+    protected function stripPath($path) {
373
+        $prefix = '/' . $this->uid . '/files';
374
+        return rtrim(substr($path, strlen($prefix)), '/');
375
+    }
376
+
377
+    public function getMount($data) {
378
+        $data['manager'] = $this;
379
+        $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint'];
380
+        $data['mountpoint'] = $mountPoint;
381
+        $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid);
382
+        return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
383
+    }
384
+
385
+    /**
386
+     * @param array $data
387
+     * @return Mount
388
+     */
389
+    protected function mountShare($data) {
390
+        $mount = $this->getMount($data);
391
+        $this->mountManager->addMount($mount);
392
+        return $mount;
393
+    }
394
+
395
+    /**
396
+     * @return \OC\Files\Mount\Manager
397
+     */
398
+    public function getMountManager() {
399
+        return $this->mountManager;
400
+    }
401
+
402
+    /**
403
+     * @param string $source
404
+     * @param string $target
405
+     * @return bool
406
+     */
407
+    public function setMountPoint($source, $target) {
408
+        $source = $this->stripPath($source);
409
+        $target = $this->stripPath($target);
410
+        $sourceHash = md5($source);
411
+        $targetHash = md5($target);
412
+
413
+        $query = $this->connection->prepare('
414 414
 			UPDATE `*PREFIX*share_external`
415 415
 			SET `mountpoint` = ?, `mountpoint_hash` = ?
416 416
 			WHERE `mountpoint_hash` = ?
417 417
 			AND `user` = ?
418 418
 		');
419
-		$result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid));
419
+        $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid));
420 420
 
421
-		return $result;
422
-	}
421
+        return $result;
422
+    }
423 423
 
424
-	public function removeShare($mountPoint) {
424
+    public function removeShare($mountPoint) {
425 425
 
426
-		$mountPointObj = $this->mountManager->find($mountPoint);
427
-		$id = $mountPointObj->getStorage()->getCache()->getId('');
426
+        $mountPointObj = $this->mountManager->find($mountPoint);
427
+        $id = $mountPointObj->getStorage()->getCache()->getId('');
428 428
 
429
-		$mountPoint = $this->stripPath($mountPoint);
430
-		$hash = md5($mountPoint);
429
+        $mountPoint = $this->stripPath($mountPoint);
430
+        $hash = md5($mountPoint);
431 431
 
432
-		$getShare = $this->connection->prepare('
432
+        $getShare = $this->connection->prepare('
433 433
 			SELECT `remote`, `share_token`, `remote_id`
434 434
 			FROM  `*PREFIX*share_external`
435 435
 			WHERE `mountpoint_hash` = ? AND `user` = ?');
436
-		$result = $getShare->execute(array($hash, $this->uid));
437
-
438
-		if ($result) {
439
-			try {
440
-				$share = $getShare->fetch();
441
-				$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
442
-			} catch (\Exception $e) {
443
-				// if we fail to notify the remote (probably cause the remote is down)
444
-				// we still want the share to be gone to prevent undeletable remotes
445
-			}
446
-		}
447
-		$getShare->closeCursor();
448
-
449
-		$query = $this->connection->prepare('
436
+        $result = $getShare->execute(array($hash, $this->uid));
437
+
438
+        if ($result) {
439
+            try {
440
+                $share = $getShare->fetch();
441
+                $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
442
+            } catch (\Exception $e) {
443
+                // if we fail to notify the remote (probably cause the remote is down)
444
+                // we still want the share to be gone to prevent undeletable remotes
445
+            }
446
+        }
447
+        $getShare->closeCursor();
448
+
449
+        $query = $this->connection->prepare('
450 450
 			DELETE FROM `*PREFIX*share_external`
451 451
 			WHERE `mountpoint_hash` = ?
452 452
 			AND `user` = ?
453 453
 		');
454
-		$result = (bool)$query->execute(array($hash, $this->uid));
455
-
456
-		if($result) {
457
-			$this->removeReShares($id);
458
-		}
459
-
460
-		return $result;
461
-	}
462
-
463
-	/**
464
-	 * remove re-shares from share table and mapping in the federated_reshares table
465
-	 *
466
-	 * @param $mountPointId
467
-	 */
468
-	protected function removeReShares($mountPointId) {
469
-		$selectQuery = $this->connection->getQueryBuilder();
470
-		$query = $this->connection->getQueryBuilder();
471
-		$selectQuery->select('id')->from('share')
472
-			->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId)));
473
-		$select = $selectQuery->getSQL();
474
-
475
-
476
-		$query->delete('federated_reshares')
477
-			->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')')));
478
-		$query->execute();
479
-
480
-		$deleteReShares = $this->connection->getQueryBuilder();
481
-		$deleteReShares->delete('share')
482
-			->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId)));
483
-		$deleteReShares->execute();
484
-	}
485
-
486
-	/**
487
-	 * remove all shares for user $uid if the user was deleted
488
-	 *
489
-	 * @param string $uid
490
-	 * @return bool
491
-	 */
492
-	public function removeUserShares($uid) {
493
-		$getShare = $this->connection->prepare('
454
+        $result = (bool)$query->execute(array($hash, $this->uid));
455
+
456
+        if($result) {
457
+            $this->removeReShares($id);
458
+        }
459
+
460
+        return $result;
461
+    }
462
+
463
+    /**
464
+     * remove re-shares from share table and mapping in the federated_reshares table
465
+     *
466
+     * @param $mountPointId
467
+     */
468
+    protected function removeReShares($mountPointId) {
469
+        $selectQuery = $this->connection->getQueryBuilder();
470
+        $query = $this->connection->getQueryBuilder();
471
+        $selectQuery->select('id')->from('share')
472
+            ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId)));
473
+        $select = $selectQuery->getSQL();
474
+
475
+
476
+        $query->delete('federated_reshares')
477
+            ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')')));
478
+        $query->execute();
479
+
480
+        $deleteReShares = $this->connection->getQueryBuilder();
481
+        $deleteReShares->delete('share')
482
+            ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId)));
483
+        $deleteReShares->execute();
484
+    }
485
+
486
+    /**
487
+     * remove all shares for user $uid if the user was deleted
488
+     *
489
+     * @param string $uid
490
+     * @return bool
491
+     */
492
+    public function removeUserShares($uid) {
493
+        $getShare = $this->connection->prepare('
494 494
 			SELECT `remote`, `share_token`, `remote_id`
495 495
 			FROM  `*PREFIX*share_external`
496 496
 			WHERE `user` = ?');
497
-		$result = $getShare->execute(array($uid));
497
+        $result = $getShare->execute(array($uid));
498 498
 
499
-		if ($result) {
500
-			$shares = $getShare->fetchAll();
501
-			foreach($shares as $share) {
502
-				$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
503
-			}
504
-		}
499
+        if ($result) {
500
+            $shares = $getShare->fetchAll();
501
+            foreach($shares as $share) {
502
+                $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
503
+            }
504
+        }
505 505
 
506
-		$query = $this->connection->prepare('
506
+        $query = $this->connection->prepare('
507 507
 			DELETE FROM `*PREFIX*share_external`
508 508
 			WHERE `user` = ?
509 509
 		');
510
-		return (bool)$query->execute(array($uid));
511
-	}
512
-
513
-	/**
514
-	 * return a list of shares which are not yet accepted by the user
515
-	 *
516
-	 * @return array list of open server-to-server shares
517
-	 */
518
-	public function getOpenShares() {
519
-		return $this->getShares(false);
520
-	}
521
-
522
-	/**
523
-	 * return a list of shares which are accepted by the user
524
-	 *
525
-	 * @return array list of accepted server-to-server shares
526
-	 */
527
-	public function getAcceptedShares() {
528
-		return $this->getShares(true);
529
-	}
530
-
531
-	/**
532
-	 * return a list of shares for the user
533
-	 *
534
-	 * @param bool|null $accepted True for accepted only,
535
-	 *                            false for not accepted,
536
-	 *                            null for all shares of the user
537
-	 * @return array list of open server-to-server shares
538
-	 */
539
-	private function getShares($accepted) {
540
-		$query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
510
+        return (bool)$query->execute(array($uid));
511
+    }
512
+
513
+    /**
514
+     * return a list of shares which are not yet accepted by the user
515
+     *
516
+     * @return array list of open server-to-server shares
517
+     */
518
+    public function getOpenShares() {
519
+        return $this->getShares(false);
520
+    }
521
+
522
+    /**
523
+     * return a list of shares which are accepted by the user
524
+     *
525
+     * @return array list of accepted server-to-server shares
526
+     */
527
+    public function getAcceptedShares() {
528
+        return $this->getShares(true);
529
+    }
530
+
531
+    /**
532
+     * return a list of shares for the user
533
+     *
534
+     * @param bool|null $accepted True for accepted only,
535
+     *                            false for not accepted,
536
+     *                            null for all shares of the user
537
+     * @return array list of open server-to-server shares
538
+     */
539
+    private function getShares($accepted) {
540
+        $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`
541 541
 		          FROM `*PREFIX*share_external` 
542 542
 				  WHERE `user` = ?';
543
-		$parameters = [$this->uid];
544
-		if (!is_null($accepted)) {
545
-			$query .= ' AND `accepted` = ?';
546
-			$parameters[] = (int) $accepted;
547
-		}
548
-		$query .= ' ORDER BY `id` ASC';
549
-
550
-		$shares = $this->connection->prepare($query);
551
-		$result = $shares->execute($parameters);
552
-
553
-		return $result ? $shares->fetchAll() : [];
554
-	}
543
+        $parameters = [$this->uid];
544
+        if (!is_null($accepted)) {
545
+            $query .= ' AND `accepted` = ?';
546
+            $parameters[] = (int) $accepted;
547
+        }
548
+        $query .= ' ORDER BY `id` ASC';
549
+
550
+        $shares = $this->connection->prepare($query);
551
+        $result = $shares->execute($parameters);
552
+
553
+        return $result ? $shares->fetchAll() : [];
554
+    }
555 555
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationProviderManager.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -42,191 +42,191 @@
 block discarded – undo
42 42
  */
43 43
 class CloudFederationProviderManager implements ICloudFederationProviderManager {
44 44
 
45
-	/** @var array list of available cloud federation providers */
46
-	private $cloudFederationProvider;
47
-
48
-	/** @var IAppManager */
49
-	private $appManager;
50
-
51
-	/** @var IClientService */
52
-	private $httpClientService;
53
-
54
-	/** @var ICloudIdManager */
55
-	private $cloudIdManager;
56
-
57
-	/** @var ILogger */
58
-	private $logger;
59
-
60
-	private $supportedAPIVersion = '1.0-proposal1';
61
-
62
-	/**
63
-	 * CloudFederationProviderManager constructor.
64
-	 *
65
-	 * @param IAppManager $appManager
66
-	 * @param IClientService $httpClientService
67
-	 * @param ICloudIdManager $cloudIdManager
68
-	 * @param ILogger $logger
69
-	 */
70
-	public function __construct(IAppManager $appManager,
71
-								IClientService $httpClientService,
72
-								ICloudIdManager $cloudIdManager,
73
-								ILogger $logger) {
74
-		$this->cloudFederationProvider= [];
75
-		$this->appManager = $appManager;
76
-		$this->httpClientService = $httpClientService;
77
-		$this->cloudIdManager = $cloudIdManager;
78
-		$this->logger = $logger;
79
-	}
80
-
81
-
82
-	/**
83
-	 * Registers an callback function which must return an cloud federation provider
84
-	 *
85
-	 * @param string $shareType which share type does the provider handles
86
-	 * @param string $displayName user facing name of the federated share provider
87
-	 * @param callable $callback
88
-	 */
89
-	public function addCloudFederationProvider($shareType, $displayName, callable $callback) {
90
-		\OC::$server->getRemoteApiFactory();
91
-
92
-		$this->cloudFederationProvider[$shareType] = [
93
-			'shareType' => $shareType,
94
-			'displayName' => $displayName,
95
-			'callback' => $callback,
96
-		];
97
-
98
-	}
99
-
100
-	/**
101
-	 * remove cloud federation provider
102
-	 *
103
-	 * @param string $providerId
104
-	 */
105
-	public function removeCloudFederationProvider($providerId) {
106
-		unset($this->cloudFederationProvider[$providerId]);
107
-	}
108
-
109
-	/**
110
-	 * get a list of all cloudFederationProviders
111
-	 *
112
-	 * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
113
-	 */
114
-	public function getAllCloudFederationProviders() {
115
-		return $this->cloudFederationProvider;
116
-	}
117
-
118
-	/**
119
-	 * get a specific cloud federation provider
120
-	 *
121
-	 * @param string $shareType
122
-	 * @return ICloudFederationProvider
123
-	 * @throws ProviderDoesNotExistsException
124
-	 */
125
-	public function getCloudFederationProvider($shareType) {
126
-		if (isset($this->cloudFederationProvider[$shareType])) {
127
-			return call_user_func($this->cloudFederationProvider[$shareType]['callback']);
128
-		} else {
129
-			throw new ProviderDoesNotExistsException($shareType);
130
-		}
131
-	}
132
-
133
-	public function sendShare(ICloudFederationShare $share) {
134
-		$cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
135
-		$ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
136
-
137
-		if (empty($ocmEndPoint)) {
138
-			return false;
139
-		}
140
-
141
-		$client = $this->httpClientService->newClient();
142
-		try {
143
-			$response = $client->post($ocmEndPoint . '/shares', [
144
-				'body' => $share->getShare(),
145
-				'timeout' => 10,
146
-				'connect_timeout' => 10,
147
-			]);
148
-
149
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
150
-				return true;
151
-			}
152
-
153
-		} catch (\Exception $e) {
154
-			// if flat re-sharing is not supported by the remote server
155
-			// we re-throw the exception and fall back to the old behaviour.
156
-			// (flat re-shares has been introduced in Nextcloud 9.1)
157
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
158
-				throw $e;
159
-			}
160
-		}
161
-
162
-		return false;
163
-
164
-	}
165
-
166
-	/**
167
-	 * @param string $url
168
-	 * @param ICloudFederationNotification $notification
169
-	 * @return mixed
170
-	 */
171
-	public function sendNotification($url, ICloudFederationNotification $notification) {
172
-		$ocmEndPoint = $this->getOCMEndPoint($url);
173
-
174
-		if (empty($ocmEndPoint)) {
175
-			return false;
176
-		}
177
-
178
-		$client = $this->httpClientService->newClient();
179
-		try {
180
-			$response = $client->post($ocmEndPoint . '/notifications', [
181
-				'body' => $notification->getMessage(),
182
-				'timeout' => 10,
183
-				'connect_timeout' => 10,
184
-			]);
185
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
186
-				$result = json_decode($response->getBody(), true);
187
-				return (is_array($result)) ? $result : [];
188
-			}
189
-		} catch (\Exception $e) {
190
-			// log the error and return false
191
-			$this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
192
-		}
193
-
194
-		return false;
195
-	}
196
-
197
-	/**
198
-	 * check if the new cloud federation API is ready to be used
199
-	 *
200
-	 * @return bool
201
-	 */
202
-	public function isReady() {
203
-		return $this->appManager->isEnabledForUser('cloud_federation_api', false);
204
-	}
205
-	/**
206
-	 * check if server supports the new OCM api and ask for the correct end-point
207
-	 *
208
-	 * @param string $url full base URL of the cloud server
209
-	 * @return string
210
-	 */
211
-	protected function getOCMEndPoint($url) {
212
-		$client = $this->httpClientService->newClient();
213
-		try {
214
-			$response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
215
-		} catch (\Exception $e) {
216
-			return '';
217
-		}
218
-
219
-		$result = $response->getBody();
220
-		$result = json_decode($result, true);
221
-
222
-		$supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
223
-
224
-		if (isset($result['endPoint']) && $supportedVersion) {
225
-			return $result['endPoint'];
226
-		}
227
-
228
-		return '';
229
-	}
45
+    /** @var array list of available cloud federation providers */
46
+    private $cloudFederationProvider;
47
+
48
+    /** @var IAppManager */
49
+    private $appManager;
50
+
51
+    /** @var IClientService */
52
+    private $httpClientService;
53
+
54
+    /** @var ICloudIdManager */
55
+    private $cloudIdManager;
56
+
57
+    /** @var ILogger */
58
+    private $logger;
59
+
60
+    private $supportedAPIVersion = '1.0-proposal1';
61
+
62
+    /**
63
+     * CloudFederationProviderManager constructor.
64
+     *
65
+     * @param IAppManager $appManager
66
+     * @param IClientService $httpClientService
67
+     * @param ICloudIdManager $cloudIdManager
68
+     * @param ILogger $logger
69
+     */
70
+    public function __construct(IAppManager $appManager,
71
+                                IClientService $httpClientService,
72
+                                ICloudIdManager $cloudIdManager,
73
+                                ILogger $logger) {
74
+        $this->cloudFederationProvider= [];
75
+        $this->appManager = $appManager;
76
+        $this->httpClientService = $httpClientService;
77
+        $this->cloudIdManager = $cloudIdManager;
78
+        $this->logger = $logger;
79
+    }
80
+
81
+
82
+    /**
83
+     * Registers an callback function which must return an cloud federation provider
84
+     *
85
+     * @param string $shareType which share type does the provider handles
86
+     * @param string $displayName user facing name of the federated share provider
87
+     * @param callable $callback
88
+     */
89
+    public function addCloudFederationProvider($shareType, $displayName, callable $callback) {
90
+        \OC::$server->getRemoteApiFactory();
91
+
92
+        $this->cloudFederationProvider[$shareType] = [
93
+            'shareType' => $shareType,
94
+            'displayName' => $displayName,
95
+            'callback' => $callback,
96
+        ];
97
+
98
+    }
99
+
100
+    /**
101
+     * remove cloud federation provider
102
+     *
103
+     * @param string $providerId
104
+     */
105
+    public function removeCloudFederationProvider($providerId) {
106
+        unset($this->cloudFederationProvider[$providerId]);
107
+    }
108
+
109
+    /**
110
+     * get a list of all cloudFederationProviders
111
+     *
112
+     * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
113
+     */
114
+    public function getAllCloudFederationProviders() {
115
+        return $this->cloudFederationProvider;
116
+    }
117
+
118
+    /**
119
+     * get a specific cloud federation provider
120
+     *
121
+     * @param string $shareType
122
+     * @return ICloudFederationProvider
123
+     * @throws ProviderDoesNotExistsException
124
+     */
125
+    public function getCloudFederationProvider($shareType) {
126
+        if (isset($this->cloudFederationProvider[$shareType])) {
127
+            return call_user_func($this->cloudFederationProvider[$shareType]['callback']);
128
+        } else {
129
+            throw new ProviderDoesNotExistsException($shareType);
130
+        }
131
+    }
132
+
133
+    public function sendShare(ICloudFederationShare $share) {
134
+        $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
135
+        $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
136
+
137
+        if (empty($ocmEndPoint)) {
138
+            return false;
139
+        }
140
+
141
+        $client = $this->httpClientService->newClient();
142
+        try {
143
+            $response = $client->post($ocmEndPoint . '/shares', [
144
+                'body' => $share->getShare(),
145
+                'timeout' => 10,
146
+                'connect_timeout' => 10,
147
+            ]);
148
+
149
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
150
+                return true;
151
+            }
152
+
153
+        } catch (\Exception $e) {
154
+            // if flat re-sharing is not supported by the remote server
155
+            // we re-throw the exception and fall back to the old behaviour.
156
+            // (flat re-shares has been introduced in Nextcloud 9.1)
157
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
158
+                throw $e;
159
+            }
160
+        }
161
+
162
+        return false;
163
+
164
+    }
165
+
166
+    /**
167
+     * @param string $url
168
+     * @param ICloudFederationNotification $notification
169
+     * @return mixed
170
+     */
171
+    public function sendNotification($url, ICloudFederationNotification $notification) {
172
+        $ocmEndPoint = $this->getOCMEndPoint($url);
173
+
174
+        if (empty($ocmEndPoint)) {
175
+            return false;
176
+        }
177
+
178
+        $client = $this->httpClientService->newClient();
179
+        try {
180
+            $response = $client->post($ocmEndPoint . '/notifications', [
181
+                'body' => $notification->getMessage(),
182
+                'timeout' => 10,
183
+                'connect_timeout' => 10,
184
+            ]);
185
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
186
+                $result = json_decode($response->getBody(), true);
187
+                return (is_array($result)) ? $result : [];
188
+            }
189
+        } catch (\Exception $e) {
190
+            // log the error and return false
191
+            $this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
192
+        }
193
+
194
+        return false;
195
+    }
196
+
197
+    /**
198
+     * check if the new cloud federation API is ready to be used
199
+     *
200
+     * @return bool
201
+     */
202
+    public function isReady() {
203
+        return $this->appManager->isEnabledForUser('cloud_federation_api', false);
204
+    }
205
+    /**
206
+     * check if server supports the new OCM api and ask for the correct end-point
207
+     *
208
+     * @param string $url full base URL of the cloud server
209
+     * @return string
210
+     */
211
+    protected function getOCMEndPoint($url) {
212
+        $client = $this->httpClientService->newClient();
213
+        try {
214
+            $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
215
+        } catch (\Exception $e) {
216
+            return '';
217
+        }
218
+
219
+        $result = $response->getBody();
220
+        $result = json_decode($result, true);
221
+
222
+        $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
223
+
224
+        if (isset($result['endPoint']) && $supportedVersion) {
225
+            return $result['endPoint'];
226
+        }
227
+
228
+        return '';
229
+    }
230 230
 
231 231
 
232 232
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationProvider.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -39,42 +39,42 @@
 block discarded – undo
39 39
 
40 40
 interface ICloudFederationProvider {
41 41
 
42
-	/**
43
-	 * get the name of the share type, handled by this provider
44
-	 *
45
-	 * @return string
46
-	 *
47
-	 * @since 14.0.0
48
-	 */
49
-	public function getShareType();
42
+    /**
43
+     * get the name of the share type, handled by this provider
44
+     *
45
+     * @return string
46
+     *
47
+     * @since 14.0.0
48
+     */
49
+    public function getShareType();
50 50
 
51
-	/**
52
-	 * share received from another server
53
-	 *
54
-	 * @param ICloudFederationShare $share
55
-	 * @return string provider specific unique ID of the share
56
-	 *
57
-	 * @throws ProviderCouldNotAddShareException
58
-	 *
59
-	 * @since 14.0.0
60
-	 */
61
-	public function shareReceived(ICloudFederationShare $share);
51
+    /**
52
+     * share received from another server
53
+     *
54
+     * @param ICloudFederationShare $share
55
+     * @return string provider specific unique ID of the share
56
+     *
57
+     * @throws ProviderCouldNotAddShareException
58
+     *
59
+     * @since 14.0.0
60
+     */
61
+    public function shareReceived(ICloudFederationShare $share);
62 62
 
63
-	/**
64
-	 * notification received from another server
65
-	 *
66
-	 * @param string $notificationType (e.g SHARE_ACCEPTED)
67
-	 * @param string $providerId share ID
68
-	 * @param array $notification provider specific notification
69
-	 * @return array $data send back to sender
70
-	 *
71
-	 * @throws ShareNotFoundException
72
-	 * @throws ActionNotSupportedException
73
-	 * @throws BadRequestException
74
-	 * @throws AuthenticationFailedException
75
-	 *
76
-	 * @since 14.0.0
77
-	 */
78
-	public function notificationReceived($notificationType, $providerId, array $notification);
63
+    /**
64
+     * notification received from another server
65
+     *
66
+     * @param string $notificationType (e.g SHARE_ACCEPTED)
67
+     * @param string $providerId share ID
68
+     * @param array $notification provider specific notification
69
+     * @return array $data send back to sender
70
+     *
71
+     * @throws ShareNotFoundException
72
+     * @throws ActionNotSupportedException
73
+     * @throws BadRequestException
74
+     * @throws AuthenticationFailedException
75
+     *
76
+     * @since 14.0.0
77
+     */
78
+    public function notificationReceived($notificationType, $providerId, array $notification);
79 79
 
80 80
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationProviderManager.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -32,76 +32,76 @@
 block discarded – undo
32 32
  */
33 33
 interface ICloudFederationProviderManager {
34 34
 
35
-	/**
36
-	 * Registers an callback function which must return an cloud federation provider
37
-	 *
38
-	 * @param string $shareType which share type does the provider handles
39
-	 * @param string $displayName user facing name of the federated share provider
40
-	 * @param callable $callback
41
-	 * @throws Exceptions\ProviderAlreadyExistsException
42
-	 *
43
-	 * @since 14.0.0
44
-	 */
45
-	public function addCloudFederationProvider($shareType, $displayName, callable $callback);
35
+    /**
36
+     * Registers an callback function which must return an cloud federation provider
37
+     *
38
+     * @param string $shareType which share type does the provider handles
39
+     * @param string $displayName user facing name of the federated share provider
40
+     * @param callable $callback
41
+     * @throws Exceptions\ProviderAlreadyExistsException
42
+     *
43
+     * @since 14.0.0
44
+     */
45
+    public function addCloudFederationProvider($shareType, $displayName, callable $callback);
46 46
 
47
-	/**
48
-	 * remove cloud federation provider
49
-	 *
50
-	 * @param string $shareType
51
-	 *
52
-	 * @since 14.0.0
53
-	 */
54
-	public function removeCloudFederationProvider($shareType);
47
+    /**
48
+     * remove cloud federation provider
49
+     *
50
+     * @param string $shareType
51
+     *
52
+     * @since 14.0.0
53
+     */
54
+    public function removeCloudFederationProvider($shareType);
55 55
 
56
-	/**
57
-	 * get a list of all cloudFederationProviders
58
-	 *
59
-	 * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
60
-	 *
61
-	 * @since 14.0.0
62
-	 */
63
-	public function getAllCloudFederationProviders();
56
+    /**
57
+     * get a list of all cloudFederationProviders
58
+     *
59
+     * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
60
+     *
61
+     * @since 14.0.0
62
+     */
63
+    public function getAllCloudFederationProviders();
64 64
 
65
-	/**
66
-	 * get a specific cloud federation provider
67
-	 *
68
-	 * @param string $shareType
69
-	 * @return ICloudFederationProvider
70
-	 * @throws Exceptions\ProviderDoesNotExistsException;
71
-	 *
72
-	 * @since 14.0.0
73
-	 */
74
-	public function getCloudFederationProvider($shareType);
65
+    /**
66
+     * get a specific cloud federation provider
67
+     *
68
+     * @param string $shareType
69
+     * @return ICloudFederationProvider
70
+     * @throws Exceptions\ProviderDoesNotExistsException;
71
+     *
72
+     * @since 14.0.0
73
+     */
74
+    public function getCloudFederationProvider($shareType);
75 75
 
76
-	/**
77
-	 * send federated share
78
-	 *
79
-	 * @param ICloudFederationShare $share
80
-	 * @return bool
81
-	 *
82
-	 * @since 14.0.0
83
-	 */
84
-	public function sendShare(ICloudFederationShare $share);
76
+    /**
77
+     * send federated share
78
+     *
79
+     * @param ICloudFederationShare $share
80
+     * @return bool
81
+     *
82
+     * @since 14.0.0
83
+     */
84
+    public function sendShare(ICloudFederationShare $share);
85 85
 
86
-	/**
87
-	 * send notification about existing share
88
-	 *
89
-	 * @param string $url
90
-	 * @param ICloudFederationNotification $notification
91
-	 * @return mixed
92
-	 *
93
-	 * @since 14.0.0
94
-	 */
95
-	public function sendNotification($url, ICloudFederationNotification $notification);
86
+    /**
87
+     * send notification about existing share
88
+     *
89
+     * @param string $url
90
+     * @param ICloudFederationNotification $notification
91
+     * @return mixed
92
+     *
93
+     * @since 14.0.0
94
+     */
95
+    public function sendNotification($url, ICloudFederationNotification $notification);
96 96
 
97
-	/**
98
-	 * check if the new cloud federation API is ready to be used
99
-	 *
100
-	 * @return bool
101
-	 *
102
-	 * @since 14.0.0
103
-	 */
104
-	public function isReady();
97
+    /**
98
+     * check if the new cloud federation API is ready to be used
99
+     *
100
+     * @return bool
101
+     *
102
+     * @since 14.0.0
103
+     */
104
+    public function isReady();
105 105
 
106 106
 
107 107
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Controller/RequestHandlerController.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -51,233 +51,233 @@
 block discarded – undo
51 51
  */
52 52
 class RequestHandlerController extends Controller {
53 53
 
54
-	/** @var ILogger */
55
-	private $logger;
54
+    /** @var ILogger */
55
+    private $logger;
56 56
 
57
-	/** @var IUserManager */
58
-	private $userManager;
57
+    /** @var IUserManager */
58
+    private $userManager;
59 59
 
60
-	/** @var IURLGenerator */
61
-	private $urlGenerator;
60
+    /** @var IURLGenerator */
61
+    private $urlGenerator;
62 62
 
63
-	/** @var ICloudFederationProviderManager */
64
-	private $cloudFederationProviderManager;
63
+    /** @var ICloudFederationProviderManager */
64
+    private $cloudFederationProviderManager;
65 65
 
66
-	/** @var Config */
67
-	private $config;
66
+    /** @var Config */
67
+    private $config;
68 68
 
69
-	/** @var ICloudFederationFactory */
70
-	private $factory;
69
+    /** @var ICloudFederationFactory */
70
+    private $factory;
71 71
 
72
-	/** @var ICloudIdManager */
73
-	private $cloudIdManager;
72
+    /** @var ICloudIdManager */
73
+    private $cloudIdManager;
74 74
 
75
-	public function __construct($appName,
76
-								IRequest $request,
77
-								ILogger $logger,
78
-								IUserManager $userManager,
79
-								IURLGenerator $urlGenerator,
80
-								ICloudFederationProviderManager $cloudFederationProviderManager,
81
-								Config $config,
82
-								ICloudFederationFactory $factory,
83
-								ICloudIdManager $cloudIdManager
84
-	) {
85
-		parent::__construct($appName, $request);
75
+    public function __construct($appName,
76
+                                IRequest $request,
77
+                                ILogger $logger,
78
+                                IUserManager $userManager,
79
+                                IURLGenerator $urlGenerator,
80
+                                ICloudFederationProviderManager $cloudFederationProviderManager,
81
+                                Config $config,
82
+                                ICloudFederationFactory $factory,
83
+                                ICloudIdManager $cloudIdManager
84
+    ) {
85
+        parent::__construct($appName, $request);
86 86
 
87
-		$this->logger = $logger;
88
-		$this->userManager = $userManager;
89
-		$this->urlGenerator = $urlGenerator;
90
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
91
-		$this->config = $config;
92
-		$this->factory = $factory;
93
-		$this->cloudIdManager = $cloudIdManager;
94
-	}
87
+        $this->logger = $logger;
88
+        $this->userManager = $userManager;
89
+        $this->urlGenerator = $urlGenerator;
90
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
91
+        $this->config = $config;
92
+        $this->factory = $factory;
93
+        $this->cloudIdManager = $cloudIdManager;
94
+    }
95 95
 
96
-	/**
97
-	 * add share
98
-	 *
99
-	 * @NoCSRFRequired
100
-	 * @PublicPage
101
-	 * @BruteForceProtection(action=receiveFederatedShare)
102
-	 *
103
-	 * @param string $shareWith
104
-	 * @param string $name resource name (e.g. document.odt)
105
-	 * @param string $description share description (optional)
106
-	 * @param string $providerId resource UID on the provider side
107
-	 * @param string $owner provider specific UID of the user who owns the resource
108
-	 * @param string $ownerDisplayName display name of the user who shared the item
109
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
110
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
111
-	 * @param string $sharedSecret use to authenticate accross servers
112
-	 * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
113
-	 * @param string $shareType ('group' or 'user' share)
114
-	 * @param $resourceType ('file', 'calendar',...)
115
-	 * @return Http\DataResponse|JSONResponse
116
-	 *
117
-	 * 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
118
-	 */
119
-	public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
96
+    /**
97
+     * add share
98
+     *
99
+     * @NoCSRFRequired
100
+     * @PublicPage
101
+     * @BruteForceProtection(action=receiveFederatedShare)
102
+     *
103
+     * @param string $shareWith
104
+     * @param string $name resource name (e.g. document.odt)
105
+     * @param string $description share description (optional)
106
+     * @param string $providerId resource UID on the provider side
107
+     * @param string $owner provider specific UID of the user who owns the resource
108
+     * @param string $ownerDisplayName display name of the user who shared the item
109
+     * @param string $sharedBy provider specific UID of the user who shared the resource
110
+     * @param string $sharedByDisplayName display name of the user who shared the resource
111
+     * @param string $sharedSecret use to authenticate accross servers
112
+     * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
113
+     * @param string $shareType ('group' or 'user' share)
114
+     * @param $resourceType ('file', 'calendar',...)
115
+     * @return Http\DataResponse|JSONResponse
116
+     *
117
+     * 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
118
+     */
119
+    public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
120 120
 
121
-		if (!$this->config->incomingRequestsEnabled()) {
122
-			return new JSONResponse(
123
-				['message' => 'This server doesn\'t support outgoing federated shares'],
124
-			Http::STATUS_NOT_IMPLEMENTED
125
-			);
126
-		}
121
+        if (!$this->config->incomingRequestsEnabled()) {
122
+            return new JSONResponse(
123
+                ['message' => 'This server doesn\'t support outgoing federated shares'],
124
+            Http::STATUS_NOT_IMPLEMENTED
125
+            );
126
+        }
127 127
 
128
-		// check if all required parameters are set
129
-		if ($shareWith === null ||
130
-			$name === null ||
131
-			$providerId === null ||
132
-			$owner === null ||
133
-			$resourceType === null ||
134
-			$shareType === null ||
135
-			!is_array($protocol) ||
136
-			!isset($protocol['name']) ||
137
-			!isset ($protocol['options']) ||
138
-			!is_array($protocol['options']) ||
139
-			!isset($protocol['options']['sharedSecret'])
140
-		) {
141
-			return new JSONResponse(
142
-				['message' => 'Missing arguments'],
143
-				Http::STATUS_BAD_REQUEST
144
-			);
145
-		}
128
+        // check if all required parameters are set
129
+        if ($shareWith === null ||
130
+            $name === null ||
131
+            $providerId === null ||
132
+            $owner === null ||
133
+            $resourceType === null ||
134
+            $shareType === null ||
135
+            !is_array($protocol) ||
136
+            !isset($protocol['name']) ||
137
+            !isset ($protocol['options']) ||
138
+            !is_array($protocol['options']) ||
139
+            !isset($protocol['options']['sharedSecret'])
140
+        ) {
141
+            return new JSONResponse(
142
+                ['message' => 'Missing arguments'],
143
+                Http::STATUS_BAD_REQUEST
144
+            );
145
+        }
146 146
 
147
-		$cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
148
-		$shareWithLocalId = $cloudId->getUser();
149
-		$shareWith = $this->mapUid($shareWithLocalId);
147
+        $cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
148
+        $shareWithLocalId = $cloudId->getUser();
149
+        $shareWith = $this->mapUid($shareWithLocalId);
150 150
 
151
-		if (!$this->userManager->userExists($shareWith)) {
152
-			return new JSONResponse(
153
-				['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
154
-				Http::STATUS_BAD_REQUEST
155
-			);
156
-		}
151
+        if (!$this->userManager->userExists($shareWith)) {
152
+            return new JSONResponse(
153
+                ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
154
+                Http::STATUS_BAD_REQUEST
155
+            );
156
+        }
157 157
 
158
-		// if no explicit display name is given, we use the uid as display name
159
-		$ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName;
160
-		$sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName;
158
+        // if no explicit display name is given, we use the uid as display name
159
+        $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName;
160
+        $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName;
161 161
 
162
-		// sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner
163
-		if ($sharedBy === null) {
164
-			$sharedBy = $owner;
165
-			$sharedByDisplayName = $ownerDisplayName;
166
-		}
162
+        // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner
163
+        if ($sharedBy === null) {
164
+            $sharedBy = $owner;
165
+            $sharedByDisplayName = $ownerDisplayName;
166
+        }
167 167
 
168
-		try {
169
-			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
170
-			$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
171
-			$share->setProtocol($protocol);
172
-			$id = $provider->shareReceived($share);
173
-		} catch (ProviderDoesNotExistsException $e) {
174
-			return new JSONResponse(
175
-				['message' => $e->getMessage()],
176
-				Http::STATUS_NOT_IMPLEMENTED
177
-			);
178
-		} catch (ProviderCouldNotAddShareException $e) {
179
-			return new JSONResponse(
180
-				['message' => $e->getMessage()],
181
-				$e->getCode()
182
-			);
183
-		} catch (\Exception $e) {
184
-			return new JSONResponse(
185
-				['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
186
-				Http::STATUS_BAD_REQUEST
187
-			);
188
-		}
168
+        try {
169
+            $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
170
+            $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
171
+            $share->setProtocol($protocol);
172
+            $id = $provider->shareReceived($share);
173
+        } catch (ProviderDoesNotExistsException $e) {
174
+            return new JSONResponse(
175
+                ['message' => $e->getMessage()],
176
+                Http::STATUS_NOT_IMPLEMENTED
177
+            );
178
+        } catch (ProviderCouldNotAddShareException $e) {
179
+            return new JSONResponse(
180
+                ['message' => $e->getMessage()],
181
+                $e->getCode()
182
+            );
183
+        } catch (\Exception $e) {
184
+            return new JSONResponse(
185
+                ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
186
+                Http::STATUS_BAD_REQUEST
187
+            );
188
+        }
189 189
 
190
-		return new JSONResponse(
191
-			['id' => $id, 'createdAt' => time()],
192
-			Http::STATUS_CREATED);
190
+        return new JSONResponse(
191
+            ['id' => $id, 'createdAt' => time()],
192
+            Http::STATUS_CREATED);
193 193
 
194
-	}
194
+    }
195 195
 
196
-	/**
197
-	 * receive notification about existing share
198
-	 *
199
-	 * @NoCSRFRequired
200
-	 * @PublicPage
201
-	 * @BruteForceProtection(action=receiveFederatedShareNotification)
202
-	 *
203
-	 * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED)
204
-	 * @param string $resourceType (calendar, file, contact,...)
205
-	 * @param string $providerId id of the share
206
-	 * @param array $notification the actual payload of the notification
207
-	 * @return JSONResponse
208
-	 */
209
-	public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) {
210
-		if (!$this->config->incomingRequestsEnabled()) {
211
-			return new JSONResponse(
212
-				['message' => 'This server doesn\'t support outgoing federated shares'],
213
-				Http::STATUS_NOT_IMPLEMENTED
214
-			);
215
-		}
196
+    /**
197
+     * receive notification about existing share
198
+     *
199
+     * @NoCSRFRequired
200
+     * @PublicPage
201
+     * @BruteForceProtection(action=receiveFederatedShareNotification)
202
+     *
203
+     * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED)
204
+     * @param string $resourceType (calendar, file, contact,...)
205
+     * @param string $providerId id of the share
206
+     * @param array $notification the actual payload of the notification
207
+     * @return JSONResponse
208
+     */
209
+    public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) {
210
+        if (!$this->config->incomingRequestsEnabled()) {
211
+            return new JSONResponse(
212
+                ['message' => 'This server doesn\'t support outgoing federated shares'],
213
+                Http::STATUS_NOT_IMPLEMENTED
214
+            );
215
+        }
216 216
 
217
-		// check if all required parameters are set
218
-		if ($notificationType === null ||
219
-			$resourceType === null ||
220
-			$providerId === null ||
221
-			!is_array($notification)
222
-		) {
223
-			return new JSONResponse(
224
-				['message' => 'Missing arguments'],
225
-				Http::STATUS_BAD_REQUEST
226
-			);
227
-		}
217
+        // check if all required parameters are set
218
+        if ($notificationType === null ||
219
+            $resourceType === null ||
220
+            $providerId === null ||
221
+            !is_array($notification)
222
+        ) {
223
+            return new JSONResponse(
224
+                ['message' => 'Missing arguments'],
225
+                Http::STATUS_BAD_REQUEST
226
+            );
227
+        }
228 228
 
229
-		try {
230
-			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
231
-			$result = $provider->notificationReceived($notificationType, $providerId, $notification);
232
-		} catch (ProviderDoesNotExistsException $e) {
233
-			return new JSONResponse(
234
-				['message' => $e->getMessage()],
235
-				Http::STATUS_BAD_REQUEST
236
-			);
237
-		} catch (ShareNotFoundException $e) {
238
-			return new JSONResponse(
239
-				['message' => $e->getMessage()],
240
-				Http::STATUS_BAD_REQUEST
241
-			);
242
-		} catch (ActionNotSupportedException $e) {
243
-			return new JSONResponse(
244
-				['message' => $e->getMessage()],
245
-				Http::STATUS_NOT_IMPLEMENTED
246
-			);
247
-		} catch (BadRequestException $e) {
248
-			return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST);
249
-		} catch (AuthenticationFailedException $e) {
250
-			return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN);
251
-		}
252
-		catch (\Exception $e) {
253
-			return new JSONResponse(
254
-				['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
255
-				Http::STATUS_BAD_REQUEST
256
-			);
257
-		}
229
+        try {
230
+            $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
231
+            $result = $provider->notificationReceived($notificationType, $providerId, $notification);
232
+        } catch (ProviderDoesNotExistsException $e) {
233
+            return new JSONResponse(
234
+                ['message' => $e->getMessage()],
235
+                Http::STATUS_BAD_REQUEST
236
+            );
237
+        } catch (ShareNotFoundException $e) {
238
+            return new JSONResponse(
239
+                ['message' => $e->getMessage()],
240
+                Http::STATUS_BAD_REQUEST
241
+            );
242
+        } catch (ActionNotSupportedException $e) {
243
+            return new JSONResponse(
244
+                ['message' => $e->getMessage()],
245
+                Http::STATUS_NOT_IMPLEMENTED
246
+            );
247
+        } catch (BadRequestException $e) {
248
+            return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST);
249
+        } catch (AuthenticationFailedException $e) {
250
+            return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN);
251
+        }
252
+        catch (\Exception $e) {
253
+            return new JSONResponse(
254
+                ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
255
+                Http::STATUS_BAD_REQUEST
256
+            );
257
+        }
258 258
 
259
-		return new JSONResponse($result,Http::STATUS_CREATED);
259
+        return new JSONResponse($result,Http::STATUS_CREATED);
260 260
 
261
-	}
261
+    }
262 262
 
263
-	/**
264
-	 * map login name to internal LDAP UID if a LDAP backend is in use
265
-	 *
266
-	 * @param string $uid
267
-	 * @return string mixed
268
-	 */
269
-	private function mapUid($uid) {
270
-		\OC::$server->getURLGenerator()->linkToDocs('key');
271
-		// FIXME this should be a method in the user management instead
272
-		$this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
273
-		\OCP\Util::emitHook(
274
-			'\OCA\Files_Sharing\API\Server2Server',
275
-			'preLoginNameUsedAsUserName',
276
-			array('uid' => &$uid)
277
-		);
278
-		$this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]);
263
+    /**
264
+     * map login name to internal LDAP UID if a LDAP backend is in use
265
+     *
266
+     * @param string $uid
267
+     * @return string mixed
268
+     */
269
+    private function mapUid($uid) {
270
+        \OC::$server->getURLGenerator()->linkToDocs('key');
271
+        // FIXME this should be a method in the user management instead
272
+        $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
273
+        \OCP\Util::emitHook(
274
+            '\OCA\Files_Sharing\API\Server2Server',
275
+            'preLoginNameUsedAsUserName',
276
+            array('uid' => &$uid)
277
+        );
278
+        $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]);
279 279
 
280
-		return $uid;
281
-	}
280
+        return $uid;
281
+    }
282 282
 
283 283
 }
Please login to merge, or discard this patch.