Completed
Push — master ( a89f9a...3036b1 )
by Morris
29:19 queued 12:13
created
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/federatedfilesharing/lib/Settings/Admin.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -32,58 +32,58 @@
 block discarded – undo
32 32
 
33 33
 class Admin implements ISettings {
34 34
 
35
-	/** @var FederatedShareProvider */
36
-	private $fedShareProvider;
35
+    /** @var FederatedShareProvider */
36
+    private $fedShareProvider;
37 37
 
38
-	/** @var IConfig */
39
-	private $gsConfig;
38
+    /** @var IConfig */
39
+    private $gsConfig;
40 40
 
41
-	/**
42
-	 * Admin constructor.
43
-	 *
44
-	 * @param FederatedShareProvider $fedShareProvider
45
-	 * @param IConfig $globalScaleConfig
46
-	 */
47
-	public function __construct(FederatedShareProvider $fedShareProvider, IConfig $globalScaleConfig) {
48
-		$this->fedShareProvider = $fedShareProvider;
49
-		$this->gsConfig = $globalScaleConfig;
50
-	}
41
+    /**
42
+     * Admin constructor.
43
+     *
44
+     * @param FederatedShareProvider $fedShareProvider
45
+     * @param IConfig $globalScaleConfig
46
+     */
47
+    public function __construct(FederatedShareProvider $fedShareProvider, IConfig $globalScaleConfig) {
48
+        $this->fedShareProvider = $fedShareProvider;
49
+        $this->gsConfig = $globalScaleConfig;
50
+    }
51 51
 
52
-	/**
53
-	 * @return TemplateResponse
54
-	 */
55
-	public function getForm() {
52
+    /**
53
+     * @return TemplateResponse
54
+     */
55
+    public function getForm() {
56 56
 
57
-		$parameters = [
58
-			'internalOnly' => $this->gsConfig->onlyInternalFederation(),
59
-			'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
60
-			'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
61
-			'federatedGroupSharingSupported' => $this->fedShareProvider->isFederatedGroupSharingSupported(),
62
-			'outgoingServer2serverGroupShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverGroupShareEnabled(),
63
-			'incomingServer2serverGroupShareEnabled' => $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled(),
64
-			'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
65
-			'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(),
66
-		];
57
+        $parameters = [
58
+            'internalOnly' => $this->gsConfig->onlyInternalFederation(),
59
+            'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
60
+            'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
61
+            'federatedGroupSharingSupported' => $this->fedShareProvider->isFederatedGroupSharingSupported(),
62
+            'outgoingServer2serverGroupShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverGroupShareEnabled(),
63
+            'incomingServer2serverGroupShareEnabled' => $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled(),
64
+            'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
65
+            'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(),
66
+        ];
67 67
 
68
-		return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
69
-	}
68
+        return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
69
+    }
70 70
 
71
-	/**
72
-	 * @return string the section ID, e.g. 'sharing'
73
-	 */
74
-	public function getSection() {
75
-		return 'sharing';
76
-	}
71
+    /**
72
+     * @return string the section ID, e.g. 'sharing'
73
+     */
74
+    public function getSection() {
75
+        return 'sharing';
76
+    }
77 77
 
78
-	/**
79
-	 * @return int whether the form should be rather on the top or bottom of
80
-	 * the admin section. The forms are arranged in ascending order of the
81
-	 * priority values. It is required to return a value between 0 and 100.
82
-	 *
83
-	 * E.g.: 70
84
-	 */
85
-	public function getPriority() {
86
-		return 20;
87
-	}
78
+    /**
79
+     * @return int whether the form should be rather on the top or bottom of
80
+     * the admin section. The forms are arranged in ascending order of the
81
+     * priority values. It is required to return a value between 0 and 100.
82
+     *
83
+     * E.g.: 70
84
+     */
85
+    public function getPriority() {
86
+        return 20;
87
+    }
88 88
 
89 89
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationShare.php 1 patch
Indentation   +302 added lines, -302 removed lines patch added patch discarded remove patch
@@ -25,332 +25,332 @@
 block discarded – undo
25 25
 
26 26
 class CloudFederationShare implements ICloudFederationShare {
27 27
 
28
-	private $share = [
29
-		'shareWith' => '',
30
-		'shareType' => '',
31
-		'name' => '',
32
-		'resourceType' => '',
33
-		'description' => '',
34
-		'providerId' => '',
35
-		'owner' => '',
36
-		'ownerDisplayName' => '',
37
-		'sharedBy' => '',
38
-		'sharedByDisplayName' => '',
39
-		'protocol' => []
40
-	];
28
+    private $share = [
29
+        'shareWith' => '',
30
+        'shareType' => '',
31
+        'name' => '',
32
+        'resourceType' => '',
33
+        'description' => '',
34
+        'providerId' => '',
35
+        'owner' => '',
36
+        'ownerDisplayName' => '',
37
+        'sharedBy' => '',
38
+        'sharedByDisplayName' => '',
39
+        'protocol' => []
40
+    ];
41 41
 
42
-	/**
43
-	 * get a CloudFederationShare Object to prepare a share you want to send
44
-	 *
45
-	 * @param string $shareWith
46
-	 * @param string $name resource name (e.g. document.odt)
47
-	 * @param string $description share description (optional)
48
-	 * @param string $providerId resource UID on the provider side
49
-	 * @param string $owner provider specific UID of the user who owns the resource
50
-	 * @param string $ownerDisplayName display name of the user who shared the item
51
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
52
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
53
-	 * @param string $shareType ('group' or 'user' share)
54
-	 * @param string $resourceType ('file', 'calendar',...)
55
-	 * @param string $sharedSecret
56
-	 */
57
-	public function __construct($shareWith = '',
58
-								$name = '',
59
-								$description = '',
60
-								$providerId = '',
61
-								$owner = '',
62
-								$ownerDisplayName = '',
63
-								$sharedBy = '',
64
-								$sharedByDisplayName = '',
65
-								$shareType = '',
66
-								$resourceType = '',
67
-								$sharedSecret = ''
68
-	) {
69
-		$this->setShareWith($shareWith);
70
-		$this->setResourceName($name);
71
-		$this->setDescription($description);
72
-		$this->setProviderId($providerId);
73
-		$this->setOwner($owner);
74
-		$this->setOwnerDisplayName($ownerDisplayName);
75
-		$this->setSharedBy($sharedBy);
76
-		$this->setSharedByDisplayName($sharedByDisplayName);
77
-		$this->setProtocol([
78
-			'name' => 'webdav',
79
-			'options' => [
80
-				'sharedSecret' => $sharedSecret,
81
-				'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
82
-			]
83
-		]);
84
-		$this->setShareType($shareType);
85
-		$this->setResourceType($resourceType);
42
+    /**
43
+     * get a CloudFederationShare Object to prepare a share you want to send
44
+     *
45
+     * @param string $shareWith
46
+     * @param string $name resource name (e.g. document.odt)
47
+     * @param string $description share description (optional)
48
+     * @param string $providerId resource UID on the provider side
49
+     * @param string $owner provider specific UID of the user who owns the resource
50
+     * @param string $ownerDisplayName display name of the user who shared the item
51
+     * @param string $sharedBy provider specific UID of the user who shared the resource
52
+     * @param string $sharedByDisplayName display name of the user who shared the resource
53
+     * @param string $shareType ('group' or 'user' share)
54
+     * @param string $resourceType ('file', 'calendar',...)
55
+     * @param string $sharedSecret
56
+     */
57
+    public function __construct($shareWith = '',
58
+                                $name = '',
59
+                                $description = '',
60
+                                $providerId = '',
61
+                                $owner = '',
62
+                                $ownerDisplayName = '',
63
+                                $sharedBy = '',
64
+                                $sharedByDisplayName = '',
65
+                                $shareType = '',
66
+                                $resourceType = '',
67
+                                $sharedSecret = ''
68
+    ) {
69
+        $this->setShareWith($shareWith);
70
+        $this->setResourceName($name);
71
+        $this->setDescription($description);
72
+        $this->setProviderId($providerId);
73
+        $this->setOwner($owner);
74
+        $this->setOwnerDisplayName($ownerDisplayName);
75
+        $this->setSharedBy($sharedBy);
76
+        $this->setSharedByDisplayName($sharedByDisplayName);
77
+        $this->setProtocol([
78
+            'name' => 'webdav',
79
+            'options' => [
80
+                'sharedSecret' => $sharedSecret,
81
+                'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
82
+            ]
83
+        ]);
84
+        $this->setShareType($shareType);
85
+        $this->setResourceType($resourceType);
86 86
 
87
-	}
87
+    }
88 88
 
89
-	/**
90
-	 * set uid of the recipient
91
-	 *
92
-	 * @param string $user
93
-	 *
94
-	 * @since 14.0.0
95
-	 */
96
-	public function setShareWith($user) {
97
-		$this->share['shareWith'] = $user;
98
-	}
89
+    /**
90
+     * set uid of the recipient
91
+     *
92
+     * @param string $user
93
+     *
94
+     * @since 14.0.0
95
+     */
96
+    public function setShareWith($user) {
97
+        $this->share['shareWith'] = $user;
98
+    }
99 99
 
100
-	/**
101
-	 * set resource name (e.g. document.odt)
102
-	 *
103
-	 * @param string $name
104
-	 *
105
-	 * @since 14.0.0
106
-	 */
107
-	public function setResourceName($name) {
108
-		$this->share['name'] = $name;
109
-	}
100
+    /**
101
+     * set resource name (e.g. document.odt)
102
+     *
103
+     * @param string $name
104
+     *
105
+     * @since 14.0.0
106
+     */
107
+    public function setResourceName($name) {
108
+        $this->share['name'] = $name;
109
+    }
110 110
 
111
-	/**
112
-	 * set resource type (e.g. file, calendar, contact,...)
113
-	 *
114
-	 * @param string $resourceType
115
-	 *
116
-	 * @since 14.0.0
117
-	 */
118
-	public function setResourceType($resourceType) {
119
-		$this->share['resourceType'] = $resourceType;
120
-	}
111
+    /**
112
+     * set resource type (e.g. file, calendar, contact,...)
113
+     *
114
+     * @param string $resourceType
115
+     *
116
+     * @since 14.0.0
117
+     */
118
+    public function setResourceType($resourceType) {
119
+        $this->share['resourceType'] = $resourceType;
120
+    }
121 121
 
122
-	/**
123
-	 * set resource description (optional)
124
-	 *
125
-	 * @param string $description
126
-	 *
127
-	 * @since 14.0.0
128
-	 */
129
-	public function setDescription($description) {
130
-		$this->share['description'] = $description;
131
-	}
122
+    /**
123
+     * set resource description (optional)
124
+     *
125
+     * @param string $description
126
+     *
127
+     * @since 14.0.0
128
+     */
129
+    public function setDescription($description) {
130
+        $this->share['description'] = $description;
131
+    }
132 132
 
133
-	/**
134
-	 * set provider ID (e.g. file ID)
135
-	 *
136
-	 * @param string $providerId
137
-	 *
138
-	 * @since 14.0.0
139
-	 */
140
-	public function setProviderId($providerId) {
141
-		$this->share['providerId'] = $providerId;
142
-	}
133
+    /**
134
+     * set provider ID (e.g. file ID)
135
+     *
136
+     * @param string $providerId
137
+     *
138
+     * @since 14.0.0
139
+     */
140
+    public function setProviderId($providerId) {
141
+        $this->share['providerId'] = $providerId;
142
+    }
143 143
 
144
-	/**
145
-	 * set owner UID
146
-	 *
147
-	 * @param string $owner
148
-	 *
149
-	 * @since 14.0.0
150
-	 */
151
-	public function setOwner($owner) {
152
-		$this->share['owner'] = $owner;
153
-	}
144
+    /**
145
+     * set owner UID
146
+     *
147
+     * @param string $owner
148
+     *
149
+     * @since 14.0.0
150
+     */
151
+    public function setOwner($owner) {
152
+        $this->share['owner'] = $owner;
153
+    }
154 154
 
155
-	/**
156
-	 * set owner display name
157
-	 *
158
-	 * @param string $ownerDisplayName
159
-	 *
160
-	 * @since 14.0.0
161
-	 */
162
-	public function setOwnerDisplayName($ownerDisplayName) {
163
-		$this->share['ownerDisplayName'] = $ownerDisplayName;
164
-	}
155
+    /**
156
+     * set owner display name
157
+     *
158
+     * @param string $ownerDisplayName
159
+     *
160
+     * @since 14.0.0
161
+     */
162
+    public function setOwnerDisplayName($ownerDisplayName) {
163
+        $this->share['ownerDisplayName'] = $ownerDisplayName;
164
+    }
165 165
 
166
-	/**
167
-	 * set UID of the user who sends the share
168
-	 *
169
-	 * @param string $sharedBy
170
-	 *
171
-	 * @since 14.0.0
172
-	 */
173
-	public function setSharedBy($sharedBy) {
174
-		$this->share['sharedBy'] = $sharedBy;
175
-	}
166
+    /**
167
+     * set UID of the user who sends the share
168
+     *
169
+     * @param string $sharedBy
170
+     *
171
+     * @since 14.0.0
172
+     */
173
+    public function setSharedBy($sharedBy) {
174
+        $this->share['sharedBy'] = $sharedBy;
175
+    }
176 176
 
177
-	/**
178
-	 * set display name of the user who sends the share
179
-	 *
180
-	 * @param $sharedByDisplayName
181
-	 *
182
-	 * @since 14.0.0
183
-	 */
184
-	public function setSharedByDisplayName($sharedByDisplayName) {
185
-		$this->share['sharedByDisplayName'] = $sharedByDisplayName;
186
-	}
177
+    /**
178
+     * set display name of the user who sends the share
179
+     *
180
+     * @param $sharedByDisplayName
181
+     *
182
+     * @since 14.0.0
183
+     */
184
+    public function setSharedByDisplayName($sharedByDisplayName) {
185
+        $this->share['sharedByDisplayName'] = $sharedByDisplayName;
186
+    }
187 187
 
188
-	/**
189
-	 * set protocol specification
190
-	 *
191
-	 * @param array $protocol
192
-	 *
193
-	 * @since 14.0.0
194
-	 */
195
-	public function setProtocol(array $protocol) {
196
-		$this->share['protocol'] = $protocol;
197
-	}
188
+    /**
189
+     * set protocol specification
190
+     *
191
+     * @param array $protocol
192
+     *
193
+     * @since 14.0.0
194
+     */
195
+    public function setProtocol(array $protocol) {
196
+        $this->share['protocol'] = $protocol;
197
+    }
198 198
 
199
-	/**
200
-	 * share type (group or user)
201
-	 *
202
-	 * @param string $shareType
203
-	 *
204
-	 * @since 14.0.0
205
-	 */
206
-	public function setShareType($shareType) {
207
-		if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) {
208
-			$this->share['shareType'] = 'group';
209
-		} else {
210
-			$this->share['shareType'] = 'user';
211
-		}
212
-	}
199
+    /**
200
+     * share type (group or user)
201
+     *
202
+     * @param string $shareType
203
+     *
204
+     * @since 14.0.0
205
+     */
206
+    public function setShareType($shareType) {
207
+        if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) {
208
+            $this->share['shareType'] = 'group';
209
+        } else {
210
+            $this->share['shareType'] = 'user';
211
+        }
212
+    }
213 213
 
