Completed
Pull Request — master (#9895)
by Björn
168:09 queued 150:46
created
lib/public/Federation/ICloudFederationNotification.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -30,24 +30,24 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationNotification {
32 32
 
33
-	/**
34
-	 * add a message to the notification
35
-	 *
36
-	 * @param string $notificationType (e.g. SHARE_ACCEPTED)
37
-	 * @param string $resourceType (e.g. file, calendar, contact,...)
38
-	 * @param $providerId id of the share
39
-	 * @param array $notification , payload of the notification
40
-	 *
41
-	 * @since 14.0.0
42
-	 */
43
-	public function setMessage($notificationType, $resourceType, $providerId, array $notification);
33
+    /**
34
+     * add a message to the notification
35
+     *
36
+     * @param string $notificationType (e.g. SHARE_ACCEPTED)
37
+     * @param string $resourceType (e.g. file, calendar, contact,...)
38
+     * @param $providerId id of the share
39
+     * @param array $notification , payload of the notification
40
+     *
41
+     * @since 14.0.0
42
+     */
43
+    public function setMessage($notificationType, $resourceType, $providerId, array $notification);
44 44
 
45
-	/**
46
-	 * get message, ready to send out
47
-	 *
48
-	 * @return array
49
-	 *
50
-	 * @since 14.0.0
51
-	 */
52
-	public function getMessage();
45
+    /**
46
+     * get message, ready to send out
47
+     *
48
+     * @return array
49
+     *
50
+     * @since 14.0.0
51
+     */
52
+    public function getMessage();
53 53
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationShare.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -30,221 +30,221 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationShare {
32 32
 
33
-	/**
34
-	 * set uid of the recipient
35
-	 *
36
-	 * @param string $user
37
-	 *
38
-	 * @since 14.0.0
39
-	 */
40
-	public function setShareWith($user);
41
-
42
-	/**
43
-	 * set resource name (e.g. file, calendar, contact,...)
44
-	 *
45
-	 * @param string $name
46
-	 *
47
-	 * @since 14.0.0
48
-	 */
49
-	public function setResourceName($name);
50
-
51
-	/**
52
-	 * set resource type (e.g. file, calendar, contact,...)
53
-	 *
54
-	 * @param string $resourceType
55
-	 *
56
-	 * @since 14.0.0
57
-	 */
58
-	public function setResourceType($resourceType);
59
-
60
-	/**
61
-	 * set resource description (optional)
62
-	 *
63
-	 * @param string $description
64
-	 *
65
-	 * @since 14.0.0
66
-	 */
67
-	public function setDescription($description);
68
-
69
-	/**
70
-	 * set provider ID (e.g. file ID)
71
-	 *
72
-	 * @param string $providerId
73
-	 *
74
-	 * @since 14.0.0
75
-	 */
76
-	public function setProviderId($providerId);
77
-
78
-	/**
79
-	 * set owner UID
80
-	 *
81
-	 * @param string $owner
82
-	 *
83
-	 * @since 14.0.0
84
-	 */
85
-	public function setOwner($owner);
86
-
87
-	/**
88
-	 * set owner display name
89
-	 *
90
-	 * @param string $ownerDisplayName
91
-	 *
92
-	 * @since 14.0.0
93
-	 */
94
-	public function setOwnerDisplayName($ownerDisplayName);
95
-
96
-	/**
97
-	 * set UID of the user who sends the share
98
-	 *
99
-	 * @param string $sharedBy
100
-	 *
101
-	 * @since 14.0.0
102
-	 */
103
-	public function setSharedBy($sharedBy);
104
-
105
-	/**
106
-	 * set display name of the user who sends the share
107
-	 *
108
-	 * @param $sharedByDisplayName
109
-	 *
110
-	 * @since 14.0.0
111
-	 */
112
-	public function setSharedByDisplayName($sharedByDisplayName);
113
-
114
-	/**
115
-	 * set protocol specification
116
-	 *
117
-	 * @param array $protocol
118
-	 *
119
-	 * @since 14.0.0
120
-	 */
121
-	public function setProtocol(array $protocol);
122
-
123
-	/**
124
-	 * share type (group or user)
125
-	 *
126
-	 * @param string $shareType
127
-	 *
128
-	 * @since 14.0.0
129
-	 */
130
-	public function setShareType($shareType);
131
-
132
-	/**
133
-	 * get the whole share, ready to send out
134
-	 *
135
-	 * @return array
136
-	 *
137
-	 * @since 14.0.0
138
-	 */
139
-	public function getShare();
140
-
141
-	/**
142
-	 * get uid of the recipient
143
-	 *
144
-	 * @return string
145
-	 *
146
-	 * @since 14.0.0
147
-	 */
148
-	public function getShareWith();
149
-
150
-	/**
151
-	 * get resource name (e.g. file, calendar, contact,...)
152
-	 *
153
-	 * @return string
154
-	 *
155
-	 * @since 14.0.0
156
-	 */
157
-	public function getResourceName();
158
-
159
-	/**
160
-	 * get resource type (e.g. file, calendar, contact,...)
161
-	 *
162
-	 * @return string
163
-	 *
164
-	 * @since 14.0.0
165
-	 */
166
-	public function getResourceType();
167
-
168
-	/**
169
-	 * get resource description (optional)
170
-	 *
171
-	 * @return string
172
-	 *
173
-	 * @since 14.0.0
174
-	 */
175
-	public function getDescription();
176
-
177
-	/**
178
-	 * get provider ID (e.g. file ID)
179
-	 *
180
-	 * @return string
181
-	 *
182
-	 * @since 14.0.0
183
-	 */
184
-	public function getProviderId();
185
-
186
-	/**
187
-	 * get owner UID
188
-	 *
189
-	 * @return string
190
-	 *
191
-	 * @since 14.0.0
192
-	 */
193
-	public function getOwner();
194
-
195
-	/**
196
-	 * get owner display name
197
-	 *
198
-	 * @return string
199
-	 *
200
-	 * @since 14.0.0
201
-	 */
202
-	public function getOwnerDisplayName();
203
-
204
-	/**
205
-	 * get UID of the user who sends the share
206
-	 *
207
-	 * @return string
208
-	 *
209
-	 * @since 14.0.0
210
-	 */
211
-	public function getSharedBy();
212
-
213
-	/**
214
-	 * get display name of the user who sends the share
215
-	 *
216
-	 * @return string
217
-	 *
218
-	 * @since 14.0.0
219
-	 */
220
-	public function getSharedByDisplayName();
221
-
222
-	/**
223
-	 * get share type (group or user)
224
-	 *
225
-	 * @return string
226
-	 *
227
-	 * @since 14.0.0
228
-	 */
229
-	public function getShareType();
230
-
231
-	/**
232
-	 * get share Secret
233
-	 *
234
-	 * @return string
235
-	 *
236
-	 * @since 14.0.0
237
-	 */
238
-	public function getShareSecret();
239
-
240
-
241
-	/**
242
-	 * get protocol specification
243
-	 *
244
-	 * @return array
245
-	 *
246
-	 * @since 14.0.0
247
-	 */
248
-	public function getProtocol();
33
+    /**
34
+     * set uid of the recipient
35
+     *
36
+     * @param string $user
37
+     *
38
+     * @since 14.0.0
39
+     */
40
+    public function setShareWith($user);
41
+
42
+    /**
43
+     * set resource name (e.g. file, calendar, contact,...)
44
+     *
45
+     * @param string $name
46
+     *
47
+     * @since 14.0.0
48
+     */
49
+    public function setResourceName($name);
50
+
51
+    /**
52
+     * set resource type (e.g. file, calendar, contact,...)
53
+     *
54
+     * @param string $resourceType
55
+     *
56
+     * @since 14.0.0
57
+     */
58
+    public function setResourceType($resourceType);
59
+
60
+    /**
61
+     * set resource description (optional)
62
+     *
63
+     * @param string $description
64
+     *
65
+     * @since 14.0.0
66
+     */
67
+    public function setDescription($description);
68
+
69
+    /**
70
+     * set provider ID (e.g. file ID)
71
+     *
72
+     * @param string $providerId
73
+     *
74
+     * @since 14.0.0
75
+     */
76
+    public function setProviderId($providerId);
77
+
78
+    /**
79
+     * set owner UID
80
+     *
81
+     * @param string $owner
82
+     *
83
+     * @since 14.0.0
84
+     */
85
+    public function setOwner($owner);
86
+
87
+    /**
88
+     * set owner display name
89
+     *
90
+     * @param string $ownerDisplayName
91
+     *
92
+     * @since 14.0.0
93
+     */
94
+    public function setOwnerDisplayName($ownerDisplayName);
95
+
96
+    /**
97
+     * set UID of the user who sends the share
98
+     *
99
+     * @param string $sharedBy
100
+     *
101
+     * @since 14.0.0
102
+     */
103
+    public function setSharedBy($sharedBy);
104
+
105
+    /**
106
+     * set display name of the user who sends the share
107
+     *
108
+     * @param $sharedByDisplayName
109
+     *
110
+     * @since 14.0.0
111
+     */
112
+    public function setSharedByDisplayName($sharedByDisplayName);
113
+
114
+    /**
115
+     * set protocol specification
116
+     *
117
+     * @param array $protocol
118
+     *
119
+     * @since 14.0.0
120
+     */
121
+    public function setProtocol(array $protocol);
122
+
123
+    /**
124
+     * share type (group or user)
125
+     *
126
+     * @param string $shareType
127
+     *
128
+     * @since 14.0.0
129
+     */
130
+    public function setShareType($shareType);
131
+
132
+    /**
133
+     * get the whole share, ready to send out
134
+     *
135
+     * @return array
136
+     *
137
+     * @since 14.0.0
138
+     */
139
+    public function getShare();
140
+
141
+    /**
142
+     * get uid of the recipient
143
+     *
144
+     * @return string
145
+     *
146
+     * @since 14.0.0
147
+     */
148
+    public function getShareWith();
149
+
150
+    /**
151
+     * get resource name (e.g. file, calendar, contact,...)
152
+     *
153
+     * @return string
154
+     *
155
+     * @since 14.0.0
156
+     */
157
+    public function getResourceName();
158
+
159
+    /**
160
+     * get resource type (e.g. file, calendar, contact,...)
161
+     *
162
+     * @return string
163
+     *
164
+     * @since 14.0.0
165
+     */
166
+    public function getResourceType();
167
+
168
+    /**
169
+     * get resource description (optional)
170
+     *
171
+     * @return string
172
+     *
173
+     * @since 14.0.0
174
+     */
175
+    public function getDescription();
176
+
177
+    /**
178
+     * get provider ID (e.g. file ID)
179
+     *
180
+     * @return string
181
+     *
182
+     * @since 14.0.0
183
+     */
184
+    public function getProviderId();
185
+
186
+    /**
187
+     * get owner UID
188
+     *
189
+     * @return string
190
+     *
191
+     * @since 14.0.0
192
+     */
193
+    public function getOwner();
194
+
195
+    /**
196
+     * get owner display name
197
+     *
198
+     * @return string
199
+     *
200
+     * @since 14.0.0
201
+     */
202
+    public function getOwnerDisplayName();
203
+
204
+    /**
205
+     * get UID of the user who sends the share
206
+     *
207
+     * @return string
208
+     *
209
+     * @since 14.0.0
210
+     */
211
+    public function getSharedBy();
212
+
213
+    /**
214
+     * get display name of the user who sends the share
215
+     *
216
+     * @return string
217
+     *
218
+     * @since 14.0.0
219
+     */
220
+    public function getSharedByDisplayName();
221
+
222
+    /**
223
+     * get share type (group or user)
224
+     *
225
+     * @return string
226
+     *
227
+     * @since 14.0.0
228
+     */
229
+    public function getShareType();
230
+
231
+    /**
232
+     * get share Secret
233
+     *
234
+     * @return string
235
+     *
236
+     * @since 14.0.0
237
+     */
238
+    public function getShareSecret();
239
+
240
+
241
+    /**
242
+     * get protocol specification
243
+     *
244
+     * @return array
245
+     *
246
+     * @since 14.0.0
247
+     */
248
+    public function getProtocol();
249 249
 
250 250
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/ProviderCouldNotAddShareException.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,19 +33,19 @@
 block discarded – undo
33 33
  */
34 34
 class ProviderCouldNotAddShareException extends HintException {
35 35
 
36
-	/**
37
-	 * ProviderCouldNotAddShareException constructor.
38
-	 *
39
-	 * @since 14.0.0
40
-	 *
41
-	 * @param string $message
42
-	 * @param string $hint
43
-	 * @param int $code
44
-	 * @param \Exception|null $previous
45
-	 */
46
-	public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) {
47
-		parent::__construct($message, $hint, $code, $previous);
48
-	}
36
+    /**
37
+     * ProviderCouldNotAddShareException constructor.
38
+     *
39
+     * @since 14.0.0
40
+     *
41
+     * @param string $message
42
+     * @param string $hint
43
+     * @param int $code
44
+     * @param \Exception|null $previous
45
+     */
46
+    public function __construct($message, $hint = '', $code = Http::STATUS_BAD_REQUEST, \Exception $previous = null) {
47
+        parent::__construct($message, $hint, $code, $previous);
48
+    }
49 49
 
50 50
 
51 51
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationFactory.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
  */
31 31
 interface ICloudFederationFactory {
32 32
 
33
-	/**
34
-	 * get a CloudFederationShare Object to prepare a share you want to send
35
-	 *
36
-	 * @param string $shareWith
37
-	 * @param string $name resource name (e.g. document.odt)
38
-	 * @param string $description share description (optional)
39
-	 * @param string $providerId resource UID on the provider side
40
-	 * @param string $owner provider specific UID of the user who owns the resource
41
-	 * @param string $ownerDisplayName display name of the user who shared the item
42
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
43
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
44
-	 * @param string $sharedSecret used to authenticate requests across servers
45
-	 * @param string $shareType ('group' or 'user' share)
46
-	 * @param $resourceType ('file', 'calendar',...)
47
-	 * @return ICloudFederationShare
48
-	 *
49
-	 * @since 14.0.0
50
-	 */
51
-	public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType);
33
+    /**
34
+     * get a CloudFederationShare Object to prepare a share you want to send
35
+     *
36
+     * @param string $shareWith
37
+     * @param string $name resource name (e.g. document.odt)
38
+     * @param string $description share description (optional)
39
+     * @param string $providerId resource UID on the provider side
40
+     * @param string $owner provider specific UID of the user who owns the resource
41
+     * @param string $ownerDisplayName display name of the user who shared the item
42
+     * @param string $sharedBy provider specific UID of the user who shared the resource
43
+     * @param string $sharedByDisplayName display name of the user who shared the resource
44
+     * @param string $sharedSecret used to authenticate requests across servers
45
+     * @param string $shareType ('group' or 'user' share)
46
+     * @param $resourceType ('file', 'calendar',...)
47
+     * @return ICloudFederationShare
48
+     *
49
+     * @since 14.0.0
50
+     */
51
+    public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType);
52 52
 
53
-	/**
54
-	 * get a Cloud FederationNotification object to prepare a notification you
55
-	 * want to send
56
-	 *
57
-	 * @return ICloudFederationNotification
58
-	 *
59
-	 * @since 14.0.0
60
-	 */
61
-	public function getCloudFederationNotification();
53
+    /**
54
+     * get a Cloud FederationNotification object to prepare a notification you
55
+     * want to send
56
+     *
57
+     * @return ICloudFederationNotification
58
+     *
59
+     * @since 14.0.0
60
+     */
61
+    public function getCloudFederationNotification();
62 62
 }
Please login to merge, or discard this patch.
lib/public/Federation/Exceptions/AuthenticationFailedException.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@
 block discarded – undo
32 32
  */
33 33
 class AuthenticationFailedException extends HintException {
34 34
 
35
-	/**
36
-	 * BadRequestException constructor.
37
-	 *
38
-	 * @since 14.0.0
39
-	 *
40
-	 */
41
-	public function __construct() {
42
-		$l = \OC::$server->getL10N('federation');
43
-		$message = 'Authentication failed, wrong token or provider ID given';
44
-		$hint = $l->t('Authentication failed, wrong token or provider ID given');
45
-		parent::__construct($message, $hint);
46
-	}
35
+    /**
36
+     * BadRequestException constructor.
37
+     *
38
+     * @since 14.0.0
39
+     *
40
+     */
41
+    public function __construct() {
42
+        $l = \OC::$server->getL10N('federation');
43
+        $message = 'Authentication failed, wrong token or provider ID given';
44
+        $hint = $l->t('Authentication failed, wrong token or provider ID given');
45
+        parent::__construct($message, $hint);
46
+    }
47 47
 
48 48
 }
Please login to merge, or discard this patch.
lib/private/Share/Constants.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@
 block discarded – undo
29 29
 
30 30
 class Constants {
31 31
 
32
-	const SHARE_TYPE_USER = 0;
33
-	const SHARE_TYPE_GROUP = 1;
34
-	const SHARE_TYPE_LINK = 3;
35
-	const SHARE_TYPE_EMAIL = 4;
36
-	const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
37
-	const SHARE_TYPE_REMOTE = 6;
38
-	const SHARE_TYPE_CIRCLE = 7;
39
-	const SHARE_TYPE_GUEST = 8;
40
-	const SHARE_TYPE_REMOTE_GROUP = 9;
32
+    const SHARE_TYPE_USER = 0;
33
+    const SHARE_TYPE_GROUP = 1;
34
+    const SHARE_TYPE_LINK = 3;
35
+    const SHARE_TYPE_EMAIL = 4;
36
+    const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
37
+    const SHARE_TYPE_REMOTE = 6;
38
+    const SHARE_TYPE_CIRCLE = 7;
39
+    const SHARE_TYPE_GUEST = 8;
40
+    const SHARE_TYPE_REMOTE_GROUP = 9;
41 41
 
42
-	const FORMAT_NONE = -1;
43
-	const FORMAT_STATUSES = -2;
44
-	const FORMAT_SOURCES = -3;  // ToDo Check if it is still in use otherwise remove it
42
+    const FORMAT_NONE = -1;
43
+    const FORMAT_STATUSES = -2;
44
+    const FORMAT_SOURCES = -3;  // ToDo Check if it is still in use otherwise remove it
45 45
 
46
-	const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls
46
+    const RESPONSE_FORMAT = 'json'; // default resonse format for ocs calls
47 47
 
48
-	const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility
48
+    const TOKEN_LENGTH = 15; // old (oc7) length is 32, keep token length in db at least that for compatibility
49 49
 
50
-	protected static $shareTypeUserAndGroups = -1;
51
-	protected static $shareTypeGroupUserUnique = 2;
52
-	protected static $backends = array();
53
-	protected static $backendTypes = array();
54
-	protected static $isResharingAllowed;
50
+    protected static $shareTypeUserAndGroups = -1;
51
+    protected static $shareTypeGroupUserUnique = 2;
52
+    protected static $backends = array();
53
+    protected static $backendTypes = array();
54
+    protected static $isResharingAllowed;
55 55
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Config.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -35,26 +35,26 @@
 block discarded – undo
35 35
  */
36 36
 class Config {
37 37
 
38
-	/** @var ICloudFederationProviderManager */
39
-	private $cloudFederationProviderManager;
40
-
41
-	public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
42
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
43
-	}
44
-
45
-	/**
46
-	 * get a list of supported share types
47
-	 *
48
-	 * @param string $resourceType
49
-	 * @return array
50
-	 */
51
-	public function getSupportedShareTypes($resourceType) {
52
-		try {
53
-			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
54
-			return $provider->getSupportedShareTypes();
55
-		} catch (\Exception $e) {
56
-			return [];
57
-		}
58
-	}
38
+    /** @var ICloudFederationProviderManager */
39
+    private $cloudFederationProviderManager;
40
+
41
+    public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
42
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
43
+    }
44
+
45
+    /**
46
+     * get a list of supported share types
47
+     *
48
+     * @param string $resourceType
49
+     * @return array
50
+     */
51
+    public function getSupportedShareTypes($resourceType) {
52
+        try {
53
+            $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
54
+            return $provider->getSupportedShareTypes();
55
+        } catch (\Exception $e) {
56
+            return [];
57
+        }
58
+    }
59 59
 
60 60
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/External/Storage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -407,7 +407,7 @@
 block discarded – undo
407 407
 	/**
408 408
 	 * calculate default permissions in case no permissions are provided
409 409
 	 *
410
-	 * @param $path
410
+	 * @param string $path
411 411
 	 * @return int
412 412
 	 */
413 413
 	protected function getDefaultPermissions($path) {
Please login to merge, or discard this patch.
Indentation   +376 added lines, -376 removed lines patch added patch discarded remove patch
@@ -43,380 +43,380 @@
 block discarded – undo
43 43
 use OCP\Files\StorageNotAvailableException;
44 44
 
45 45
 class Storage extends DAV implements ISharedStorage {
46
-	/** @var ICloudId */
47
-	private $cloudId;
48
-	/** @var string */
49
-	private $mountPoint;
50
-	/** @var string */
51
-	private $token;
52
-	/** @var \OCP\ICacheFactory */
53
-	private $memcacheFactory;
54
-	/** @var \OCP\Http\Client\IClientService */
55
-	private $httpClient;
56
-	/** @var bool */
57
-	private $updateChecked = false;
58
-
59
-	/**
60
-	 * @var \OCA\Files_Sharing\External\Manager
61
-	 */
62
-	private $manager;
63
-
64
-	public function __construct($options) {
65
-		$this->memcacheFactory = \OC::$server->getMemCacheFactory();
66
-		$this->httpClient = $options['HttpClientService'];
67
-
68
-		$this->manager = $options['manager'];
69
-		$this->cloudId = $options['cloudId'];
70
-		$discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
71
-
72
-		list($protocol, $remote) = explode('://', $this->cloudId->getRemote());
73
-		if (strpos($remote, '/')) {
74
-			list($host, $root) = explode('/', $remote, 2);
75
-		} else {
76
-			$host = $remote;
77
-			$root = '';
78
-		}
79
-		$secure = $protocol === 'https';
80
-		$federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81
-		$webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
-		$root = rtrim($root, '/') . $webDavEndpoint;
83
-		$this->mountPoint = $options['mountpoint'];
84
-		$this->token = $options['token'];
85
-
86
-		parent::__construct(array(
87
-			'secure' => $secure,
88
-			'host' => $host,
89
-			'root' => $root,
90
-			'user' => $options['token'],
91
-			'password' => (string)$options['password']
92
-		));
93
-	}
94
-
95
-	public function getWatcher($path = '', $storage = null) {
96
-		if (!$storage) {
97
-			$storage = $this;
98
-		}
99
-		if (!isset($this->watcher)) {
100
-			$this->watcher = new Watcher($storage);
101
-			$this->watcher->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
102
-		}
103
-		return $this->watcher;
104
-	}
105
-
106
-	public function getRemoteUser() {
107
-		return $this->cloudId->getUser();
108
-	}
109
-
110
-	public function getRemote() {
111
-		return $this->cloudId->getRemote();
112
-	}
113
-
114
-	public function getMountPoint() {
115
-		return $this->mountPoint;
116
-	}
117
-
118
-	public function getToken() {
119
-		return $this->token;
120
-	}
121
-
122
-	public function getPassword() {
123
-		return $this->password;
124
-	}
125
-
126
-	/**
127
-	 * @brief get id of the mount point
128
-	 * @return string
129
-	 */
130
-	public function getId() {
131
-		return 'shared::' . md5($this->token . '@' . $this->getRemote());
132
-	}
133
-
134
-	public function getCache($path = '', $storage = null) {
135
-		if (is_null($this->cache)) {
136
-			$this->cache = new Cache($this, $this->cloudId);
137
-		}
138
-		return $this->cache;
139
-	}
140
-
141
-	/**
142
-	 * @param string $path
143
-	 * @param \OC\Files\Storage\Storage $storage
144
-	 * @return \OCA\Files_Sharing\External\Scanner
145
-	 */
146
-	public function getScanner($path = '', $storage = null) {
147
-		if (!$storage) {
148
-			$storage = $this;
149
-		}
150
-		if (!isset($this->scanner)) {
151
-			$this->scanner = new Scanner($storage);
152
-		}
153
-		return $this->scanner;
154
-	}
155
-
156
-	/**
157
-	 * check if a file or folder has been updated since $time
158
-	 *
159
-	 * @param string $path
160
-	 * @param int $time
161
-	 * @throws \OCP\Files\StorageNotAvailableException
162
-	 * @throws \OCP\Files\StorageInvalidException
163
-	 * @return bool
164
-	 */
165
-	public function hasUpdated($path, $time) {
166
-		// since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage
167
-		// because of that we only do one check for the entire storage per request
168
-		if ($this->updateChecked) {
169
-			return false;
170
-		}
171
-		$this->updateChecked = true;
172
-		try {
173
-			return parent::hasUpdated('', $time);
174
-		} catch (StorageInvalidException $e) {
175
-			// check if it needs to be removed
176
-			$this->checkStorageAvailability();
177
-			throw $e;
178
-		} catch (StorageNotAvailableException $e) {
179
-			// check if it needs to be removed or just temp unavailable
180
-			$this->checkStorageAvailability();
181
-			throw $e;
182
-		}
183
-	}
184
-
185
-	public function test() {
186
-		try {
187
-			return parent::test();
188
-		} catch (StorageInvalidException $e) {
189
-			// check if it needs to be removed
190
-			$this->checkStorageAvailability();
191
-			throw $e;
192
-		} catch (StorageNotAvailableException $e) {
193
-			// check if it needs to be removed or just temp unavailable
194
-			$this->checkStorageAvailability();
195
-			throw $e;
196
-		}
197
-	}
198
-
199
-	/**
200
-	 * Check whether this storage is permanently or temporarily
201
-	 * unavailable
202
-	 *
203
-	 * @throws \OCP\Files\StorageNotAvailableException
204
-	 * @throws \OCP\Files\StorageInvalidException
205
-	 */
206
-	public function checkStorageAvailability() {
207
-		// see if we can find out why the share is unavailable
208
-		try {
209
-			$this->getShareInfo();
210
-		} catch (NotFoundException $e) {
211
-			// a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
212
-			if ($this->testRemote()) {
213
-				// valid Nextcloud instance means that the public share no longer exists
214
-				// since this is permanent (re-sharing the file will create a new token)
215
-				// we remove the invalid storage
216
-				$this->manager->removeShare($this->mountPoint);
217
-				$this->manager->getMountManager()->removeMount($this->mountPoint);
218
-				throw new StorageInvalidException();
219
-			} else {
220
-				// Nextcloud instance is gone, likely to be a temporary server configuration error
221
-				throw new StorageNotAvailableException();
222
-			}
223
-		} catch (ForbiddenException $e) {
224
-			// auth error, remove share for now (provide a dialog in the future)
225
-			$this->manager->removeShare($this->mountPoint);
226
-			$this->manager->getMountManager()->removeMount($this->mountPoint);
227
-			throw new StorageInvalidException();
228
-		} catch (\GuzzleHttp\Exception\ConnectException $e) {
229
-			throw new StorageNotAvailableException();
230
-		} catch (\GuzzleHttp\Exception\RequestException $e) {
231
-			throw new StorageNotAvailableException();
232
-		} catch (\Exception $e) {
233
-			throw $e;
234
-		}
235
-	}
236
-
237
-	public function file_exists($path) {
238
-		if ($path === '') {
239
-			return true;
240
-		} else {
241
-			return parent::file_exists($path);
242
-		}
243
-	}
244
-
245
-	/**
246
-	 * check if the configured remote is a valid federated share provider
247
-	 *
248
-	 * @return bool
249
-	 */
250
-	protected function testRemote() {
251
-		try {
252
-			return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
-				|| $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
-				|| $this->testRemoteUrl($this->getRemote() . '/status.php');
255
-		} catch (\Exception $e) {
256
-			return false;
257
-		}
258
-	}
259
-
260
-	/**
261
-	 * @param string $url
262
-	 * @return bool
263
-	 */
264
-	private function testRemoteUrl($url) {
265
-		$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
-		if($cache->hasKey($url)) {
267
-			return (bool)$cache->get($url);
268
-		}
269
-
270
-		$client = $this->httpClient->newClient();
271
-		try {
272
-			$result = $client->get($url, [
273
-				'timeout' => 10,
274
-				'connect_timeout' => 10,
275
-			])->getBody();
276
-			$data = json_decode($result);
277
-			$returnValue = (is_object($data) && !empty($data->version));
278
-		} catch (ConnectException $e) {
279
-			$returnValue = false;
280
-		} catch (ClientException $e) {
281
-			$returnValue = false;
282
-		}
283
-
284
-		$cache->set($url, $returnValue, 60*60*24);
285
-		return $returnValue;
286
-	}
287
-
288
-	/**
289
-	 * Whether the remote is an ownCloud/Nextcloud, used since some sharing features are not
290
-	 * standardized. Let's use this to detect whether to use it.
291
-	 *
292
-	 * @return bool
293
-	 */
294
-	public function remoteIsOwnCloud() {
295
-		if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
296
-			return false;
297
-		}
298
-		return true;
299
-	}
300
-
301
-	/**
302
-	 * @return mixed
303
-	 * @throws ForbiddenException
304
-	 * @throws NotFoundException
305
-	 * @throws \Exception
306
-	 */
307
-	public function getShareInfo() {
308
-		$remote = $this->getRemote();
309
-		$token = $this->getToken();
310
-		$password = $this->getPassword();
311
-
312
-		// If remote is not an ownCloud do not try to get any share info
313
-		if(!$this->remoteIsOwnCloud()) {
314
-			return ['status' => 'unsupported'];
315
-		}
316
-
317
-		$url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
318
-
319
-		// TODO: DI
320
-		$client = \OC::$server->getHTTPClientService()->newClient();
321
-		try {
322
-			$response = $client->post($url, [
323
-				'body' => ['password' => $password],
324
-				'timeout' => 10,
325
-				'connect_timeout' => 10,
326
-			]);
327
-		} catch (\GuzzleHttp\Exception\RequestException $e) {
328
-			if ($e->getCode() === Http::STATUS_UNAUTHORIZED || $e->getCode() === Http::STATUS_FORBIDDEN) {
329
-				throw new ForbiddenException();
330
-			}
331
-			if ($e->getCode() === Http::STATUS_NOT_FOUND) {
332
-				throw new NotFoundException();
333
-			}
334
-			// throw this to be on the safe side: the share will still be visible
335
-			// in the UI in case the failure is intermittent, and the user will
336
-			// be able to decide whether to remove it if it's really gone
337
-			throw new StorageNotAvailableException();
338
-		}
339
-
340
-		return json_decode($response->getBody(), true);
341
-	}
342
-
343
-	public function getOwner($path) {
344
-		return $this->cloudId->getDisplayId();
345
-	}
346
-
347
-	public function isSharable($path) {
348
-		if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
349
-			return false;
350
-		}
351
-		return ($this->getPermissions($path) & Constants::PERMISSION_SHARE);
352
-	}
353
-
354
-	public function getPermissions($path) {
355
-		$response = $this->propfind($path);
356
-		// old federated sharing permissions
357
-		if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) {
358
-			$permissions = $response['{http://open-collaboration-services.org/ns}share-permissions'];
359
-		} else if (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) {
360
-			// permissions provided by the OCM API
361
-			$permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions']);
362
-		} else {
363
-			// use default permission if remote server doesn't provide the share permissions
364
-			$permissions = $this->getDefaultPermissions($path);
365
-		}
366
-
367
-		return $permissions;
368
-	}
369
-
370
-	public function needsPartFile() {
371
-		return false;
372
-	}
373
-
374
-	/**
375
-	 * translate OCM Permissions to Nextcloud permissions
376
-	 *
377
-	 * @param string $ocmPermissions json encoded OCM permissions
378
-	 * @param string $path path to file
379
-	 * @return int
380
-	 */
381
-	protected function ocmPermissions2ncPermissions($ocmPermissions, $path) {
382
-		try {
383
-			$ocmPermissions = json_decode($ocmPermissions);
384
-			$ncPermissions = 0;
385
-			foreach($ocmPermissions as $permission) {
386
-				switch (strtolower($permission)) {
387
-					case 'read':
388
-						$ncPermissions += Constants::PERMISSION_READ;
389
-						break;
390
-					case 'write':
391
-						$ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
392
-						break;
393
-					case 'share':
394
-						$ncPermissions += Constants::PERMISSION_SHARE;
395
-						break;
396
-					default:
397
-						throw new \Exception();
398
-				}
399
-			}
400
-		} catch (\Exception $e) {
401
-			$ncPermissions = $this->getDefaultPermissions($path);
402
-		}
403
-
404
-		return $ncPermissions;
405
-	}
406
-
407
-	/**
408
-	 * calculate default permissions in case no permissions are provided
409
-	 *
410
-	 * @param $path
411
-	 * @return int
412
-	 */
413
-	protected function getDefaultPermissions($path) {
414
-		if ($this->is_dir($path)) {
415
-			$permissions = Constants::PERMISSION_ALL;
416
-		} else {
417
-			$permissions = Constants::PERMISSION_ALL & ~Constants::PERMISSION_CREATE;
418
-		}
419
-
420
-		return $permissions;
421
-	}
46
+    /** @var ICloudId */
47
+    private $cloudId;
48
+    /** @var string */
49
+    private $mountPoint;
50
+    /** @var string */
51
+    private $token;
52
+    /** @var \OCP\ICacheFactory */
53
+    private $memcacheFactory;
54
+    /** @var \OCP\Http\Client\IClientService */
55
+    private $httpClient;
56
+    /** @var bool */
57
+    private $updateChecked = false;
58
+
59
+    /**
60
+     * @var \OCA\Files_Sharing\External\Manager
61
+     */
62
+    private $manager;
63
+
64
+    public function __construct($options) {
65
+        $this->memcacheFactory = \OC::$server->getMemCacheFactory();
66
+        $this->httpClient = $options['HttpClientService'];
67
+
68
+        $this->manager = $options['manager'];
69
+        $this->cloudId = $options['cloudId'];
70
+        $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
71
+
72
+        list($protocol, $remote) = explode('://', $this->cloudId->getRemote());
73
+        if (strpos($remote, '/')) {
74
+            list($host, $root) = explode('/', $remote, 2);
75
+        } else {
76
+            $host = $remote;
77
+            $root = '';
78
+        }
79
+        $secure = $protocol === 'https';
80
+        $federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81
+        $webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
+        $root = rtrim($root, '/') . $webDavEndpoint;
83
+        $this->mountPoint = $options['mountpoint'];
84
+        $this->token = $options['token'];
85
+
86
+        parent::__construct(array(
87
+            'secure' => $secure,
88
+            'host' => $host,
89
+            'root' => $root,
90
+            'user' => $options['token'],
91
+            'password' => (string)$options['password']
92
+        ));
93
+    }
94
+
95
+    public function getWatcher($path = '', $storage = null) {
96
+        if (!$storage) {
97
+            $storage = $this;
98
+        }
99
+        if (!isset($this->watcher)) {
100
+            $this->watcher = new Watcher($storage);
101
+            $this->watcher->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
102
+        }
103
+        return $this->watcher;
104
+    }
105
+
106
+    public function getRemoteUser() {
107
+        return $this->cloudId->getUser();
108
+    }
109
+
110
+    public function getRemote() {
111
+        return $this->cloudId->getRemote();
112
+    }
113
+
114
+    public function getMountPoint() {
115
+        return $this->mountPoint;
116
+    }
117
+
118
+    public function getToken() {
119
+        return $this->token;
120
+    }
121
+
122
+    public function getPassword() {
123
+        return $this->password;
124
+    }
125
+
126
+    /**
127
+     * @brief get id of the mount point
128
+     * @return string
129
+     */
130
+    public function getId() {
131
+        return 'shared::' . md5($this->token . '@' . $this->getRemote());
132
+    }
133
+
134
+    public function getCache($path = '', $storage = null) {
135
+        if (is_null($this->cache)) {
136
+            $this->cache = new Cache($this, $this->cloudId);
137
+        }
138
+        return $this->cache;
139
+    }
140
+
141
+    /**
142
+     * @param string $path
143
+     * @param \OC\Files\Storage\Storage $storage
144
+     * @return \OCA\Files_Sharing\External\Scanner
145
+     */
146
+    public function getScanner($path = '', $storage = null) {
147
+        if (!$storage) {
148
+            $storage = $this;
149
+        }
150
+        if (!isset($this->scanner)) {
151
+            $this->scanner = new Scanner($storage);
152
+        }
153
+        return $this->scanner;
154
+    }
155
+
156
+    /**
157
+     * check if a file or folder has been updated since $time
158
+     *
159
+     * @param string $path
160
+     * @param int $time
161
+     * @throws \OCP\Files\StorageNotAvailableException
162
+     * @throws \OCP\Files\StorageInvalidException
163
+     * @return bool
164
+     */
165
+    public function hasUpdated($path, $time) {
166
+        // since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage
167
+        // because of that we only do one check for the entire storage per request
168
+        if ($this->updateChecked) {
169
+            return false;
170
+        }
171
+        $this->updateChecked = true;
172
+        try {
173
+            return parent::hasUpdated('', $time);
174
+        } catch (StorageInvalidException $e) {
175
+            // check if it needs to be removed
176
+            $this->checkStorageAvailability();
177
+            throw $e;
178
+        } catch (StorageNotAvailableException $e) {
179
+            // check if it needs to be removed or just temp unavailable
180
+            $this->checkStorageAvailability();
181
+            throw $e;
182
+        }
183
+    }
184
+
185
+    public function test() {
186
+        try {
187
+            return parent::test();
188
+        } catch (StorageInvalidException $e) {
189
+            // check if it needs to be removed
190
+            $this->checkStorageAvailability();
191
+            throw $e;
192
+        } catch (StorageNotAvailableException $e) {
193
+            // check if it needs to be removed or just temp unavailable
194
+            $this->checkStorageAvailability();
195
+            throw $e;
196
+        }
197
+    }
198
+
199
+    /**
200
+     * Check whether this storage is permanently or temporarily
201
+     * unavailable
202
+     *
203
+     * @throws \OCP\Files\StorageNotAvailableException
204
+     * @throws \OCP\Files\StorageInvalidException
205
+     */
206
+    public function checkStorageAvailability() {
207
+        // see if we can find out why the share is unavailable
208
+        try {
209
+            $this->getShareInfo();
210
+        } catch (NotFoundException $e) {
211
+            // a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
212
+            if ($this->testRemote()) {
213
+                // valid Nextcloud instance means that the public share no longer exists
214
+                // since this is permanent (re-sharing the file will create a new token)
215
+                // we remove the invalid storage
216
+                $this->manager->removeShare($this->mountPoint);
217
+                $this->manager->getMountManager()->removeMount($this->mountPoint);
218
+                throw new StorageInvalidException();
219
+            } else {
220
+                // Nextcloud instance is gone, likely to be a temporary server configuration error
221
+                throw new StorageNotAvailableException();
222
+            }
223
+        } catch (ForbiddenException $e) {
224
+            // auth error, remove share for now (provide a dialog in the future)
225
+            $this->manager->removeShare($this->mountPoint);
226
+            $this->manager->getMountManager()->removeMount($this->mountPoint);
227
+            throw new StorageInvalidException();
228
+        } catch (\GuzzleHttp\Exception\ConnectException $e) {
229
+            throw new StorageNotAvailableException();
230
+        } catch (\GuzzleHttp\Exception\RequestException $e) {
231
+            throw new StorageNotAvailableException();
232
+        } catch (\Exception $e) {
233
+            throw $e;
234
+        }
235
+    }
236
+
237
+    public function file_exists($path) {
238
+        if ($path === '') {
239
+            return true;
240
+        } else {
241
+            return parent::file_exists($path);
242
+        }
243
+    }
244
+
245
+    /**
246
+     * check if the configured remote is a valid federated share provider
247
+     *
248
+     * @return bool
249
+     */
250
+    protected function testRemote() {
251
+        try {
252
+            return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
+                || $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
+                || $this->testRemoteUrl($this->getRemote() . '/status.php');
255
+        } catch (\Exception $e) {
256
+            return false;
257
+        }
258
+    }
259
+
260
+    /**
261
+     * @param string $url
262
+     * @return bool
263
+     */
264
+    private function testRemoteUrl($url) {
265
+        $cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
+        if($cache->hasKey($url)) {
267
+            return (bool)$cache->get($url);
268
+        }
269
+
270
+        $client = $this->httpClient->newClient();
271
+        try {
272
+            $result = $client->get($url, [
273
+                'timeout' => 10,
274
+                'connect_timeout' => 10,
275
+            ])->getBody();
276
+            $data = json_decode($result);
277
+            $returnValue = (is_object($data) && !empty($data->version));
278
+        } catch (ConnectException $e) {
279
+            $returnValue = false;
280
+        } catch (ClientException $e) {
281
+            $returnValue = false;
282
+        }
283
+
284
+        $cache->set($url, $returnValue, 60*60*24);
285
+        return $returnValue;
286
+    }
287
+
288
+    /**
289
+     * Whether the remote is an ownCloud/Nextcloud, used since some sharing features are not
290
+     * standardized. Let's use this to detect whether to use it.
291
+     *
292
+     * @return bool
293
+     */
294
+    public function remoteIsOwnCloud() {
295
+        if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
296
+            return false;
297
+        }
298
+        return true;
299
+    }
300
+
301
+    /**
302
+     * @return mixed
303
+     * @throws ForbiddenException
304
+     * @throws NotFoundException
305
+     * @throws \Exception
306
+     */
307
+    public function getShareInfo() {
308
+        $remote = $this->getRemote();
309
+        $token = $this->getToken();
310
+        $password = $this->getPassword();
311
+
312
+        // If remote is not an ownCloud do not try to get any share info
313
+        if(!$this->remoteIsOwnCloud()) {
314
+            return ['status' => 'unsupported'];
315
+        }
316
+
317
+        $url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
318
+
319
+        // TODO: DI
320
+        $client = \OC::$server->getHTTPClientService()->newClient();
321
+        try {
322
+            $response = $client->post($url, [
323
+                'body' => ['password' => $password],
324
+                'timeout' => 10,
325
+                'connect_timeout' => 10,
326
+            ]);
327
+        } catch (\GuzzleHttp\Exception\RequestException $e) {
328
+            if ($e->getCode() === Http::STATUS_UNAUTHORIZED || $e->getCode() === Http::STATUS_FORBIDDEN) {
329
+                throw new ForbiddenException();
330
+            }
331
+            if ($e->getCode() === Http::STATUS_NOT_FOUND) {
332
+                throw new NotFoundException();
333
+            }
334
+            // throw this to be on the safe side: the share will still be visible
335
+            // in the UI in case the failure is intermittent, and the user will
336
+            // be able to decide whether to remove it if it's really gone
337
+            throw new StorageNotAvailableException();
338
+        }
339
+
340
+        return json_decode($response->getBody(), true);
341
+    }
342
+
343
+    public function getOwner($path) {
344
+        return $this->cloudId->getDisplayId();
345
+    }
346
+
347
+    public function isSharable($path) {
348
+        if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
349
+            return false;
350
+        }
351
+        return ($this->getPermissions($path) & Constants::PERMISSION_SHARE);
352
+    }
353
+
354
+    public function getPermissions($path) {
355
+        $response = $this->propfind($path);
356
+        // old federated sharing permissions
357
+        if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) {
358
+            $permissions = $response['{http://open-collaboration-services.org/ns}share-permissions'];
359
+        } else if (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) {
360
+            // permissions provided by the OCM API
361
+            $permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions']);
362
+        } else {
363
+            // use default permission if remote server doesn't provide the share permissions
364
+            $permissions = $this->getDefaultPermissions($path);
365
+        }
366
+
367
+        return $permissions;
368
+    }
369
+
370
+    public function needsPartFile() {
371
+        return false;
372
+    }
373
+
374
+    /**
375
+     * translate OCM Permissions to Nextcloud permissions
376
+     *
377
+     * @param string $ocmPermissions json encoded OCM permissions
378
+     * @param string $path path to file
379
+     * @return int
380
+     */
381
+    protected function ocmPermissions2ncPermissions($ocmPermissions, $path) {
382
+        try {
383
+            $ocmPermissions = json_decode($ocmPermissions);
384
+            $ncPermissions = 0;
385
+            foreach($ocmPermissions as $permission) {
386
+                switch (strtolower($permission)) {
387
+                    case 'read':
388
+                        $ncPermissions += Constants::PERMISSION_READ;
389
+                        break;
390
+                    case 'write':
391
+                        $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
392
+                        break;
393
+                    case 'share':
394
+                        $ncPermissions += Constants::PERMISSION_SHARE;
395
+                        break;
396
+                    default:
397
+                        throw new \Exception();
398
+                }
399
+            }
400
+        } catch (\Exception $e) {
401
+            $ncPermissions = $this->getDefaultPermissions($path);
402
+        }
403
+
404
+        return $ncPermissions;
405
+    }
406
+
407
+    /**
408
+     * calculate default permissions in case no permissions are provided
409
+     *
410
+     * @param $path
411
+     * @return int
412
+     */
413
+    protected function getDefaultPermissions($path) {
414
+        if ($this->is_dir($path)) {
415
+            $permissions = Constants::PERMISSION_ALL;
416
+        } else {
417
+            $permissions = Constants::PERMISSION_ALL & ~Constants::PERMISSION_CREATE;
418
+        }
419
+
420
+        return $permissions;
421
+    }
422 422
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		$secure = $protocol === 'https';
80 80
 		$federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81 81
 		$webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