214
-	/**
215
-	 * get the whole share, ready to send out
216
-	 *
217
-	 * @return array
218
-	 *
219
-	 * @since 14.0.0
220
-	 */
221
-	public function getShare() {
222
-		return $this->share;
223
-	}
214
+    /**
215
+     * get the whole share, ready to send out
216
+     *
217
+     * @return array
218
+     *
219
+     * @since 14.0.0
220
+     */
221
+    public function getShare() {
222
+        return $this->share;
223
+    }
224 224
 
225
-	/**
226
-	 * get uid of the recipient
227
-	 *
228
-	 * @return string
229
-	 *
230
-	 * @since 14.0.0
231
-	 */
232
-	public function getShareWith() {
233
-		return $this->share['shareWith'];
234
-	}
225
+    /**
226
+     * get uid of the recipient
227
+     *
228
+     * @return string
229
+     *
230
+     * @since 14.0.0
231
+     */
232
+    public function getShareWith() {
233
+        return $this->share['shareWith'];
234
+    }
235 235
 
236
-	/**
237
-	 * get resource name (e.g. file, calendar, contact,...)
238
-	 *
239
-	 * @return string
240
-	 *
241
-	 * @since 14.0.0
242
-	 */
243
-	public function getResourceName() {
244
-		return $this->share['name'];
245
-	}
236
+    /**
237
+     * get resource name (e.g. file, calendar, contact,...)
238
+     *
239
+     * @return string
240
+     *
241
+     * @since 14.0.0
242
+     */
243
+    public function getResourceName() {
244
+        return $this->share['name'];
245
+    }
246 246
 
247
-	/**
248
-	 * get resource type (e.g. file, calendar, contact,...)
249
-	 *
250
-	 * @return string
251
-	 *
252
-	 * @since 14.0.0
253
-	 */
254
-	public function getResourceType() {
255
-		return $this->share['resourceType'];
256
-	}
247
+    /**
248
+     * get resource type (e.g. file, calendar, contact,...)
249
+     *
250
+     * @return string
251
+     *
252
+     * @since 14.0.0
253
+     */
254
+    public function getResourceType() {
255
+        return $this->share['resourceType'];
256
+    }
257 257
 
258
-	/**
259
-	 * get resource description (optional)
260
-	 *
261
-	 * @return string
262
-	 *
263
-	 * @since 14.0.0
264
-	 */
265
-	public function getDescription() {
266
-		return $this->share['description'];
267
-	}
258
+    /**
259
+     * get resource description (optional)
260
+     *
261
+     * @return string
262
+     *
263
+     * @since 14.0.0
264
+     */
265
+    public function getDescription() {
266
+        return $this->share['description'];
267
+    }
268 268
 
269
-	/**
270
-	 * get provider ID (e.g. file ID)
271
-	 *
272
-	 * @return string
273
-	 *
274
-	 * @since 14.0.0
275
-	 */
276
-	public function getProviderId() {
277
-		return $this->share['providerId'];
278
-	}
269
+    /**
270
+     * get provider ID (e.g. file ID)
271
+     *
272
+     * @return string
273
+     *
274
+     * @since 14.0.0
275
+     */
276
+    public function getProviderId() {
277
+        return $this->share['providerId'];
278
+    }
279 279
 
280
-	/**
281
-	 * get owner UID
282
-	 *
283
-	 * @return string
284
-	 *
285
-	 * @since 14.0.0
286
-	 */
287
-	public function getOwner() {
288
-		return $this->share['owner'];
289
-	}
280
+    /**
281
+     * get owner UID
282
+     *
283
+     * @return string
284
+     *
285
+     * @since 14.0.0
286
+     */
287
+    public function getOwner() {
288
+        return $this->share['owner'];
289
+    }
290 290
 
291
-	/**
292
-	 * get owner display name
293
-	 *
294
-	 * @return string
295
-	 *
296
-	 * @since 14.0.0
297
-	 */
298
-	public function getOwnerDisplayName() {
299
-		return $this->share['ownerDisplayName'];
300
-	}
291
+    /**
292
+     * get owner display name
293
+     *
294
+     * @return string
295
+     *
296
+     * @since 14.0.0
297
+     */
298
+    public function getOwnerDisplayName() {
299
+        return $this->share['ownerDisplayName'];
300
+    }
301 301
 
302
-	/**
303
-	 * get UID of the user who sends the share
304
-	 *
305
-	 * @return string
306
-	 *
307
-	 * @since 14.0.0
308
-	 */
309
-	public function getSharedBy() {
310
-		return $this->share['sharedBy'];
311
-	}
302
+    /**
303
+     * get UID of the user who sends the share
304
+     *
305
+     * @return string
306
+     *
307
+     * @since 14.0.0
308
+     */
309
+    public function getSharedBy() {
310
+        return $this->share['sharedBy'];
311
+    }
312 312
 
313
-	/**
314
-	 * get display name of the user who sends the share
315
-	 *
316
-	 * @return string
317
-	 *
318
-	 * @since 14.0.0
319
-	 */
320
-	public function getSharedByDisplayName() {
321
-		return $this->share['sharedByDisplayName'];
322
-	}
313
+    /**
314
+     * get display name of the user who sends the share
315
+     *
316
+     * @return string
317
+     *
318
+     * @since 14.0.0
319
+     */
320
+    public function getSharedByDisplayName() {
321
+        return $this->share['sharedByDisplayName'];
322
+    }
323 323
 
324
-	/**
325
-	 * get share type (group or user)
326
-	 *
327
-	 * @return string
328
-	 *
329
-	 * @since 14.0.0
330
-	 */
331
-	public function getShareType() {
332
-		return $this->share['shareType'];
333
-	}
324
+    /**
325
+     * get share type (group or user)
326
+     *
327
+     * @return string
328
+     *
329
+     * @since 14.0.0
330
+     */
331
+    public function getShareType() {
332
+        return $this->share['shareType'];
333
+    }
334 334
 
335
-	/**
336
-	 * get share Secret
337
-	 *
338
-	 * @return string
339
-	 *
340
-	 * @since 14.0.0
341
-	 */
342
-	public function getShareSecret() {
343
-		return $this->share['protocol']['options']['sharedSecret'];
344
-	}
335
+    /**
336
+     * get share Secret
337
+     *
338
+     * @return string
339
+     *
340
+     * @since 14.0.0
341
+     */
342
+    public function getShareSecret() {
343
+        return $this->share['protocol']['options']['sharedSecret'];
344
+    }
345 345
 
346
-	/**
347
-	 * get protocol specification
348
-	 *
349
-	 * @return array
350
-	 *
351
-	 * @since 14.0.0
352
-	 */
353
-	public function getProtocol() {
354
-		return $this->share['protocol'];
355
-	}
346
+    /**
347
+     * get protocol specification
348
+     *
349
+     * @return array
350
+     *
351
+     * @since 14.0.0
352
+     */
353
+    public function getProtocol() {
354
+        return $this->share['protocol'];
355
+    }
356 356
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Controller/RequestHandlerController.php 1 patch
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -52,249 +52,249 @@
 block discarded – undo
52 52
  */