-		$root = rtrim($root, '/') . $webDavEndpoint;
82
+		$root = rtrim($root, '/').$webDavEndpoint;
83 83
 		$this->mountPoint = $options['mountpoint'];
84 84
 		$this->token = $options['token'];
85 85
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			'host' => $host,
89 89
 			'root' => $root,
90 90
 			'user' => $options['token'],
91
-			'password' => (string)$options['password']
91
+			'password' => (string) $options['password']
92 92
 		));
93 93
 	}
94 94
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return string
129 129
 	 */
130 130
 	public function getId() {
131
-		return 'shared::' . md5($this->token . '@' . $this->getRemote());
131
+		return 'shared::'.md5($this->token.'@'.$this->getRemote());
132 132
 	}
133 133
 
134 134
 	public function getCache($path = '', $storage = null) {
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 	 */
250 250
 	protected function testRemote() {
251 251
 		try {
252
-			return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
-				|| $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
-				|| $this->testRemoteUrl($this->getRemote() . '/status.php');
252
+			return $this->testRemoteUrl($this->getRemote().'/ocs-provider/index.php')
253
+				|| $this->testRemoteUrl($this->getRemote().'/ocs-provider/')
254
+				|| $this->testRemoteUrl($this->getRemote().'/status.php');
255 255
 		} catch (\Exception $e) {
256 256
 			return false;
257 257
 		}
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 */
264 264
 	private function testRemoteUrl($url) {
265 265
 		$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
-		if($cache->hasKey($url)) {
267
-			return (bool)$cache->get($url);
266
+		if ($cache->hasKey($url)) {
267
+			return (bool) $cache->get($url);
268 268
 		}
269 269
 
270 270
 		$client = $this->httpClient->newClient();
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 			$returnValue = false;
282 282
 		}
283 283
 
284
-		$cache->set($url, $returnValue, 60*60*24);
284
+		$cache->set($url, $returnValue, 60 * 60 * 24);
285 285
 		return $returnValue;
286 286
 	}
287 287
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return bool
293 293
 	 */
294 294
 	public function remoteIsOwnCloud() {
295
-		if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
295
+		if (defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote().'/status.php')) {
296 296
 			return false;
297 297
 		}
298 298
 		return true;
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
 		$password = $this->getPassword();
311 311
 
312 312
 		// If remote is not an ownCloud do not try to get any share info
313
-		if(!$this->remoteIsOwnCloud()) {
313
+		if (!$this->remoteIsOwnCloud()) {
314 314
 			return ['status' => 'unsupported'];
315 315
 		}
316 316
 
317
-		$url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
317
+		$url = rtrim($remote, '/').'/index.php/apps/files_sharing/shareinfo?t='.$token;
318 318
 
319 319
 		// TODO: DI
320 320
 		$client = \OC::$server->getHTTPClientService()->newClient();
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		try {
383 383
 			$ocmPermissions = json_decode($ocmPermissions);
384 384
 			$ncPermissions = 0;
385
-			foreach($ocmPermissions as $permission) {
385
+			foreach ($ocmPermissions as $permission) {
386 386
 				switch (strtolower($permission)) {
387 387
 					case 'read':
388 388
 						$ncPermissions += Constants::PERMISSION_READ;
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesPlugin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 	/**
451 451
 	 * translate Nextcloud permissions to OCM Permissions
452 452
 	 *
453
-	 * @param $ncPermissions
453
+	 * @param integer $ncPermissions
454 454
 	 * @return array
455 455
 	 */
456 456
 	protected function ncPermissions2ocmPermissions($ncPermissions) {
Please login to merge, or discard this patch.
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -50,444 +50,444 @@
 block discarded – undo
50 50
 
51 51
 class FilesPlugin extends ServerPlugin {
52 52
 
53
-	// namespace
54
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
55
-	const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
56
-	const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
57
-	const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
58
-	const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
59
-	const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
60
-	const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
61
-	const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
62
-	const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
63
-	const GETETAG_PROPERTYNAME = '{DAV:}getetag';
64
-	const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
65
-	const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
66
-	const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
67
-	const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
68
-	const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
69
-	const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
70
-	const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
71
-	const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
72
-
73
-	/**
74
-	 * Reference to main server object
75
-	 *
76
-	 * @var \Sabre\DAV\Server
77
-	 */
78
-	private $server;
79
-
80
-	/**
81
-	 * @var Tree
82
-	 */
83
-	private $tree;
84
-
85
-	/**
86
-	 * Whether this is public webdav.
87
-	 * If true, some returned information will be stripped off.
88
-	 *
89
-	 * @var bool
90
-	 */
91
-	private $isPublic;
92
-
93
-	/**
94
-	 * @var bool
95
-	 */
96
-	private $downloadAttachment;
97
-
98
-	/**
99
-	 * @var IConfig
100
-	 */
101
-	private $config;
102
-
103
-	/**
104
-	 * @var IRequest
105
-	 */
106
-	private $request;
107
-
108
-	/**
109
-	 * @var IPreview
110
-	 */
111
-	private $previewManager;
112
-
113
-	/**
114
-	 * @param Tree $tree
115
-	 * @param IConfig $config
116
-	 * @param IRequest $request
117
-	 * @param IPreview $previewManager
118
-	 * @param bool $isPublic
119
-	 * @param bool $downloadAttachment
120
-	 */
121
-	public function __construct(Tree $tree,
122
-								IConfig $config,
123
-								IRequest $request,
124
-								IPreview $previewManager,
125
-								$isPublic = false,
126
-								$downloadAttachment = true) {
127
-		$this->tree = $tree;
128
-		$this->config = $config;
129
-		$this->request = $request;
130
-		$this->isPublic = $isPublic;
131
-		$this->downloadAttachment = $downloadAttachment;
132
-		$this->previewManager = $previewManager;
133
-	}
134
-
135
-	/**
136
-	 * This initializes the plugin.
137
-	 *
138
-	 * This function is called by \Sabre\DAV\Server, after
139
-	 * addPlugin is called.
140
-	 *
141
-	 * This method should set up the required event subscriptions.
142
-	 *
143
-	 * @param \Sabre\DAV\Server $server
144
-	 * @return void
145
-	 */
146
-	public function initialize(\Sabre\DAV\Server $server) {
147
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
148
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
149
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
150
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
151
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
152
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
153
-		$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
154
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
155
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
163
-
164
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
165
-		$allowedProperties = ['{DAV:}getetag'];
166
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
167
-
168
-		$this->server = $server;
169
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
170
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
171
-		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
172
-		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
173
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
174
-		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
175
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
176
-			$body = $response->getBody();
177
-			if (is_resource($body)) {
178
-				fclose($body);
179
-			}
180
-		});
181
-		$this->server->on('beforeMove', [$this, 'checkMove']);
182
-	}
183
-
184
-	/**
185
-	 * Plugin that checks if a move can actually be performed.
186
-	 *
187
-	 * @param string $source source path
188
-	 * @param string $destination destination path
189
-	 * @throws Forbidden
190
-	 * @throws NotFound
191
-	 */
192
-	function checkMove($source, $destination) {
193
-		$sourceNode = $this->tree->getNodeForPath($source);
194
-		if (!$sourceNode instanceof Node) {
195
-			return;
196
-		}
197
-		list($sourceDir,) = \Sabre\Uri\split($source);
198
-		list($destinationDir,) = \Sabre\Uri\split($destination);
199
-
200
-		if ($sourceDir !== $destinationDir) {
201
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
202
-			if ($sourceNodeFileInfo === null) {
203
-				throw new NotFound($source . ' does not exist');
204
- 			}
205
-
206
-			if (!$sourceNodeFileInfo->isDeletable()) {
207
-				throw new Forbidden($source . " cannot be deleted");
208
-			}
209
-		}
210
-	}
211
-
212
-	/**
213
-	 * This sets a cookie to be able to recognize the start of the download
214
-	 * the content must not be longer than 32 characters and must only contain
215
-	 * alphanumeric characters
216
-	 *
217
-	 * @param RequestInterface $request
218
-	 * @param ResponseInterface $response
219
-	 */
220
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
221
-		$queryParams = $request->getQueryParameters();
222
-
223
-		/**
224
-		 * this sets a cookie to be able to recognize the start of the download
225
-		 * the content must not be longer than 32 characters and must only contain
226
-		 * alphanumeric characters
227
-		 */
228
-		if (isset($queryParams['downloadStartSecret'])) {
229
-			$token = $queryParams['downloadStartSecret'];
230
-			if (!isset($token[32])
231
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
232
-				// FIXME: use $response->setHeader() instead
233
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
234
-			}
235
-		}
236
-	}
237
-
238
-	/**
239
-	 * Add headers to file download
240
-	 *
241
-	 * @param RequestInterface $request
242
-	 * @param ResponseInterface $response
243
-	 */
244
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
245
-		// Only handle valid files
246
-		$node = $this->tree->getNodeForPath($request->getPath());
247
-		if (!($node instanceof IFile)) return;
248
-
249
-		// adds a 'Content-Disposition: attachment' header in case no disposition
250
-		// header has been set before
251
-		if ($this->downloadAttachment &&
252
-			$response->getHeader('Content-Disposition') === null) {
253
-			$filename = $node->getName();
254
-			if ($this->request->isUserAgent(
255
-				[
256
-					Request::USER_AGENT_IE,
257
-					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
258
-					Request::USER_AGENT_FREEBOX,
259
-				])) {
260
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
261
-			} else {
262
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
263
-													 . '; filename="' . rawurlencode($filename) . '"');
264
-			}
265
-		}
266
-
267
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
268
-			//Add OC-Checksum header
269
-			/** @var $node File */
270
-			$checksum = $node->getChecksum();
271
-			if ($checksum !== null && $checksum !== '') {
272
-				$response->addHeader('OC-Checksum', $checksum);
273
-			}
274
-		}
275
-	}
276
-
277
-	/**
278
-	 * Adds all ownCloud-specific properties
279
-	 *
280
-	 * @param PropFind $propFind
281
-	 * @param \Sabre\DAV\INode $node
282
-	 * @return void
283
-	 */
284
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
285
-
286
-		$httpRequest = $this->server->httpRequest;
287
-
288
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
289
-			/**
290
-			 * This was disabled, because it made dir listing throw an exception,
291
-			 * so users were unable to navigate into folders where one subitem
292
-			 * is blocked by the files_accesscontrol app, see:
293
-			 * https://github.com/nextcloud/files_accesscontrol/issues/65
53
+    // namespace
54
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
55
+    const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
56
+    const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
57
+    const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
58
+    const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
59
+    const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
60
+    const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
61
+    const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
62
+    const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
63
+    const GETETAG_PROPERTYNAME = '{DAV:}getetag';
64
+    const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
65
+    const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
66
+    const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
67
+    const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
68
+    const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
69
+    const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
70
+    const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
71
+    const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
72
+
73
+    /**
74
+     * Reference to main server object
75
+     *
76
+     * @var \Sabre\DAV\Server
77
+     */
78
+    private $server;
79
+
80
+    /**
81
+     * @var Tree
82
+     */
83
+    private $tree;
84
+
85
+    /**
86
+     * Whether this is public webdav.
87
+     * If true, some returned information will be stripped off.
88
+     *
89
+     * @var bool
90
+     */
91
+    private $isPublic;
92
+
93
+    /**
94
+     * @var bool
95
+     */
96
+    private $downloadAttachment;
97
+
98
+    /**
99
+     * @var IConfig
100
+     */
101
+    private $config;
102
+
103
+    /**
104
+     * @var IRequest
105
+     */
106
+    private $request;
107
+
108
+    /**
109
+     * @var IPreview
110
+     */
111
+    private $previewManager;
112
+
113
+    /**
114
+     * @param Tree $tree
115
+     * @param IConfig $config
116
+     * @param IRequest $request
117
+     * @param IPreview $previewManager
118
+     * @param bool $isPublic
119
+     * @param bool $downloadAttachment
120
+     */
121
+    public function __construct(Tree $tree,
122
+                                IConfig $config,
123
+                                IRequest $request,
124
+                                IPreview $previewManager,
125
+                                $isPublic = false,
126
+                                $downloadAttachment = true) {
127
+        $this->tree = $tree;
128
+        $this->config = $config;
129
+        $this->request = $request;
130
+        $this->isPublic = $isPublic;
131
+        $this->downloadAttachment = $downloadAttachment;
132
+        $this->previewManager = $previewManager;
133
+    }
134
+
135
+    /**
136
+     * This initializes the plugin.
137
+     *
138
+     * This function is called by \Sabre\DAV\Server, after
139
+     * addPlugin is called.
140
+     *
141
+     * This method should set up the required event subscriptions.
142
+     *
143
+     * @param \Sabre\DAV\Server $server
144
+     * @return void
145
+     */
146
+    public function initialize(\Sabre\DAV\Server $server) {
147
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
148
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
149
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
150
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
151
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
152
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
153
+        $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
154
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
155
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
163
+
164
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
165
+        $allowedProperties = ['{DAV:}getetag'];
166
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
167
+
168
+        $this->server = $server;
169
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
170
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
171
+        $this->server->on('afterBind', array($this, 'sendFileIdHeader'));
172
+        $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
173
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
174
+        $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
175
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
176
+            $body = $response->getBody();
177
+            if (is_resource($body)) {
178
+                fclose($body);
179
+            }
180
+        });
181
+        $this->server->on('beforeMove', [$this, 'checkMove']);
182
+    }
183
+
184
+    /**
185
+     * Plugin that checks if a move can actually be performed.
186
+     *
187
+     * @param string $source source path
188
+     * @param string $destination destination path
189
+     * @throws Forbidden
190
+     * @throws NotFound
191
+     */
192
+    function checkMove($source, $destination) {
193
+        $sourceNode = $this->tree->getNodeForPath($source);
194
+        if (!$sourceNode instanceof Node) {
195
+            return;
196
+        }
197
+        list($sourceDir,) = \Sabre\Uri\split($source);
198
+        list($destinationDir,) = \Sabre\Uri\split($destination);
199
+
200
+        if ($sourceDir !== $destinationDir) {
201
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
202
+            if ($sourceNodeFileInfo === null) {
203
+                throw new NotFound($source . ' does not exist');
204
+                }
205
+
206
+            if (!$sourceNodeFileInfo->isDeletable()) {
207
+                throw new Forbidden($source . " cannot be deleted");
208
+            }
209
+        }
210
+    }
211
+
212
+    /**
213
+     * This sets a cookie to be able to recognize the start of the download
214
+     * the content must not be longer than 32 characters and must only contain
215
+     * alphanumeric characters
216
+     *
217
+     * @param RequestInterface $request
218
+     * @param ResponseInterface $response
219
+     */
220
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
221
+        $queryParams = $request->getQueryParameters();
222
+
223
+        /**
224
+         * this sets a cookie to be able to recognize the start of the download
225
+         * the content must not be longer than 32 characters and must only contain
226
+         * alphanumeric characters
227
+         */
228
+        if (isset($queryParams['downloadStartSecret'])) {
229
+            $token = $queryParams['downloadStartSecret'];
230
+            if (!isset($token[32])
231
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
232
+                // FIXME: use $response->setHeader() instead
233
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
234
+            }
235
+        }
236
+    }
237
+
238
+    /**
239
+     * Add headers to file download
240
+     *
241
+     * @param RequestInterface $request
242
+     * @param ResponseInterface $response
243
+     */
244
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
245
+        // Only handle valid files
246
+        $node = $this->tree->getNodeForPath($request->getPath());
247
+        if (!($node instanceof IFile)) return;
248
+
249
+        // adds a 'Content-Disposition: attachment' header in case no disposition
250
+        // header has been set before
251
+        if ($this->downloadAttachment &&
252
+            $response->getHeader('Content-Disposition') === null) {
253
+            $filename = $node->getName();
254
+            if ($this->request->isUserAgent(
255
+                [
256
+                    Request::USER_AGENT_IE,
257
+                    Request::USER_AGENT_ANDROID_MOBILE_CHROME,
258
+                    Request::USER_AGENT_FREEBOX,
259
+                ])) {
260
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
261
+            } else {
262
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
263
+                                                        . '; filename="' . rawurlencode($filename) . '"');
264
+            }
265
+        }
266
+
267
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
268
+            //Add OC-Checksum header
269
+            /** @var $node File */
270
+            $checksum = $node->getChecksum();
271
+            if ($checksum !== null && $checksum !== '') {
272
+                $response->addHeader('OC-Checksum', $checksum);
273
+            }
274
+        }
275
+    }
276
+
277
+    /**
278
+     * Adds all ownCloud-specific properties
279
+     *
280
+     * @param PropFind $propFind
281
+     * @param \Sabre\DAV\INode $node
282
+     * @return void
283
+     */
284
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
285
+
286
+        $httpRequest = $this->server->httpRequest;
287
+
288
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
289
+            /**
290
+             * This was disabled, because it made dir listing throw an exception,
291
+             * so users were unable to navigate into folders where one subitem
292
+             * is blocked by the files_accesscontrol app, see:
293
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
294 294
 			if (!$node->getFileInfo()->isReadable()) {
295 295
 				// avoid detecting files through this means
296 296
 				throw new NotFound();
297 297
 			}
298
-			 */
299
-
300
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
301
-				return $node->getFileId();
302
-			});
303
-
304
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
305
-				return $node->getInternalFileId();
306
-			});
307
-
308
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
309
-				$perms = $node->getDavPermissions();
310
-				if ($this->isPublic) {
311
-					// remove mount information
312
-					$perms = str_replace(['S', 'M'], '', $perms);
313
-				}
314
-				return $perms;
315
-			});
316
-
317
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
318
-				return $node->getSharePermissions(
319
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
320
-				);
321
-			});
322
-
323
-			$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
-				$ncPermissions = $node->getSharePermissions(
325
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
326
-				);
327
-				$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
328
-				return json_encode($ocmPermissions);
329
-			});
330
-
331
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
332
-				return $node->getETag();
333
-			});
334
-
335
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
336
-				$owner = $node->getOwner();
337
-				if (!$owner) {
338
-					return null;
339
-				} else {
340
-					return $owner->getUID();
341
-				}
342
-			});
343
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
344
-				$owner = $node->getOwner();
345
-				if (!$owner) {
346
-					return null;
347
-				} else {
348
-					return $owner->getDisplayName();
349
-				}
350
-			});
351
-
352
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
353
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
354
-			});
355
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
356
-				return $node->getSize();
357
-			});
358
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
359
-				return $node->getFileInfo()->getMountPoint()->getMountType();
360
-			});
361
-		}
362
-
363
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
364
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
365
-				return $this->config->getSystemValue('data-fingerprint', '');
366
-			});
367
-		}
368
-
369
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
370
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
371
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
372
-				try {
373
-					$directDownloadUrl = $node->getDirectDownload();
374
-					if (isset($directDownloadUrl['url'])) {
375
-						return $directDownloadUrl['url'];
376
-					}
377
-				} catch (StorageNotAvailableException $e) {
378
-					return false;
379
-				} catch (ForbiddenException $e) {
380
-					return false;
381
-				}
382
-				return false;
383
-			});
384
-
385
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
386
-				$checksum = $node->getChecksum();
387
-				if ($checksum === NULL || $checksum === '') {
388
-					return null;
389
-				}
390
-
391
-				return new ChecksumList($checksum);
392
-			});
393
-
394
-		}
395
-
396
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
397
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
398
-				return $node->getSize();
399
-			});
400
-
401
-			$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
402
-				return $node->getFileInfo()->isEncrypted() ? '1' : '0';
403
-			});
404
-		}
405
-	}
406
-
407
-	/**
408
-	 * translate Nextcloud permissions to OCM Permissions
409
-	 *
410
-	 * @param $ncPermissions
411
-	 * @return array
412
-	 */
413
-	protected function ncPermissions2ocmPermissions($ncPermissions) {
414
-
415
-		$ocmPermissions = [];
416
-
417
-		if ($ncPermissions & Constants::PERMISSION_SHARE) {
418
-			$ocmPermissions[] = 'share';
419
-		}
420
-
421
-		if ($ncPermissions & Constants::PERMISSION_READ) {
422
-			$ocmPermissions[] = 'read';
423
-		}
424
-
425
-		if (($ncPermissions & Constants::PERMISSION_CREATE) ||
426
-			($ncPermissions & Constants::PERMISSION_UPDATE)) {
427
-			$ocmPermissions[] = 'write';
428
-		}
429
-
430
-		return $ocmPermissions;
431
-
432
-	}
433
-
434
-	/**
435
-	 * Update ownCloud-specific properties
436
-	 *
437
-	 * @param string $path
438
-	 * @param PropPatch $propPatch
439
-	 *
440
-	 * @return void
441
-	 */
442
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
443
-		$node = $this->tree->getNodeForPath($path);
444
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
445
-			return;
446
-		}
447
-
448
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
449
-			if (empty($time)) {
450
-				return false;
451
-			}
452
-			$node->touch($time);
453
-			return true;
454
-		});
455
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
456
-			if (empty($etag)) {
457
-				return false;
458
-			}
459
-			if ($node->setEtag($etag) !== -1) {
460
-				return true;
461
-			}
462
-			return false;
463
-		});
464
-	}
465
-
466
-	/**
467
-	 * @param string $filePath
468
-	 * @param \Sabre\DAV\INode $node
469
-	 * @throws \Sabre\DAV\Exception\BadRequest
470
-	 */
471
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
472
-		// chunked upload handling
473
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
474
-			list($path, $name) = \Sabre\Uri\split($filePath);
475
-			$info = \OC_FileChunking::decodeName($name);
476
-			if (!empty($info)) {
477
-				$filePath = $path . '/' . $info['name'];
478
-			}
479
-		}
480
-
481
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
482
-		if (!$this->server->tree->nodeExists($filePath)) {
483
-			return;
484
-		}
485
-		$node = $this->server->tree->getNodeForPath($filePath);
486
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
487
-			$fileId = $node->getFileId();
488
-			if (!is_null($fileId)) {
489
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
490
-			}
491
-		}
492
-	}
298
+             */
299
+
300
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
301
+                return $node->getFileId();
302
+            });
303
+
304
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
305
+                return $node->getInternalFileId();
306
+            });
307
+
308
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
309
+                $perms = $node->getDavPermissions();
310
+                if ($this->isPublic) {
311
+                    // remove mount information
312
+                    $perms = str_replace(['S', 'M'], '', $perms);
313
+                }
314
+                return $perms;
315
+            });
316
+
317
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
318
+                return $node->getSharePermissions(
319
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
320
+                );
321
+            });
322
+
323
+            $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
+                $ncPermissions = $node->getSharePermissions(
325
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
326
+                );
327
+                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
328
+                return json_encode($ocmPermissions);
329
+            });
330
+
331
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
332
+                return $node->getETag();
333
+            });
334
+
335
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
336
+                $owner = $node->getOwner();
337
+                if (!$owner) {
338
+                    return null;
339
+                } else {
340
+                    return $owner->getUID();
341
+                }
342
+            });
343
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
344
+                $owner = $node->getOwner();
345
+                if (!$owner) {
346
+                    return null;
347
+                } else {
348
+                    return $owner->getDisplayName();
349
+                }
350
+            });
351
+
352
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
353
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
354
+            });
355
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
356
+                return $node->getSize();
357
+            });
358
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
359
+                return $node->getFileInfo()->getMountPoint()->getMountType();
360
+            });
361
+        }
362
+
363
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
364
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
365
+                return $this->config->getSystemValue('data-fingerprint', '');
366
+            });
367
+        }
368
+
369
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
370
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
371
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
372
+                try {
373
+                    $directDownloadUrl = $node->getDirectDownload();
374
+                    if (isset($directDownloadUrl['url'])) {
375
+                        return $directDownloadUrl['url'];
376
+                    }
377
+                } catch (StorageNotAvailableException $e) {
378
+                    return false;
379
+                } catch (ForbiddenException $e) {
380
+                    return false;
381
+                }
382
+                return false;
383
+            });
384
+
385
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
386
+                $checksum = $node->getChecksum();
387
+                if ($checksum === NULL || $checksum === '') {
388
+                    return null;
389
+                }
390
+
391
+                return new ChecksumList($checksum);
392
+            });
393
+
394
+        }
395
+
396
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
397
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
398
+                return $node->getSize();
399
+            });
400
+
401
+            $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
402
+                return $node->getFileInfo()->isEncrypted() ? '1' : '0';
403
+            });
404
+        }
405
+    }
406
+
407
+    /**
408
+     * translate Nextcloud permissions to OCM Permissions
409
+     *
410
+     * @param $ncPermissions
411
+     * @return array
412
+     */
413
+    protected function ncPermissions2ocmPermissions($ncPermissions) {
414
+
415
+        $ocmPermissions = [];
416
+
417
+        if ($ncPermissions & Constants::PERMISSION_SHARE) {
418
+            $ocmPermissions[] = 'share';
419
+        }
420
+
421
+        if ($ncPermissions & Constants::PERMISSION_READ) {
422
+            $ocmPermissions[] = 'read';
423
+        }
424
+
425
+        if (($ncPermissions & Constants::PERMISSION_CREATE) ||
426
+            ($ncPermissions & Constants::PERMISSION_UPDATE)) {
427
+            $ocmPermissions[] = 'write';
428
+        }
429
+
430
+        return $ocmPermissions;
431
+
432
+    }
433
+
434
+    /**
435
+     * Update ownCloud-specific properties
436
+     *
437
+     * @param string $path
438
+     * @param PropPatch $propPatch
439
+     *
440
+     * @return void
441
+     */
442
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
443
+        $node = $this->tree->getNodeForPath($path);
444
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
445
+            return;
446
+        }
447
+
448
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
449
+            if (empty($time)) {
450
+                return false;
451
+            }
452
+            $node->touch($time);
453
+            return true;
454
+        });
455
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
456
+            if (empty($etag)) {
457
+                return false;
458
+            }
459
+            if ($node->setEtag($etag) !== -1) {
460
+                return true;
461
+            }
462
+            return false;
463
+        });
464
+    }
465
+
466
+    /**
467
+     * @param string $filePath
468
+     * @param \Sabre\DAV\INode $node
469
+     * @throws \Sabre\DAV\Exception\BadRequest
470
+     */
471
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
472
+        // chunked upload handling
473
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
474
+            list($path, $name) = \Sabre\Uri\split($filePath);
475
+            $info = \OC_FileChunking::decodeName($name);
476
+            if (!empty($info)) {
477
+                $filePath = $path . '/' . $info['name'];
478
+            }
479
+        }
480
+
481
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
482
+        if (!$this->server->tree->nodeExists($filePath)) {
483
+            return;
484
+        }
485
+        $node = $this->server->tree->getNodeForPath($filePath);
486
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
487
+            $fileId = $node->getFileId();
488
+            if (!is_null($fileId)) {
489
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
490
+            }
491
+        }
492
+    }
493 493
 }
Please login to merge, or discard this patch.