53 53
 class RequestHandlerController extends Controller {
54 54
 
55
-	/** @var ILogger */
56
-	private $logger;
57
-
58
-	/** @var IUserManager */
59
-	private $userManager;
60
-
61
-	/** @var IGroupManager */
62
-	private $groupManager;
63
-
64
-	/** @var IURLGenerator */
65
-	private $urlGenerator;
66
-
67
-	/** @var ICloudFederationProviderManager */
68
-	private $cloudFederationProviderManager;
69
-
70
-	/** @var Config */
71
-	private $config;
72
-
73
-	/** @var ICloudFederationFactory */
74
-	private $factory;
75
-
76
-	/** @var ICloudIdManager */
77
-	private $cloudIdManager;
78
-
79
-	public function __construct($appName,
80
-								IRequest $request,
81
-								ILogger $logger,
82
-								IUserManager $userManager,
83
-								IGroupManager $groupManager,
84
-								IURLGenerator $urlGenerator,
85
-								ICloudFederationProviderManager $cloudFederationProviderManager,
86
-								Config $config,
87
-								ICloudFederationFactory $factory,
88
-								ICloudIdManager $cloudIdManager
89
-	) {
90
-		parent::__construct($appName, $request);
91
-
92
-		$this->logger = $logger;
93
-		$this->userManager = $userManager;
94
-		$this->groupManager = $groupManager;
95
-		$this->urlGenerator = $urlGenerator;
96
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
97
-		$this->config = $config;
98
-		$this->factory = $factory;
99
-		$this->cloudIdManager = $cloudIdManager;
100
-	}
101
-
102
-	/**
103
-	 * add share
104
-	 *
105
-	 * @NoCSRFRequired
106
-	 * @PublicPage
107
-	 * @BruteForceProtection(action=receiveFederatedShare)
108
-	 *
109
-	 * @param string $shareWith
110
-	 * @param string $name resource name (e.g. document.odt)
111
-	 * @param string $description share description (optional)
112
-	 * @param string $providerId resource UID on the provider side
113
-	 * @param string $owner provider specific UID of the user who owns the resource
114
-	 * @param string $ownerDisplayName display name of the user who shared the item
115
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
116
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
117
-	 * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
118
-	 * @param string $shareType ('group' or 'user' share)
119
-	 * @param $resourceType ('file', 'calendar',...)
120
-	 * @return Http\DataResponse|JSONResponse
121
-	 *
122
-	 * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares
123
-	 */
124
-	public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
125
-
126
-		// check if all required parameters are set
127
-		if ($shareWith === null ||
128
-			$name === null ||
129
-			$providerId === null ||
130
-			$owner === null ||
131
-			$resourceType === null ||
132
-			$shareType === null ||
133
-			!is_array($protocol) ||
134
-			!isset($protocol['name']) ||
135
-			!isset ($protocol['options']) ||
136
-			!is_array($protocol['options']) ||
137
-			!isset($protocol['options']['sharedSecret'])
138
-		) {
139
-			return new JSONResponse(
140
-				['message' => 'Missing arguments'],
141
-				Http::STATUS_BAD_REQUEST
142
-			);
143
-		}
144
-
145
-		$supportedShareTypes = $this->config->getSupportedShareTypes($resourceType);
146
-		if (!in_array($shareType, $supportedShareTypes)) {
147
-			return new JSONResponse(
148
-				['message' => 'Share type "' . $shareType . '" not implemented'],
149
-				Http::STATUS_NOT_IMPLEMENTED
150
-			);
151
-		}
152
-
153
-		$cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
154
-		$shareWith = $cloudId->getUser();
155
-
156
-		if ($shareType === 'user') {
157
-			$shareWith = $this->mapUid($shareWith);
158
-
159
-			if (!$this->userManager->userExists($shareWith)) {
160
-				return new JSONResponse(
161
-					['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
162
-					Http::STATUS_BAD_REQUEST
163
-				);
164
-			}
165
-		}
166
-
167
-		if ($shareType === 'group') {
168
-			if(!$this->groupManager->groupExists($shareWith)) {
169
-				return new JSONResponse(
170
-					['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
171
-					Http::STATUS_BAD_REQUEST
172
-				);
173
-			}
174
-		}
175
-
176
-		// if no explicit display name is given, we use the uid as display name
177
-		$ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName;
178
-		$sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName;
179
-
180
-		// sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner
181
-		if ($sharedBy === null) {
182
-			$sharedBy = $owner;
183
-			$sharedByDisplayName = $ownerDisplayName;
184
-		}
185
-
186
-		try {
187
-			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
188
-			$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
189
-			$share->setProtocol($protocol);
190
-			$provider->shareReceived($share);
191
-		} catch (ProviderDoesNotExistsException $e) {
192
-			return new JSONResponse(
193
-				['message' => $e->getMessage()],
194
-				Http::STATUS_NOT_IMPLEMENTED
195
-			);
196
-		} catch (ProviderCouldNotAddShareException $e) {
197
-			return new JSONResponse(
198
-				['message' => $e->getMessage()],
199
-				$e->getCode()
200
-			);
201
-		} catch (\Exception $e) {
202
-			return new JSONResponse(
203
-				['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
204
-				Http::STATUS_BAD_REQUEST
205
-			);
206
-		}
207
-
208
-		$user = $this->userManager->get($shareWith);
209
-		$recipientDisplayName = '';
210
-		if($user) {
211
-			$recipientDisplayName = $user->getDisplayName();
212
-		}
213
-
214
-		return new JSONResponse(
215
-			['recipientDisplayName' => $recipientDisplayName],
216
-			Http::STATUS_CREATED);
217
-
218
-	}
219
-
220
-	/**
221
-	 * receive notification about existing share
222
-	 *
223
-	 * @NoCSRFRequired
224
-	 * @PublicPage
225
-	 * @BruteForceProtection(action=receiveFederatedShareNotification)
226
-	 *
227
-	 * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED)
228
-	 * @param string $resourceType (calendar, file, contact,...)
229
-	 * @param string $providerId id of the share
230
-	 * @param array $notification the actual payload of the notification
231
-	 * @return JSONResponse
232
-	 */
233
-	public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) {
234
-
235
-		// check if all required parameters are set
236
-		if ($notificationType === null ||
237
-			$resourceType === null ||
238
-			$providerId === null ||
239
-			!is_array($notification)
240
-		) {
241
-			return new JSONResponse(
242
-				['message' => 'Missing arguments'],
243
-				Http::STATUS_BAD_REQUEST
244
-			);
245
-		}
246
-
247
-		try {
248
-			$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
249
-			$result = $provider->notificationReceived($notificationType, $providerId, $notification);
250
-		} catch (ProviderDoesNotExistsException $e) {
251
-			return new JSONResponse(
252
-				['message' => $e->getMessage()],
253
-				Http::STATUS_BAD_REQUEST
254
-			);
255
-		} catch (ShareNotFound $e) {
256
-			return new JSONResponse(
257
-				['message' => $e->getMessage()],
258
-				Http::STATUS_BAD_REQUEST
259
-			);
260
-		} catch (ActionNotSupportedException $e) {
261
-			return new JSONResponse(
262
-				['message' => $e->getMessage()],
263
-				Http::STATUS_NOT_IMPLEMENTED
264
-			);
265
-		} catch (BadRequestException $e) {
266
-			return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST);
267
-		} catch (AuthenticationFailedException $e) {
268
-			return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN);
269
-		}
270
-		catch (\Exception $e) {
271
-			return new JSONResponse(
272
-				['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
273
-				Http::STATUS_BAD_REQUEST
274
-			);
275
-		}
276
-
277
-		return new JSONResponse($result,Http::STATUS_CREATED);
278
-
279
-	}
280
-
281
-	/**
282
-	 * map login name to internal LDAP UID if a LDAP backend is in use
283
-	 *
284
-	 * @param string $uid
285
-	 * @return string mixed
286
-	 */
287
-	private function mapUid($uid) {
288
-		// FIXME this should be a method in the user management instead
289
-		$this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
290
-		\OCP\Util::emitHook(
291
-			'\OCA\Files_Sharing\API\Server2Server',
292
-			'preLoginNameUsedAsUserName',
293
-			array('uid' => &$uid)
294
-		);
295
-		$this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]);
296
-
297
-		return $uid;
298
-	}
55
+    /** @var ILogger */
56
+    private $logger;
57
+
58
+    /** @var IUserManager */
59
+    private $userManager;
60
+
61
+    /** @var IGroupManager */
62
+    private $groupManager;
63
+
64
+    /** @var IURLGenerator */
65
+    private $urlGenerator;
66
+
67
+    /** @var ICloudFederationProviderManager */
68
+    private $cloudFederationProviderManager;
69
+
70
+    /** @var Config */
71
+    private $config;
72
+
73
+    /** @var ICloudFederationFactory */
74
+    private $factory;
75
+
76
+    /** @var ICloudIdManager */
77
+    private $cloudIdManager;
78
+
79
+    public function __construct($appName,
80
+                                IRequest $request,
81
+                                ILogger $logger,
82
+                                IUserManager $userManager,
83
+                                IGroupManager $groupManager,
84
+                                IURLGenerator $urlGenerator,
85
+                                ICloudFederationProviderManager $cloudFederationProviderManager,
86
+                                Config $config,
87
+                                ICloudFederationFactory $factory,
88
+                                ICloudIdManager $cloudIdManager
89
+    ) {
90
+        parent::__construct($appName, $request);
91
+
92
+        $this->logger = $logger;
93
+        $this->userManager = $userManager;
94
+        $this->groupManager = $groupManager;
95
+        $this->urlGenerator = $urlGenerator;
96
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
97
+        $this->config = $config;
98
+        $this->factory = $factory;
99
+        $this->cloudIdManager = $cloudIdManager;
100
+    }
101
+
102
+    /**
103
+     * add share
104
+     *
105
+     * @NoCSRFRequired
106
+     * @PublicPage
107
+     * @BruteForceProtection(action=receiveFederatedShare)
108
+     *
109
+     * @param string $shareWith
110
+     * @param string $name resource name (e.g. document.odt)
111
+     * @param string $description share description (optional)
112
+     * @param string $providerId resource UID on the provider side
113
+     * @param string $owner provider specific UID of the user who owns the resource
114
+     * @param string $ownerDisplayName display name of the user who shared the item
115
+     * @param string $sharedBy provider specific UID of the user who shared the resource
116
+     * @param string $sharedByDisplayName display name of the user who shared the resource
117
+     * @param array $protocol (e,.g. ['name' => 'webdav', 'options' => ['username' => 'john', 'permissions' => 31]])
118
+     * @param string $shareType ('group' or 'user' share)
119
+     * @param $resourceType ('file', 'calendar',...)
120
+     * @return Http\DataResponse|JSONResponse
121
+     *
122
+     * Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares
123
+     */
124
+    public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
125
+
126
+        // check if all required parameters are set
127
+        if ($shareWith === null ||
128
+            $name === null ||
129
+            $providerId === null ||
130
+            $owner === null ||
131
+            $resourceType === null ||
132
+            $shareType === null ||
133
+            !is_array($protocol) ||
134
+            !isset($protocol['name']) ||
135
+            !isset ($protocol['options']) ||
136
+            !is_array($protocol['options']) ||
137
+            !isset($protocol['options']['sharedSecret'])
138
+        ) {
139
+            return new JSONResponse(
140
+                ['message' => 'Missing arguments'],
141
+                Http::STATUS_BAD_REQUEST
142
+            );
143
+        }
144
+
145
+        $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType);
146
+        if (!in_array($shareType, $supportedShareTypes)) {
147
+            return new JSONResponse(
148
+                ['message' => 'Share type "' . $shareType . '" not implemented'],
149
+                Http::STATUS_NOT_IMPLEMENTED
150
+            );
151
+        }
152
+
153
+        $cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
154
+        $shareWith = $cloudId->getUser();
155
+
156
+        if ($shareType === 'user') {
157
+            $shareWith = $this->mapUid($shareWith);
158
+
159
+            if (!$this->userManager->userExists($shareWith)) {
160
+                return new JSONResponse(
161
+                    ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
162
+                    Http::STATUS_BAD_REQUEST
163
+                );
164
+            }
165
+        }
166
+
167
+        if ($shareType === 'group') {
168
+            if(!$this->groupManager->groupExists($shareWith)) {
169
+                return new JSONResponse(
170
+                    ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()],
171
+                    Http::STATUS_BAD_REQUEST
172
+                );
173
+            }
174
+        }
175
+
176
+        // if no explicit display name is given, we use the uid as display name
177
+        $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName;
178
+        $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName;
179
+
180
+        // sharedBy* parameter is optional, if nothing is set we assume that it is the same user as the owner
181
+        if ($sharedBy === null) {
182
+            $sharedBy = $owner;
183
+            $sharedByDisplayName = $ownerDisplayName;
184
+        }
185
+
186
+        try {
187
+            $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
188
+            $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
189
+            $share->setProtocol($protocol);
190
+            $provider->shareReceived($share);
191
+        } catch (ProviderDoesNotExistsException $e) {
192
+            return new JSONResponse(
193
+                ['message' => $e->getMessage()],
194
+                Http::STATUS_NOT_IMPLEMENTED
195
+            );
196
+        } catch (ProviderCouldNotAddShareException $e) {
197
+            return new JSONResponse(
198
+                ['message' => $e->getMessage()],
199
+                $e->getCode()
200
+            );
201
+        } catch (\Exception $e) {
202
+            return new JSONResponse(
203
+                ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
204
+                Http::STATUS_BAD_REQUEST
205
+            );
206
+        }
207
+
208
+        $user = $this->userManager->get($shareWith);
209
+        $recipientDisplayName = '';
210
+        if($user) {
211
+            $recipientDisplayName = $user->getDisplayName();
212
+        }
213
+
214
+        return new JSONResponse(
215
+            ['recipientDisplayName' => $recipientDisplayName],
216
+            Http::STATUS_CREATED);
217
+
218
+    }
219
+
220
+    /**
221
+     * receive notification about existing share
222
+     *
223
+     * @NoCSRFRequired
224
+     * @PublicPage
225
+     * @BruteForceProtection(action=receiveFederatedShareNotification)
226
+     *
227
+     * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED)
228
+     * @param string $resourceType (calendar, file, contact,...)
229
+     * @param string $providerId id of the share
230
+     * @param array $notification the actual payload of the notification
231
+     * @return JSONResponse
232
+     */
233
+    public function receiveNotification($notificationType, $resourceType, $providerId, array $notification) {
234
+
235
+        // check if all required parameters are set
236
+        if ($notificationType === null ||
237
+            $resourceType === null ||
238
+            $providerId === null ||
239
+            !is_array($notification)
240
+        ) {
241
+            return new JSONResponse(
242
+                ['message' => 'Missing arguments'],
243
+                Http::STATUS_BAD_REQUEST
244
+            );
245
+        }
246
+
247
+        try {
248
+            $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
249
+            $result = $provider->notificationReceived($notificationType, $providerId, $notification);
250
+        } catch (ProviderDoesNotExistsException $e) {
251
+            return new JSONResponse(
252
+                ['message' => $e->getMessage()],
253
+                Http::STATUS_BAD_REQUEST
254
+            );
255
+        } catch (ShareNotFound $e) {
256
+            return new JSONResponse(
257
+                ['message' => $e->getMessage()],
258
+                Http::STATUS_BAD_REQUEST
259
+            );
260
+        } catch (ActionNotSupportedException $e) {
261
+            return new JSONResponse(
262
+                ['message' => $e->getMessage()],
263
+                Http::STATUS_NOT_IMPLEMENTED
264
+            );
265
+        } catch (BadRequestException $e) {
266
+            return new JSONResponse($e->getReturnMessage(), Http::STATUS_BAD_REQUEST);
267
+        } catch (AuthenticationFailedException $e) {
268
+            return new JSONResponse(["message" => "RESOURCE_NOT_FOUND"], Http::STATUS_FORBIDDEN);
269
+        }
270
+        catch (\Exception $e) {
271
+            return new JSONResponse(
272
+                ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()],
273
+                Http::STATUS_BAD_REQUEST
274
+            );
275
+        }
276
+
277
+        return new JSONResponse($result,Http::STATUS_CREATED);
278
+
279
+    }
280
+
281
+    /**
282
+     * map login name to internal LDAP UID if a LDAP backend is in use
283
+     *
284
+     * @param string $uid
285
+     * @return string mixed
286
+     */
287
+    private function mapUid($uid) {
288
+        // FIXME this should be a method in the user management instead
289
+        $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
290
+        \OCP\Util::emitHook(
291
+            '\OCA\Files_Sharing\API\Server2Server',
292
+            'preLoginNameUsedAsUserName',
293
+            array('uid' => &$uid)
294
+        );
295
+        $this->logger->debug('shareWith after, ' . $uid, ['app' => $this->appName]);
296
+
297
+        return $uid;
298
+    }
299 299
 
300 300
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/AppInfo/Application.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -39,117 +39,117 @@
 block discarded – undo
39 39
 
40 40
 class Application extends App {
41 41
 
42
-	/** @var FederatedShareProvider */
43
-	protected $federatedShareProvider;
42
+    /** @var FederatedShareProvider */
43
+    protected $federatedShareProvider;
44 44
 
45
-	public function __construct() {
46
-		parent::__construct('federatedfilesharing');
45
+    public function __construct() {
46
+        parent::__construct('federatedfilesharing');
47 47
 
48
-		$container = $this->getContainer();
49
-		$server = $container->getServer();
48
+        $container = $this->getContainer();
49
+        $server = $container->getServer();
50 50
 
51
-		$cloudFederationManager = $server->getCloudFederationProviderManager();
52
-		$cloudFederationManager->addCloudFederationProvider('file',
53
-			'Federated Files Sharing',
54
-			function() use ($container) {
55
-				$server = $container->getServer();
56
-				return new CloudFederationProviderFiles(
57
-					$server->getAppManager(),
58
-					$server->query(FederatedShareProvider::class),
59
-					$server->query(AddressHandler::class),
60
-					$server->getLogger(),
61
-					$server->getUserManager(),
62
-					$server->getCloudIdManager(),
63
-					$server->getActivityManager(),
64
-					$server->getNotificationManager(),
65
-					$server->getURLGenerator(),
66
-					$server->getCloudFederationFactory(),
67
-					$server->getCloudFederationProviderManager(),
68
-					$server->getDatabaseConnection(),
69
-					$server->getGroupManager()
70
-				);
71
-			});
51
+        $cloudFederationManager = $server->getCloudFederationProviderManager();
52
+        $cloudFederationManager->addCloudFederationProvider('file',
53
+            'Federated Files Sharing',
54
+            function() use ($container) {
55
+                $server = $container->getServer();
56
+                return new CloudFederationProviderFiles(
57
+                    $server->getAppManager(),
58
+                    $server->query(FederatedShareProvider::class),
59
+                    $server->query(AddressHandler::class),
60
+                    $server->getLogger(),
61
+                    $server->getUserManager(),
62
+                    $server->getCloudIdManager(),
63
+                    $server->getActivityManager(),
64
+                    $server->getNotificationManager(),
65
+                    $server->getURLGenerator(),
66
+                    $server->getCloudFederationFactory(),
67
+                    $server->getCloudFederationProviderManager(),
68
+                    $server->getDatabaseConnection(),
69
+                    $server->getGroupManager()
70
+                );
71
+            });
72 72
 
73
-		$container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
74
-			$addressHandler = new AddressHandler(
75
-				$server->getURLGenerator(),
76
-				$server->getL10N('federatedfilesharing'),
77
-				$server->getCloudIdManager()
78
-			);
79
-			$notification = new Notifications(
80
-				$addressHandler,
81
-				$server->getHTTPClientService(),
82
-				$server->query(\OCP\OCS\IDiscoveryService::class),
83
-				\OC::$server->getJobList(),
84
-				\OC::$server->getCloudFederationProviderManager(),
85
-				\OC::$server->getCloudFederationFactory()
86
-			);
87
-			return new RequestHandlerController(
88
-				$c->query('AppName'),
89
-				$server->getRequest(),
90
-				$this->getFederatedShareProvider(),
91
-				$server->getDatabaseConnection(),
92
-				$server->getShareManager(),
93
-				$notification,
94
-				$addressHandler,
95
-				$server->getUserManager(),
96
-				$server->getCloudIdManager(),
97
-				$server->getLogger(),
98
-				$server->getCloudFederationFactory(),
99
-				$server->getCloudFederationProviderManager()
100
-			);
101
-		});
102
-	}
73
+        $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
74
+            $addressHandler = new AddressHandler(
75
+                $server->getURLGenerator(),
76
+                $server->getL10N('federatedfilesharing'),
77
+                $server->getCloudIdManager()
78
+            );
79
+            $notification = new Notifications(
80
+                $addressHandler,
81
+                $server->getHTTPClientService(),
82
+                $server->query(\OCP\OCS\IDiscoveryService::class),
83
+                \OC::$server->getJobList(),
84
+                \OC::$server->getCloudFederationProviderManager(),
85
+                \OC::$server->getCloudFederationFactory()
86
+            );
87
+            return new RequestHandlerController(
88
+                $c->query('AppName'),
89
+                $server->getRequest(),
90
+                $this->getFederatedShareProvider(),
91
+                $server->getDatabaseConnection(),
92
+                $server->getShareManager(),
93
+                $notification,
94
+                $addressHandler,
95
+                $server->getUserManager(),
96
+                $server->getCloudIdManager(),
97
+                $server->getLogger(),
98
+                $server->getCloudFederationFactory(),
99
+                $server->getCloudFederationProviderManager()
100
+            );
101
+        });
102
+    }
103 103
 
104
-	/**
105
-	 * get instance of federated share provider
106
-	 *
107
-	 * @return FederatedShareProvider
108
-	 */
109
-	public function getFederatedShareProvider() {
110
-		if ($this->federatedShareProvider === null) {
111
-			$this->initFederatedShareProvider();
112
-		}
113
-		return $this->federatedShareProvider;
114
-	}
104
+    /**
105
+     * get instance of federated share provider
106
+     *
107
+     * @return FederatedShareProvider
108
+     */
109
+    public function getFederatedShareProvider() {
110
+        if ($this->federatedShareProvider === null) {
111
+            $this->initFederatedShareProvider();
112
+        }
113
+        return $this->federatedShareProvider;
114
+    }
115 115
 
116
-	/**
117
-	 * initialize federated share provider
118
-	 */
119
-	protected function initFederatedShareProvider() {
120
-		$c = $this->getContainer();
121
-		$addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
122
-			\OC::$server->getURLGenerator(),
123
-			\OC::$server->getL10N('federatedfilesharing'),
124
-			\OC::$server->getCloudIdManager()
125
-		);
126
-		$notifications = new \OCA\FederatedFileSharing\Notifications(
127
-			$addressHandler,
128
-			\OC::$server->getHTTPClientService(),
129
-			\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
130
-			\OC::$server->getJobList(),
131
-			\OC::$server->getCloudFederationProviderManager(),
132
-			\OC::$server->getCloudFederationFactory()
133
-		);
134
-		$tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
135
-			\OC::$server->getSecureRandom()
136
-		);
116
+    /**
117
+     * initialize federated share provider
118
+     */
119
+    protected function initFederatedShareProvider() {
120
+        $c = $this->getContainer();
121
+        $addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
122
+            \OC::$server->getURLGenerator(),
123
+            \OC::$server->getL10N('federatedfilesharing'),
124
+            \OC::$server->getCloudIdManager()
125
+        );
126
+        $notifications = new \OCA\FederatedFileSharing\Notifications(
127
+            $addressHandler,
128
+            \OC::$server->getHTTPClientService(),
129
+            \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
130
+            \OC::$server->getJobList(),
131
+            \OC::$server->getCloudFederationProviderManager(),
132
+            \OC::$server->getCloudFederationFactory()
133
+        );
134
+        $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
135
+            \OC::$server->getSecureRandom()
136
+        );
137 137
 
138
-		$this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
139
-			\OC::$server->getDatabaseConnection(),
140
-			$addressHandler,
141
-			$notifications,
142
-			$tokenHandler,
143
-			\OC::$server->getL10N('federatedfilesharing'),
144
-			\OC::$server->getLogger(),
145
-			\OC::$server->getLazyRootFolder(),
146
-			\OC::$server->getConfig(),
147
-			\OC::$server->getUserManager(),
148
-			\OC::$server->getCloudIdManager(),
149
-			$c->query(IConfig::class),
150
-			\OC::$server->getCloudFederationProviderManager()
138
+        $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
139
+            \OC::$server->getDatabaseConnection(),
140
+            $addressHandler,
141
+            $notifications,
142
+            $tokenHandler,
143
+            \OC::$server->getL10N('federatedfilesharing'),
144
+            \OC::$server->getLogger(),
145
+            \OC::$server->getLazyRootFolder(),
146
+            \OC::$server->getConfig(),
147
+            \OC::$server->getUserManager(),
148
+            \OC::$server->getCloudIdManager(),
149
+            $c->query(IConfig::class),
150
+            \OC::$server->getCloudFederationProviderManager()
151 151
 
152
-		);
153
-	}
152
+        );
153
+    }
154 154
 
155 155
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/AppInfo/Application.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -45,138 +45,138 @@
 block discarded – undo
45 45
 use OCA\Files_Sharing\External\Manager;
46 46
 
47 47
 class Application extends App {
48
-	public function __construct(array $urlParams = array()) {
49
-		parent::__construct('files_sharing', $urlParams);
48
+    public function __construct(array $urlParams = array()) {
49
+        parent::__construct('files_sharing', $urlParams);
50 50
 
51
-		$container = $this->getContainer();
52
-		/** @var IServerContainer $server */
53
-		$server = $container->getServer();
51
+        $container = $this->getContainer();
52
+        /** @var IServerContainer $server */
53
+        $server = $container->getServer();
54 54
 
55
-		/**
56
-		 * Controllers
57
-		 */
58
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
59
-			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
60
-			return new ShareController(
61
-				$c->query('AppName'),
62
-				$c->query('Request'),
63
-				$server->getConfig(),
64
-				$server->getURLGenerator(),
65
-				$server->getUserManager(),
66
-				$server->getLogger(),
67
-				$server->getActivityManager(),
68
-				$server->getShareManager(),
69
-				$server->getSession(),
70
-				$server->getPreviewManager(),
71
-				$server->getRootFolder(),
72
-				$federatedSharingApp->getFederatedShareProvider(),
73
-				$server->getEventDispatcher(),
74
-				$server->getL10N($c->query('AppName')),
75
-				$server->query(Defaults::class)
76
-			);
77
-		});
78
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
79
-			return new ExternalSharesController(
80
-				$c->query('AppName'),
81
-				$c->query('Request'),
82
-				$c->query('ExternalManager'),
83
-				$c->query('HttpClientService')
84
-			);
85
-		});
55
+        /**
56
+         * Controllers
57
+         */
58
+        $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
59
+            $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
60
+            return new ShareController(
61
+                $c->query('AppName'),
62
+                $c->query('Request'),
63
+                $server->getConfig(),
64
+                $server->getURLGenerator(),
65
+                $server->getUserManager(),
66
+                $server->getLogger(),
67
+                $server->getActivityManager(),
68
+                $server->getShareManager(),
69
+                $server->getSession(),
70
+                $server->getPreviewManager(),
71
+                $server->getRootFolder(),
72
+                $federatedSharingApp->getFederatedShareProvider(),
73
+                $server->getEventDispatcher(),
74
+                $server->getL10N($c->query('AppName')),
75
+                $server->query(Defaults::class)
76
+            );
77
+        });
78
+        $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
79
+            return new ExternalSharesController(
80
+                $c->query('AppName'),
81
+                $c->query('Request'),
82
+                $c->query('ExternalManager'),
83
+                $c->query('HttpClientService')
84
+            );
85
+        });
86 86
 
87
-		/**
88
-		 * Core class wrappers
89
-		 */
90
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
91
-			return $server->getHTTPClientService();
92
-		});
93
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
94
-			return $server->getCloudIdManager();
95
-		});
96
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
97
-			$user = $server->getUserSession()->getUser();
98
-			$uid = $user ? $user->getUID() : null;
99
-			return new \OCA\Files_Sharing\External\Manager(
100
-				$server->getDatabaseConnection(),
101
-				\OC\Files\Filesystem::getMountManager(),
102
-				\OC\Files\Filesystem::getLoader(),
103
-				$server->getHTTPClientService(),
104
-				$server->getNotificationManager(),
105
-				$server->query(\OCP\OCS\IDiscoveryService::class),
106
-				$server->getCloudFederationProviderManager(),
107
-				$server->getCloudFederationFactory(),
108
-				$server->getGroupManager(),
109
-				$server->getUserManager(),
110
-				$uid
111
-			);
112
-		});
113
-		$container->registerAlias(Manager::class, 'ExternalManager');
87
+        /**
88
+         * Core class wrappers
89
+         */
90
+        $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
91
+            return $server->getHTTPClientService();
92
+        });
93
+        $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
94
+            return $server->getCloudIdManager();
95
+        });
96
+        $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
97
+            $user = $server->getUserSession()->getUser();
98
+            $uid = $user ? $user->getUID() : null;
99
+            return new \OCA\Files_Sharing\External\Manager(
100
+                $server->getDatabaseConnection(),
101
+                \OC\Files\Filesystem::getMountManager(),
102
+                \OC\Files\Filesystem::getLoader(),
103
+                $server->getHTTPClientService(),
104
+                $server->getNotificationManager(),
105
+                $server->query(\OCP\OCS\IDiscoveryService::class),
106
+                $server->getCloudFederationProviderManager(),
107
+                $server->getCloudFederationFactory(),
108
+                $server->getGroupManager(),
109
+                $server->getUserManager(),
110
+                $uid
111
+            );
112
+        });
113
+        $container->registerAlias(Manager::class, 'ExternalManager');
114 114
 
115
-		/**
116
-		 * Middleware
117
-		 */
118
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
119
-			return new SharingCheckMiddleware(
120
-				$c->query('AppName'),
121
-				$server->getConfig(),
122
-				$server->getAppManager(),
123
-				$c['ControllerMethodReflector'],
124
-				$server->getShareManager(),
125
-				$server->getRequest()
126
-			);
127
-		});
115
+        /**
116
+         * Middleware
117
+         */
118
+        $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
119
+            return new SharingCheckMiddleware(
120
+                $c->query('AppName'),
121
+                $server->getConfig(),
122
+                $server->getAppManager(),
123
+                $c['ControllerMethodReflector'],
124
+                $server->getShareManager(),
125
+                $server->getRequest()
126
+            );
127
+        });
128 128
 
129
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
130
-			return new OCSShareAPIMiddleware(
131
-				$server->getShareManager(),
132
-				$server->getL10N($c->query('AppName'))
133
-			);
134
-		});
129
+        $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
130
+            return new OCSShareAPIMiddleware(
131
+                $server->getShareManager(),
132
+                $server->getL10N($c->query('AppName'))
133
+            );
134
+        });
135 135
 
136
-		$container->registerService(ShareInfoMiddleware::class, function () use ($server) {
137
-			return new ShareInfoMiddleware(
138
-				$server->getShareManager()
139
-			);
140
-		});
136
+        $container->registerService(ShareInfoMiddleware::class, function () use ($server) {
137
+            return new ShareInfoMiddleware(
138
+                $server->getShareManager()
139
+            );
140
+        });
141 141
 
142
-		// Execute middlewares
143
-		$container->registerMiddleWare('SharingCheckMiddleware');
144
-		$container->registerMiddleWare('OCSShareAPIMiddleware');
145
-		$container->registerMiddleWare(ShareInfoMiddleware::class);
142
+        // Execute middlewares
143
+        $container->registerMiddleWare('SharingCheckMiddleware');
144
+        $container->registerMiddleWare('OCSShareAPIMiddleware');
145
+        $container->registerMiddleWare(ShareInfoMiddleware::class);
146 146
 
147
-		$container->registerService('MountProvider', function (IContainer $c) {
148
-			/** @var \OCP\IServerContainer $server */
149
-			$server = $c->query('ServerContainer');
150
-			return new MountProvider(
151
-				$server->getConfig(),
152
-				$server->getShareManager(),
153
-				$server->getLogger()
154
-			);
155
-		});
147
+        $container->registerService('MountProvider', function (IContainer $c) {
148
+            /** @var \OCP\IServerContainer $server */
149
+            $server = $c->query('ServerContainer');
150
+            return new MountProvider(
151
+                $server->getConfig(),
152
+                $server->getShareManager(),
153
+                $server->getLogger()
154
+            );
155
+        });
156 156
 
157
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
158
-			/** @var \OCP\IServerContainer $server */
159
-			$server = $c->query('ServerContainer');
160
-			return new \OCA\Files_Sharing\External\MountProvider(
161
-				$server->getDatabaseConnection(),
162
-				function() use ($c) {
163
-					return $c->query('ExternalManager');
164
-				},
165
-				$server->getCloudIdManager()
166
-			);
167
-		});
157
+        $container->registerService('ExternalMountProvider', function (IContainer $c) {
158
+            /** @var \OCP\IServerContainer $server */
159
+            $server = $c->query('ServerContainer');
160
+            return new \OCA\Files_Sharing\External\MountProvider(
161
+                $server->getDatabaseConnection(),
162
+                function() use ($c) {
163
+                    return $c->query('ExternalManager');
164
+                },
165
+                $server->getCloudIdManager()
166
+            );
167
+        });
168 168
 
169
-		/*
169
+        /*
170 170
 		 * Register capabilities
171 171
 		 */
172
-		$container->registerCapability(Capabilities::class);
173
-	}
172
+        $container->registerCapability(Capabilities::class);
173
+    }
174 174
 
175
-	public function registerMountProviders() {
176
-		/** @var \OCP\IServerContainer $server */
177
-		$server = $this->getContainer()->query('ServerContainer');
178
-		$mountProviderCollection = $server->getMountProviderCollection();
179
-		$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
180
-		$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
181
-	}
175
+    public function registerMountProviders() {
176
+        /** @var \OCP\IServerContainer $server */
177
+        $server = $this->getContainer()->query('ServerContainer');
178
+        $mountProviderCollection = $server->getMountProviderCollection();
179
+        $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
180
+        $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
181
+    }
182 182
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Hooks.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -32,35 +32,35 @@
 block discarded – undo
32 32
 
33 33
 class Hooks {
34 34
 
35
-	public static function deleteUser($params) {
36
-		$manager = new External\Manager(
37
-			\OC::$server->getDatabaseConnection(),
38
-			\OC\Files\Filesystem::getMountManager(),
39
-			\OC\Files\Filesystem::getLoader(),
40
-			\OC::$server->getHTTPClientService(),
41
-			\OC::$server->getNotificationManager(),
42
-			\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
43
-			\OC::$server->getCloudFederationProviderManager(),
44
-			\OC::$server->getCloudFederationFactory(),
45
-			\OC::$server->getGroupManager(),
46
-			\OC::$server->getUserManager(),
47
-			$params['uid']);
35
+    public static function deleteUser($params) {
36
+        $manager = new External\Manager(
37
+            \OC::$server->getDatabaseConnection(),
38
+            \OC\Files\Filesystem::getMountManager(),
39
+            \OC\Files\Filesystem::getLoader(),
40
+            \OC::$server->getHTTPClientService(),
41
+            \OC::$server->getNotificationManager(),
42
+            \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
43
+            \OC::$server->getCloudFederationProviderManager(),
44
+            \OC::$server->getCloudFederationFactory(),
45
+            \OC::$server->getGroupManager(),
46
+            \OC::$server->getUserManager(),
47
+            $params['uid']);
48 48
 
49
-		$manager->removeUserShares($params['uid']);
50
-	}
49
+        $manager->removeUserShares($params['uid']);
50
+    }
51 51
 
52
-	public static function unshareChildren($params) {
53
-		$path = Filesystem::getView()->getAbsolutePath($params['path']);
54
-		$view = new \OC\Files\View('/');
52
+    public static function unshareChildren($params) {
53
+        $path = Filesystem::getView()->getAbsolutePath($params['path']);
54
+        $view = new \OC\Files\View('/');
55 55
 
56
-		// find share mount points within $path and unmount them
57
-		$mountManager = \OC\Files\Filesystem::getMountManager();
58
-		$mountedShares = $mountManager->findIn($path);
59
-		foreach ($mountedShares as $mount) {
60
-			if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
61
-				$mountPoint = $mount->getMountPoint();
62
-				$view->unlink($mountPoint);
63
-			}
64
-		}
65
-	}
56
+        // find share mount points within $path and unmount them
57
+        $mountManager = \OC\Files\Filesystem::getMountManager();
58
+        $mountedShares = $mountManager->findIn($path);
59
+        foreach ($mountedShares as $mount) {
60
+            if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
61
+                $mountPoint = $mount->getMountPoint();
62
+                $view->unlink($mountPoint);
63
+            }
64
+        }
65
+    }
66 66
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationProviderManager.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -42,202 +42,202 @@
 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
-	/** @var array cache OCM end-points */
61
-	private $ocmEndPoints = [];
62
-
63
-	private $supportedAPIVersion = '1.0-proposal1';
64
-
65
-	/**
66
-	 * CloudFederationProviderManager constructor.
67
-	 *
68
-	 * @param IAppManager $appManager
69
-	 * @param IClientService $httpClientService
70
-	 * @param ICloudIdManager $cloudIdManager
71
-	 * @param ILogger $logger
72
-	 */
73
-	public function __construct(IAppManager $appManager,
74
-								IClientService $httpClientService,
75
-								ICloudIdManager $cloudIdManager,
76
-								ILogger $logger) {
77
-		$this->cloudFederationProvider= [];
78
-		$this->appManager = $appManager;
79
-		$this->httpClientService = $httpClientService;
80
-		$this->cloudIdManager = $cloudIdManager;
81
-		$this->logger = $logger;
82
-	}
83
-
84
-
85
-	/**
86
-	 * Registers an callback function which must return an cloud federation provider
87
-	 *
88
-	 * @param string $resourceType which resource type does the provider handles
89
-	 * @param string $displayName user facing name of the federated share provider
90
-	 * @param callable $callback
91
-	 */
92
-	public function addCloudFederationProvider($resourceType, $displayName, callable $callback) {
93
-		$this->cloudFederationProvider[$resourceType] = [
94
-			'resourceType' => $resourceType,
95
-			'displayName' => $displayName,
96
-			'callback' => $callback,
97
-		];
98
-
99
-	}
100
-
101
-	/**
102
-	 * remove cloud federation provider
103
-	 *
104
-	 * @param string $providerId
105
-	 */
106
-	public function removeCloudFederationProvider($providerId) {
107
-		unset($this->cloudFederationProvider[$providerId]);
108
-	}
109
-
110
-	/**
111
-	 * get a list of all cloudFederationProviders
112
-	 *
113
-	 * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]]
114
-	 */
115
-	public function getAllCloudFederationProviders() {
116
-		return $this->cloudFederationProvider;
117
-	}
118
-
119
-	/**
120
-	 * get a specific cloud federation provider
121
-	 *
122
-	 * @param string $resourceType
123
-	 * @return ICloudFederationProvider
124
-	 * @throws ProviderDoesNotExistsException
125
-	 */
126
-	public function getCloudFederationProvider($resourceType) {
127
-		if (isset($this->cloudFederationProvider[$resourceType])) {
128
-			return call_user_func($this->cloudFederationProvider[$resourceType]['callback']);
129
-		} else {
130
-			throw new ProviderDoesNotExistsException($resourceType);
131
-		}
132
-	}
133
-
134
-	public function sendShare(ICloudFederationShare $share) {
135
-		$cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
136
-		$ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
137
-
138
-		if (empty($ocmEndPoint)) {
139
-			return false;
140
-		}
141
-
142
-		$client = $this->httpClientService->newClient();
143
-		try {
144
-			$response = $client->post($ocmEndPoint . '/shares', [
145
-				'body' => $share->getShare(),
146
-				'timeout' => 10,
147
-				'connect_timeout' => 10,
148
-			]);
149
-
150
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
151
-				$result = json_decode($response->getBody(), true);
152
-				return (is_array($result)) ? $result : [];
153
-			}
154
-
155
-		} catch (\Exception $e) {
156
-			// if flat re-sharing is not supported by the remote server
157
-			// we re-throw the exception and fall back to the old behaviour.
158
-			// (flat re-shares has been introduced in Nextcloud 9.1)
159
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
160
-				$this->logger->debug($e->getMessage());
161
-				throw $e;
162
-			}
163
-		}
164
-
165
-		return false;
166
-
167
-	}
168
-
169
-	/**
170
-	 * @param string $url
171
-	 * @param ICloudFederationNotification $notification
172
-	 * @return mixed
173
-	 */
174
-	public function sendNotification($url, ICloudFederationNotification $notification) {
175
-		$ocmEndPoint = $this->getOCMEndPoint($url);
176
-
177
-		if (empty($ocmEndPoint)) {
178
-			return false;
179
-		}
180
-
181
-		$client = $this->httpClientService->newClient();
182
-		try {
183
-			$response = $client->post($ocmEndPoint . '/notifications', [
184
-				'body' => $notification->getMessage(),
185
-				'timeout' => 10,
186
-				'connect_timeout' => 10,
187
-			]);
188
-			if ($response->getStatusCode() === Http::STATUS_CREATED) {
189
-				$result = json_decode($response->getBody(), true);
190
-				return (is_array($result)) ? $result : [];
191
-			}
192
-		} catch (\Exception $e) {
193
-			// log the error and return false
194
-			$this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
195
-		}
196
-
197
-		return false;
198
-	}
199
-
200
-	/**
201
-	 * check if the new cloud federation API is ready to be used
202
-	 *
203
-	 * @return bool
204
-	 */
205
-	public function isReady() {
206
-		return $this->appManager->isEnabledForUser('cloud_federation_api');
207
-	}
208
-	/**
209
-	 * check if server supports the new OCM api and ask for the correct end-point
210
-	 *
211
-	 * @param string $url full base URL of the cloud server
212
-	 * @return string
213
-	 */
214
-	protected function getOCMEndPoint($url) {
215
-
216
-		if (isset($this->ocmEndPoints[$url])) {
217
-			return $this->ocmEndPoints[$url];
218
-		}
219
-
220
-		$client = $this->httpClientService->newClient();
221
-		try {
222
-			$response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
223
-		} catch (\Exception $e) {
224
-			$this->ocmEndPoints[$url] = '';
225
-			return '';
226
-		}
227
-
228
-		$result = $response->getBody();
229
-		$result = json_decode($result, true);
230
-
231
-		$supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
232
-
233
-		if (isset($result['endPoint']) && $supportedVersion) {
234
-			$this->ocmEndPoints[$url] = $result['endPoint'];
235
-			return $result['endPoint'];
236
-		}
237
-
238
-		$this->ocmEndPoints[$url] = '';
239
-		return '';
240
-	}
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
+    /** @var array cache OCM end-points */
61
+    private $ocmEndPoints = [];
62
+
63
+    private $supportedAPIVersion = '1.0-proposal1';
64
+
65
+    /**
66
+     * CloudFederationProviderManager constructor.
67
+     *
68
+     * @param IAppManager $appManager
69
+     * @param IClientService $httpClientService
70
+     * @param ICloudIdManager $cloudIdManager
71
+     * @param ILogger $logger
72
+     */
73
+    public function __construct(IAppManager $appManager,
74
+                                IClientService $httpClientService,
75
+                                ICloudIdManager $cloudIdManager,
76
+                                ILogger $logger) {
77
+        $this->cloudFederationProvider= [];
78
+        $this->appManager = $appManager;
79
+        $this->httpClientService = $httpClientService;
80
+        $this->cloudIdManager = $cloudIdManager;
81
+        $this->logger = $logger;
82
+    }
83
+
84
+
85
+    /**
86
+     * Registers an callback function which must return an cloud federation provider
87
+     *
88
+     * @param string $resourceType which resource type does the provider handles
89
+     * @param string $displayName user facing name of the federated share provider
90
+     * @param callable $callback
91
+     */
92
+    public function addCloudFederationProvider($resourceType, $displayName, callable $callback) {
93
+        $this->cloudFederationProvider[$resourceType] = [
94
+            'resourceType' => $resourceType,
95
+            'displayName' => $displayName,
96
+            'callback' => $callback,
97
+        ];
98
+
99
+    }
100
+
101
+    /**
102
+     * remove cloud federation provider
103
+     *
104
+     * @param string $providerId
105
+     */
106
+    public function removeCloudFederationProvider($providerId) {
107
+        unset($this->cloudFederationProvider[$providerId]);
108
+    }
109
+
110
+    /**
111
+     * get a list of all cloudFederationProviders
112
+     *
113
+     * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]]
114
+     */
115
+    public function getAllCloudFederationProviders() {
116
+        return $this->cloudFederationProvider;
117
+    }
118
+
119
+    /**
120
+     * get a specific cloud federation provider
121
+     *
122
+     * @param string $resourceType
123
+     * @return ICloudFederationProvider
124
+     * @throws ProviderDoesNotExistsException
125
+     */
126
+    public function getCloudFederationProvider($resourceType) {
127
+        if (isset($this->cloudFederationProvider[$resourceType])) {
128
+            return call_user_func($this->cloudFederationProvider[$resourceType]['callback']);
129
+        } else {
130
+            throw new ProviderDoesNotExistsException($resourceType);
131
+        }
132
+    }
133
+
134
+    public function sendShare(ICloudFederationShare $share) {
135
+        $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith());
136
+        $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote());
137
+
138
+        if (empty($ocmEndPoint)) {
139
+            return false;
140
+        }
141
+
142
+        $client = $this->httpClientService->newClient();
143
+        try {
144
+            $response = $client->post($ocmEndPoint . '/shares', [
145
+                'body' => $share->getShare(),
146
+                'timeout' => 10,
147
+                'connect_timeout' => 10,
148
+            ]);
149
+
150
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
151
+                $result = json_decode($response->getBody(), true);
152
+                return (is_array($result)) ? $result : [];
153
+            }
154
+
155
+        } catch (\Exception $e) {
156
+            // if flat re-sharing is not supported by the remote server
157
+            // we re-throw the exception and fall back to the old behaviour.
158
+            // (flat re-shares has been introduced in Nextcloud 9.1)
159
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
160
+                $this->logger->debug($e->getMessage());
161
+                throw $e;
162
+            }
163
+        }
164
+
165
+        return false;
166
+
167
+    }
168
+
169
+    /**
170
+     * @param string $url
171
+     * @param ICloudFederationNotification $notification
172
+     * @return mixed
173
+     */
174
+    public function sendNotification($url, ICloudFederationNotification $notification) {
175
+        $ocmEndPoint = $this->getOCMEndPoint($url);
176
+
177
+        if (empty($ocmEndPoint)) {
178
+            return false;
179
+        }
180
+
181
+        $client = $this->httpClientService->newClient();
182
+        try {
183
+            $response = $client->post($ocmEndPoint . '/notifications', [
184
+                'body' => $notification->getMessage(),
185
+                'timeout' => 10,
186
+                'connect_timeout' => 10,
187
+            ]);
188
+            if ($response->getStatusCode() === Http::STATUS_CREATED) {
189
+                $result = json_decode($response->getBody(), true);
190
+                return (is_array($result)) ? $result : [];
191
+            }
192
+        } catch (\Exception $e) {
193
+            // log the error and return false
194
+            $this->logger->error('error while sending notification for federated share: ' . $e->getMessage());
195
+        }
196
+
197
+        return false;
198
+    }
199
+
200
+    /**
201
+     * check if the new cloud federation API is ready to be used
202
+     *
203
+     * @return bool
204
+     */
205
+    public function isReady() {
206
+        return $this->appManager->isEnabledForUser('cloud_federation_api');
207
+    }
208
+    /**
209
+     * check if server supports the new OCM api and ask for the correct end-point
210
+     *
211
+     * @param string $url full base URL of the cloud server
212
+     * @return string
213
+     */
214
+    protected function getOCMEndPoint($url) {
215
+
216
+        if (isset($this->ocmEndPoints[$url])) {
217
+            return $this->ocmEndPoints[$url];
218
+        }
219
+
220
+        $client = $this->httpClientService->newClient();
221
+        try {
222
+            $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]);
223
+        } catch (\Exception $e) {
224
+            $this->ocmEndPoints[$url] = '';
225
+            return '';
226
+        }
227
+
228
+        $result = $response->getBody();
229
+        $result = json_decode($result, true);
230
+
231
+        $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion;
232
+
233
+        if (isset($result['endPoint']) && $supportedVersion) {
234
+            $this->ocmEndPoints[$url] = $result['endPoint'];
235
+            return $result['endPoint'];
236
+        }
237
+
238
+        $this->ocmEndPoints[$url] = '';
239
+        return '';
240
+    }
241 241
 
242 242
 
243 243
 }
Please login to merge, or discard this patch.