Completed
Push — stable13 ( 593e59...c61018 )
by
unknown
21:28 queued 11:27
created
apps/federation/lib/Command/SyncFederationAddressBooks.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
 		$progress->start();
61 61
 		$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
62 62
 			if ($ex instanceof \Exception) {
63
-				$output->writeln("Error while syncing $url : " . $ex->getMessage());
63
+				$output->writeln("Error while syncing $url : ".$ex->getMessage());
64 64
 
65 65
 			} else {
66 66
 				$progress->advance();
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -30,45 +30,45 @@
 block discarded – undo
30 30
 
31 31
 class SyncFederationAddressBooks extends Command {
32 32
 
33
-	/** @var \OCA\Federation\SyncFederationAddressBooks */
34
-	private $syncService;
33
+    /** @var \OCA\Federation\SyncFederationAddressBooks */
34
+    private $syncService;
35 35
 
36
-	/**
37
-	 * @param \OCA\Federation\SyncFederationAddressBooks $syncService
38
-	 */
39
-	public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
40
-		parent::__construct();
36
+    /**
37
+     * @param \OCA\Federation\SyncFederationAddressBooks $syncService
38
+     */
39
+    public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
40
+        parent::__construct();
41 41
 
42
-		$this->syncService = $syncService;
43
-	}
42
+        $this->syncService = $syncService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('federation:sync-addressbooks')
48
-			->setDescription('Synchronizes addressbooks of all federated clouds');
49
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('federation:sync-addressbooks')
48
+            ->setDescription('Synchronizes addressbooks of all federated clouds');
49
+    }
50 50
 
51
-	/**
52
-	 * @param InputInterface $input
53
-	 * @param OutputInterface $output
54
-	 * @return int
55
-	 */
56
-	protected function execute(InputInterface $input, OutputInterface $output) {
51
+    /**
52
+     * @param InputInterface $input
53
+     * @param OutputInterface $output
54
+     * @return int
55
+     */
56
+    protected function execute(InputInterface $input, OutputInterface $output) {
57 57
 
58
-		$progress = new ProgressBar($output);
59
-		$progress->start();
60
-		$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
61
-			if ($ex instanceof \Exception) {
62
-				$output->writeln("Error while syncing $url : " . $ex->getMessage());
58
+        $progress = new ProgressBar($output);
59
+        $progress->start();
60
+        $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
61
+            if ($ex instanceof \Exception) {
62
+                $output->writeln("Error while syncing $url : " . $ex->getMessage());
63 63
 
64
-			} else {
65
-				$progress->advance();
66
-			}
67
-		});
64
+            } else {
65
+                $progress->advance();
66
+            }
67
+        });
68 68
 
69
-		$progress->finish();
70
-		$output->writeln('');
69
+        $progress->finish();
70
+        $output->writeln('');
71 71
 
72
-		return 0;
73
-	}
72
+        return 0;
73
+    }
74 74
 }
Please login to merge, or discard this patch.
apps/federation/lib/TrustedServers.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		$client = $this->httpClientService->newClient();
222 222
 		try {
223 223
 			$result = $client->get(
224
-				$url . '/status.php',
224
+				$url.'/status.php',
225 225
 				[
226 226
 					'timeout' => 3,
227 227
 					'connect_timeout' => 3,
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 
233 233
 			}
234 234
 		} catch (\Exception $e) {
235
-			$this->logger->debug('No Nextcloud server: ' . $e->getMessage());
235
+			$this->logger->debug('No Nextcloud server: '.$e->getMessage());
236 236
 			return false;
237 237
 		}
238 238
 
@@ -273,6 +273,6 @@  discard block
 block discarded – undo
273 273
 
274 274
 		}
275 275
 
276
-		return 'https://' . $url;
276
+		return 'https://'.$url;
277 277
 	}
278 278
 }
Please login to merge, or discard this patch.
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -39,248 +39,248 @@
 block discarded – undo
39 39
 
40 40
 class TrustedServers {
41 41
 
42
-	/** after a user list was exchanged at least once successfully */
43
-	const STATUS_OK = 1;
44
-	/** waiting for shared secret or initial user list exchange */
45
-	const STATUS_PENDING = 2;
46
-	/** something went wrong, misconfigured server, software bug,... user interaction needed */
47
-	const STATUS_FAILURE = 3;
48
-	/** remote server revoked access */
49
-	const STATUS_ACCESS_REVOKED = 4;
50
-
51
-	/** @var  dbHandler */
52
-	private $dbHandler;
53
-
54
-	/** @var  IClientService */
55
-	private $httpClientService;
56
-
57
-	/** @var ILogger */
58
-	private $logger;
59
-
60
-	/** @var IJobList */
61
-	private $jobList;
62
-
63
-	/** @var ISecureRandom */
64
-	private $secureRandom;
65
-
66
-	/** @var IConfig */
67
-	private $config;
68
-
69
-	/** @var EventDispatcherInterface */
70
-	private $dispatcher;
71
-
72
-	/** @var ITimeFactory */
73
-	private $timeFactory;
74
-
75
-	/**
76
-	 * @param DbHandler $dbHandler
77
-	 * @param IClientService $httpClientService
78
-	 * @param ILogger $logger
79
-	 * @param IJobList $jobList
80
-	 * @param ISecureRandom $secureRandom
81
-	 * @param IConfig $config
82
-	 * @param EventDispatcherInterface $dispatcher
83
-	 * @param ITimeFactory $timeFactory
84
-	 */
85
-	public function __construct(
86
-		DbHandler $dbHandler,
87
-		IClientService $httpClientService,
88
-		ILogger $logger,
89
-		IJobList $jobList,
90
-		ISecureRandom $secureRandom,
91
-		IConfig $config,
92
-		EventDispatcherInterface $dispatcher,
93
-		ITimeFactory $timeFactory
94
-	) {
95
-		$this->dbHandler = $dbHandler;
96
-		$this->httpClientService = $httpClientService;
97
-		$this->logger = $logger;
98
-		$this->jobList = $jobList;
99
-		$this->secureRandom = $secureRandom;
100
-		$this->config = $config;
101
-		$this->dispatcher = $dispatcher;
102
-		$this->timeFactory = $timeFactory;
103
-	}
104
-
105
-	/**
106
-	 * add server to the list of trusted servers
107
-	 *
108
-	 * @param $url
109
-	 * @return int server id
110
-	 */
111
-	public function addServer($url) {
112
-		$url = $this->updateProtocol($url);
113
-		$result = $this->dbHandler->addServer($url);
114
-		if ($result) {
115
-			$token = $this->secureRandom->generate(16);
116
-			$this->dbHandler->addToken($url, $token);
117
-			$this->jobList->add(
118
-				'OCA\Federation\BackgroundJob\RequestSharedSecret',
119
-				[
120
-					'url' => $url,
121
-					'token' => $token,
122
-					'created' => $this->timeFactory->getTime()
123
-				]
124
-			);
125
-		}
126
-
127
-		return $result;
128
-	}
129
-
130
-	/**
131
-	 * enable/disable to automatically add servers to the list of trusted servers
132
-	 * once a federated share was created and accepted successfully
133
-	 *
134
-	 * @param bool $status
135
-	 */
136
-	public function setAutoAddServers($status) {
137
-		$value = $status ? '1' : '0';
138
-		$this->config->setAppValue('federation', 'autoAddServers', $value);
139
-	}
140
-
141
-	/**
142
-	 * return if we automatically add servers to the list of trusted servers
143
-	 * once a federated share was created and accepted successfully
144
-	 *
145
-	 * @return bool
146
-	 */
147
-	public function getAutoAddServers() {
148
-		$value = $this->config->getAppValue('federation', 'autoAddServers', '0');
149
-		return $value === '1';
150
-	}
151
-
152
-	/**
153
-	 * get shared secret for the given server
154
-	 *
155
-	 * @param string $url
156
-	 * @return string
157
-	 */
158
-	public function getSharedSecret($url) {
159
-		return $this->dbHandler->getSharedSecret($url);
160
-	}
161
-
162
-	/**
163
-	 * add shared secret for the given server
164
-	 *
165
-	 * @param string $url
166
-	 * @param $sharedSecret
167
-	 */
168
-	public function addSharedSecret($url, $sharedSecret) {
169
-		$this->dbHandler->addSharedSecret($url, $sharedSecret);
170
-	}
171
-
172
-	/**
173
-	 * remove server from the list of trusted servers
174
-	 *
175
-	 * @param int $id
176
-	 */
177
-	public function removeServer($id) {
178
-		$server = $this->dbHandler->getServerById($id);
179
-		$this->dbHandler->removeServer($id);
180
-		$event = new GenericEvent($server['url_hash']);
181
-		$this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event);
182
-	}
183
-
184
-	/**
185
-	 * get all trusted servers
186
-	 *
187
-	 * @return array
188
-	 */
189
-	public function getServers() {
190
-		return $this->dbHandler->getAllServer();
191
-	}
192
-
193
-	/**
194
-	 * check if given server is a trusted Nextcloud server
195
-	 *
196
-	 * @param string $url
197
-	 * @return bool
198
-	 */
199
-	public function isTrustedServer($url) {
200
-		return $this->dbHandler->serverExists($url);
201
-	}
202
-
203
-	/**
204
-	 * set server status
205
-	 *
206
-	 * @param string $url
207
-	 * @param int $status
208
-	 */
209
-	public function setServerStatus($url, $status) {
210
-		$this->dbHandler->setServerStatus($url, $status);
211
-	}
212
-
213
-	/**
214
-	 * @param string $url
215
-	 * @return int
216
-	 */
217
-	public function getServerStatus($url) {
218
-		return $this->dbHandler->getServerStatus($url);
219
-	}
220
-
221
-	/**
222
-	 * check if URL point to a ownCloud/Nextcloud server
223
-	 *
224
-	 * @param string $url
225
-	 * @return bool
226
-	 */
227
-	public function isOwnCloudServer($url) {
228
-		$isValidOwnCloud = false;
229
-		$client = $this->httpClientService->newClient();
230
-		try {
231
-			$result = $client->get(
232
-				$url . '/status.php',
233
-				[
234
-					'timeout' => 3,
235
-					'connect_timeout' => 3,
236
-				]
237
-			);
238
-			if ($result->getStatusCode() === Http::STATUS_OK) {
239
-				$isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());
240
-
241
-			}
242
-		} catch (\Exception $e) {
243
-			$this->logger->debug('No Nextcloud server: ' . $e->getMessage());
244
-			return false;
245
-		}
246
-
247
-		return $isValidOwnCloud;
248
-	}
249
-
250
-	/**
251
-	 * check if ownCloud version is >= 9.0
252
-	 *
253
-	 * @param $status
254
-	 * @return bool
255
-	 * @throws HintException
256
-	 */
257
-	protected function checkOwnCloudVersion($status) {
258
-		$decoded = json_decode($status, true);
259
-		if (!empty($decoded) && isset($decoded['version'])) {
260
-			if (!version_compare($decoded['version'], '9.0.0', '>=')) {
261
-				throw new HintException('Remote server version is too low. 9.0 is required.');
262
-			}
263
-			return true;
264
-		}
265
-		return false;
266
-	}
267
-
268
-	/**
269
-	 * check if the URL contain a protocol, if not add https
270
-	 *
271
-	 * @param string $url
272
-	 * @return string
273
-	 */
274
-	protected function updateProtocol($url) {
275
-		if (
276
-			strpos($url, 'https://') === 0
277
-			|| strpos($url, 'http://') === 0
278
-		) {
279
-
280
-			return $url;
281
-
282
-		}
283
-
284
-		return 'https://' . $url;
285
-	}
42
+    /** after a user list was exchanged at least once successfully */
43
+    const STATUS_OK = 1;
44
+    /** waiting for shared secret or initial user list exchange */
45
+    const STATUS_PENDING = 2;
46
+    /** something went wrong, misconfigured server, software bug,... user interaction needed */
47
+    const STATUS_FAILURE = 3;
48
+    /** remote server revoked access */
49
+    const STATUS_ACCESS_REVOKED = 4;
50
+
51
+    /** @var  dbHandler */
52
+    private $dbHandler;
53
+
54
+    /** @var  IClientService */
55
+    private $httpClientService;
56
+
57
+    /** @var ILogger */
58
+    private $logger;
59
+
60
+    /** @var IJobList */
61
+    private $jobList;
62
+
63
+    /** @var ISecureRandom */
64
+    private $secureRandom;
65
+
66
+    /** @var IConfig */
67
+    private $config;
68
+
69
+    /** @var EventDispatcherInterface */
70
+    private $dispatcher;
71
+
72
+    /** @var ITimeFactory */
73
+    private $timeFactory;
74
+
75
+    /**
76
+     * @param DbHandler $dbHandler
77
+     * @param IClientService $httpClientService
78
+     * @param ILogger $logger
79
+     * @param IJobList $jobList
80
+     * @param ISecureRandom $secureRandom
81
+     * @param IConfig $config
82
+     * @param EventDispatcherInterface $dispatcher
83
+     * @param ITimeFactory $timeFactory
84
+     */
85
+    public function __construct(
86
+        DbHandler $dbHandler,
87
+        IClientService $httpClientService,
88
+        ILogger $logger,
89
+        IJobList $jobList,
90
+        ISecureRandom $secureRandom,
91
+        IConfig $config,
92
+        EventDispatcherInterface $dispatcher,
93
+        ITimeFactory $timeFactory
94
+    ) {
95
+        $this->dbHandler = $dbHandler;
96
+        $this->httpClientService = $httpClientService;
97
+        $this->logger = $logger;
98
+        $this->jobList = $jobList;
99
+        $this->secureRandom = $secureRandom;
100
+        $this->config = $config;
101
+        $this->dispatcher = $dispatcher;
102
+        $this->timeFactory = $timeFactory;
103
+    }
104
+
105
+    /**
106
+     * add server to the list of trusted servers
107
+     *
108
+     * @param $url
109
+     * @return int server id
110
+     */
111
+    public function addServer($url) {
112
+        $url = $this->updateProtocol($url);
113
+        $result = $this->dbHandler->addServer($url);
114
+        if ($result) {
115
+            $token = $this->secureRandom->generate(16);
116
+            $this->dbHandler->addToken($url, $token);
117
+            $this->jobList->add(
118
+                'OCA\Federation\BackgroundJob\RequestSharedSecret',
119
+                [
120
+                    'url' => $url,
121
+                    'token' => $token,
122
+                    'created' => $this->timeFactory->getTime()
123
+                ]
124
+            );
125
+        }
126
+
127
+        return $result;
128
+    }
129
+
130
+    /**
131
+     * enable/disable to automatically add servers to the list of trusted servers
132
+     * once a federated share was created and accepted successfully
133
+     *
134
+     * @param bool $status
135
+     */
136
+    public function setAutoAddServers($status) {
137
+        $value = $status ? '1' : '0';
138
+        $this->config->setAppValue('federation', 'autoAddServers', $value);
139
+    }
140
+
141
+    /**
142
+     * return if we automatically add servers to the list of trusted servers
143
+     * once a federated share was created and accepted successfully
144
+     *
145
+     * @return bool
146
+     */
147
+    public function getAutoAddServers() {
148
+        $value = $this->config->getAppValue('federation', 'autoAddServers', '0');
149
+        return $value === '1';
150
+    }
151
+
152
+    /**
153
+     * get shared secret for the given server
154
+     *
155
+     * @param string $url
156
+     * @return string
157
+     */
158
+    public function getSharedSecret($url) {
159
+        return $this->dbHandler->getSharedSecret($url);
160
+    }
161
+
162
+    /**
163
+     * add shared secret for the given server
164
+     *
165
+     * @param string $url
166
+     * @param $sharedSecret
167
+     */
168
+    public function addSharedSecret($url, $sharedSecret) {
169
+        $this->dbHandler->addSharedSecret($url, $sharedSecret);
170
+    }
171
+
172
+    /**
173
+     * remove server from the list of trusted servers
174
+     *
175
+     * @param int $id
176
+     */
177
+    public function removeServer($id) {
178
+        $server = $this->dbHandler->getServerById($id);
179
+        $this->dbHandler->removeServer($id);
180
+        $event = new GenericEvent($server['url_hash']);
181
+        $this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event);
182
+    }
183
+
184
+    /**
185
+     * get all trusted servers
186
+     *
187
+     * @return array
188
+     */
189
+    public function getServers() {
190
+        return $this->dbHandler->getAllServer();
191
+    }
192
+
193
+    /**
194
+     * check if given server is a trusted Nextcloud server
195
+     *
196
+     * @param string $url
197
+     * @return bool
198
+     */
199
+    public function isTrustedServer($url) {
200
+        return $this->dbHandler->serverExists($url);
201
+    }
202
+
203
+    /**
204
+     * set server status
205
+     *
206
+     * @param string $url
207
+     * @param int $status
208
+     */
209
+    public function setServerStatus($url, $status) {
210
+        $this->dbHandler->setServerStatus($url, $status);
211
+    }
212
+
213
+    /**
214
+     * @param string $url
215
+     * @return int
216
+     */
217
+    public function getServerStatus($url) {
218
+        return $this->dbHandler->getServerStatus($url);
219
+    }
220
+
221
+    /**
222
+     * check if URL point to a ownCloud/Nextcloud server
223
+     *
224
+     * @param string $url
225
+     * @return bool
226
+     */
227
+    public function isOwnCloudServer($url) {
228
+        $isValidOwnCloud = false;
229
+        $client = $this->httpClientService->newClient();
230
+        try {
231
+            $result = $client->get(
232
+                $url . '/status.php',
233
+                [
234
+                    'timeout' => 3,
235
+                    'connect_timeout' => 3,
236
+                ]
237
+            );
238
+            if ($result->getStatusCode() === Http::STATUS_OK) {
239
+                $isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());
240
+
241
+            }
242
+        } catch (\Exception $e) {
243
+            $this->logger->debug('No Nextcloud server: ' . $e->getMessage());
244
+            return false;
245
+        }
246
+
247
+        return $isValidOwnCloud;
248
+    }
249
+
250
+    /**
251
+     * check if ownCloud version is >= 9.0
252
+     *
253
+     * @param $status
254
+     * @return bool
255
+     * @throws HintException
256
+     */
257
+    protected function checkOwnCloudVersion($status) {
258
+        $decoded = json_decode($status, true);
259
+        if (!empty($decoded) && isset($decoded['version'])) {
260
+            if (!version_compare($decoded['version'], '9.0.0', '>=')) {
261
+                throw new HintException('Remote server version is too low. 9.0 is required.');
262
+            }
263
+            return true;
264
+        }
265
+        return false;
266
+    }
267
+
268
+    /**
269
+     * check if the URL contain a protocol, if not add https
270
+     *
271
+     * @param string $url
272
+     * @return string
273
+     */
274
+    protected function updateProtocol($url) {
275
+        if (
276
+            strpos($url, 'https://') === 0
277
+            || strpos($url, 'http://') === 0
278
+        ) {
279
+
280
+            return $url;
281
+
282
+        }
283
+
284
+        return 'https://' . $url;
285
+    }
286 286
 }
Please login to merge, or discard this patch.
apps/federation/lib/Settings/Admin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -29,41 +29,41 @@
 block discarded – undo
29 29
 
30 30
 class Admin implements ISettings {
31 31
 
32
-	/** @var TrustedServers */
33
-	private $trustedServers;
32
+    /** @var TrustedServers */
33
+    private $trustedServers;
34 34
 
35
-	public function __construct(TrustedServers $trustedServers) {
36
-		$this->trustedServers = $trustedServers;
37
-	}
35
+    public function __construct(TrustedServers $trustedServers) {
36
+        $this->trustedServers = $trustedServers;
37
+    }
38 38
 
39
-	/**
40
-	 * @return TemplateResponse
41
-	 */
42
-	public function getForm() {
43
-		$parameters = [
44
-			'trustedServers' => $this->trustedServers->getServers(),
45
-			'autoAddServers' => $this->trustedServers->getAutoAddServers(),
46
-		];
39
+    /**
40
+     * @return TemplateResponse
41
+     */
42
+    public function getForm() {
43
+        $parameters = [
44
+            'trustedServers' => $this->trustedServers->getServers(),
45
+            'autoAddServers' => $this->trustedServers->getAutoAddServers(),
46
+        ];
47 47
 
48
-		return new TemplateResponse('federation', 'settings-admin', $parameters, '');
49
-	}
48
+        return new TemplateResponse('federation', 'settings-admin', $parameters, '');
49
+    }
50 50
 
51
-	/**
52
-	 * @return string the section ID, e.g. 'sharing'
53
-	 */
54
-	public function getSection() {
55
-		return 'sharing';
56
-	}
51
+    /**
52
+     * @return string the section ID, e.g. 'sharing'
53
+     */
54
+    public function getSection() {
55
+        return 'sharing';
56
+    }
57 57
 
58
-	/**
59
-	 * @return int whether the form should be rather on the top or bottom of
60
-	 * the admin section. The forms are arranged in ascending order of the
61
-	 * priority values. It is required to return a value between 0 and 100.
62
-	 *
63
-	 * E.g.: 70
64
-	 */
65
-	public function getPriority() {
66
-		return 30;
67
-	}
58
+    /**
59
+     * @return int whether the form should be rather on the top or bottom of
60
+     * the admin section. The forms are arranged in ascending order of the
61
+     * priority values. It is required to return a value between 0 and 100.
62
+     *
63
+     * E.g.: 70
64
+     */
65
+    public function getPriority() {
66
+        return 30;
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
apps/federation/lib/Hooks.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,25 +27,25 @@
 block discarded – undo
27 27
 
28 28
 class Hooks {
29 29
 
30
-	/** @var TrustedServers */
31
-	private $trustedServers;
32
-
33
-	public function __construct(TrustedServers $trustedServers) {
34
-		$this->trustedServers = $trustedServers;
35
-	}
36
-
37
-	/**
38
-	 * add servers to the list of trusted servers once a federated share was established
39
-	 *
40
-	 * @param array $params
41
-	 */
42
-	public function addServerHook($params) {
43
-		if (
44
-			$this->trustedServers->getAutoAddServers() === true &&
45
-			$this->trustedServers->isTrustedServer($params['server']) === false
46
-		) {
47
-			$this->trustedServers->addServer($params['server']);
48
-		}
49
-	}
30
+    /** @var TrustedServers */
31
+    private $trustedServers;
32
+
33
+    public function __construct(TrustedServers $trustedServers) {
34
+        $this->trustedServers = $trustedServers;
35
+    }
36
+
37
+    /**
38
+     * add servers to the list of trusted servers once a federated share was established
39
+     *
40
+     * @param array $params
41
+     */
42
+    public function addServerHook($params) {
43
+        if (
44
+            $this->trustedServers->getAutoAddServers() === true &&
45
+            $this->trustedServers->isTrustedServer($params['server']) === false
46
+        ) {
47
+            $this->trustedServers->addServer($params['server']);
48
+        }
49
+    }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/PublicAuth.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -26,67 +26,67 @@
 block discarded – undo
26 26
 
27 27
 class PublicAuth implements BackendInterface {
28 28
 
29
-	/** @var string[] */
30
-	private $publicURLs;
29
+    /** @var string[] */
30
+    private $publicURLs;
31 31
 
32
-	public function __construct() {
33
-		$this->publicURLs = [
34
-			'public-calendars',
35
-			'principals/system/public'
36
-		];
37
-	}
32
+    public function __construct() {
33
+        $this->publicURLs = [
34
+            'public-calendars',
35
+            'principals/system/public'
36
+        ];
37
+    }
38 38
 
39
-	/**
40
-	 * When this method is called, the backend must check if authentication was
41
-	 * successful.
42
-	 *
43
-	 * The returned value must be one of the following
44
-	 *
45
-	 * [true, "principals/username"]
46
-	 * [false, "reason for failure"]
47
-	 *
48
-	 * If authentication was successful, it's expected that the authentication
49
-	 * backend returns a so-called principal url.
50
-	 *
51
-	 * Examples of a principal url:
52
-	 *
53
-	 * principals/admin
54
-	 * principals/user1
55
-	 * principals/users/joe
56
-	 * principals/uid/123457
57
-	 *
58
-	 * If you don't use WebDAV ACL (RFC3744) we recommend that you simply
59
-	 * return a string such as:
60
-	 *
61
-	 * principals/users/[username]
62
-	 *
63
-	 * @param RequestInterface $request
64
-	 * @param ResponseInterface $response
65
-	 * @return array
66
-	 */
67
-	function check(RequestInterface $request, ResponseInterface $response) {
39
+    /**
40
+     * When this method is called, the backend must check if authentication was
41
+     * successful.
42
+     *
43
+     * The returned value must be one of the following
44
+     *
45
+     * [true, "principals/username"]
46
+     * [false, "reason for failure"]
47
+     *
48
+     * If authentication was successful, it's expected that the authentication
49
+     * backend returns a so-called principal url.
50
+     *
51
+     * Examples of a principal url:
52
+     *
53
+     * principals/admin
54
+     * principals/user1
55
+     * principals/users/joe
56
+     * principals/uid/123457
57
+     *
58
+     * If you don't use WebDAV ACL (RFC3744) we recommend that you simply
59
+     * return a string such as:
60
+     *
61
+     * principals/users/[username]
62
+     *
63
+     * @param RequestInterface $request
64
+     * @param ResponseInterface $response
65
+     * @return array
66
+     */
67
+    function check(RequestInterface $request, ResponseInterface $response) {
68 68
 
69
-		if ($this->isRequestPublic($request)) {
70
-			return [true, "principals/system/public"];
71
-		}
72
-		return [false, "No public access to this resource."];
73
-	}
69
+        if ($this->isRequestPublic($request)) {
70
+            return [true, "principals/system/public"];
71
+        }
72
+        return [false, "No public access to this resource."];
73
+    }
74 74
 
75
-	/**
76
-	 * @inheritdoc
77
-	 */
78
-	function challenge(RequestInterface $request, ResponseInterface $response) {
79
-	}
75
+    /**
76
+     * @inheritdoc
77
+     */
78
+    function challenge(RequestInterface $request, ResponseInterface $response) {
79
+    }
80 80
 
81
-	/**
82
-	 * @param RequestInterface $request
83
-	 * @return bool
84
-	 */
85
-	private function isRequestPublic(RequestInterface $request) {
86
-		$url = $request->getPath();
87
-		$matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) {
88
-			return strpos($url, $publicUrl, 0) === 0;
89
-		});
90
-		return !empty($matchingUrls);
91
-	}
81
+    /**
82
+     * @param RequestInterface $request
83
+     * @return bool
84
+     */
85
+    private function isRequestPublic(RequestInterface $request) {
86
+        $url = $request->getPath();
87
+        $matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) {
88
+            return strpos($url, $publicUrl, 0) === 0;
89
+        });
90
+        return !empty($matchingUrls);
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 	 */
85 85
 	private function isRequestPublic(RequestInterface $request) {
86 86
 		$url = $request->getPath();
87
-		$matchingUrls = array_filter($this->publicURLs, function ($publicUrl) use ($url) {
87
+		$matchingUrls = array_filter($this->publicURLs, function($publicUrl) use ($url) {
88 88
 			return strpos($url, $publicUrl, 0) === 0;
89 89
 		});
90 90
 		return !empty($matchingUrls);
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
     static function xmlDeserialize(Reader $reader) {
48 48
 
49 49
         $elements = $reader->parseInnerTree([
50
-            '{' . Plugin::NS_OWNCLOUD. '}set'    => 'Sabre\\Xml\\Element\\KeyValue',
51
-            '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
50
+            '{'.Plugin::NS_OWNCLOUD.'}set'    => 'Sabre\\Xml\\Element\\KeyValue',
51
+            '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue',
52 52
         ]);
53 53
 
54 54
         $set = [];
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
         foreach ($elements as $elem) {
58 58
             switch ($elem['name']) {
59 59
 
60
-                case '{' . Plugin::NS_OWNCLOUD . '}set' :
60
+                case '{'.Plugin::NS_OWNCLOUD.'}set' :
61 61
                     $sharee = $elem['value'];
62 62
 
63
-                    $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary';
64
-                    $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name';
63
+                    $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary';
64
+                    $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name';
65 65
 
66 66
                     $set[] = [
67 67
                         'href'       => $sharee['{DAV:}href'],
68 68
                         'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
69 69
                         'summary'    => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
70
-                        'readOnly'   => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
70
+                        'readOnly'   => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee),
71 71
                     ];
72 72
                     break;
73 73
 
74
-                case '{' . Plugin::NS_OWNCLOUD . '}remove' :
74
+                case '{'.Plugin::NS_OWNCLOUD.'}remove' :
75 75
                     $remove[] = $elem['value']['{DAV:}href'];
76 76
                     break;
77 77
 
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Xml/Invite.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -41,130 +41,130 @@
 block discarded – undo
41 41
  */
42 42
 class Invite implements XmlSerializable {
43 43
 
44
-	/**
45
-	 * The list of users a calendar has been shared to.
46
-	 *
47
-	 * @var array
48
-	 */
49
-	protected $users;
50
-
51
-	/**
52
-	 * The organizer contains information about the person who shared the
53
-	 * object.
54
-	 *
55
-	 * @var array|null
56
-	 */
57
-	protected $organizer;
58
-
59
-	/**
60
-	 * Creates the property.
61
-	 *
62
-	 * Users is an array. Each element of the array has the following
63
-	 * properties:
64
-	 *
65
-	 *   * href - Often a mailto: address
66
-	 *   * commonName - Optional, for example a first and lastname for a user.
67
-	 *   * status - One of the SharingPlugin::STATUS_* constants.
68
-	 *   * readOnly - true or false
69
-	 *   * summary - Optional, description of the share
70
-	 *
71
-	 * The organizer key is optional to specify. It's only useful when a
72
-	 * 'sharee' requests the sharing information.
73
-	 *
74
-	 * The organizer may have the following properties:
75
-	 *   * href - Often a mailto: address.
76
-	 *   * commonName - Optional human-readable name.
77
-	 *   * firstName - Optional first name.
78
-	 *   * lastName - Optional last name.
79
-	 *
80
-	 * If you wonder why these two structures are so different, I guess a
81
-	 * valid answer is that the current spec is still a draft.
82
-	 *
83
-	 * @param array $users
84
-	 */
85
-	function __construct(array $users, array $organizer = null) {
86
-
87
-		$this->users = $users;
88
-		$this->organizer = $organizer;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Returns the list of users, as it was passed to the constructor.
94
-	 *
95
-	 * @return array
96
-	 */
97
-	function getValue() {
98
-
99
-		return $this->users;
100
-
101
-	}
102
-
103
-	/**
104
-	 * The xmlSerialize metod is called during xml writing.
105
-	 *
106
-	 * Use the $writer argument to write its own xml serialization.
107
-	 *
108
-	 * An important note: do _not_ create a parent element. Any element
109
-	 * implementing XmlSerializble should only ever write what's considered
110
-	 * its 'inner xml'.
111
-	 *
112
-	 * The parent of the current element is responsible for writing a
113
-	 * containing element.
114
-	 *
115
-	 * This allows serializers to be re-used for different element names.
116
-	 *
117
-	 * If you are opening new elements, you must also close them again.
118
-	 *
119
-	 * @param Writer $writer
120
-	 * @return void
121
-	 */
122
-	function xmlSerialize(Writer $writer) {
123
-
124
-		$cs = '{' . Plugin::NS_OWNCLOUD . '}';
125
-
126
-		if (!is_null($this->organizer)) {
127
-
128
-			$writer->startElement($cs . 'organizer');
129
-			$writer->writeElement('{DAV:}href', $this->organizer['href']);
130
-
131
-			if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
132
-				$writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
133
-			}
134
-			if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
135
-				$writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
136
-			}
137
-			if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
138
-				$writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
139
-			}
140
-			$writer->endElement(); // organizer
141
-
142
-		}
143
-
144
-		foreach ($this->users as $user) {
145
-
146
-			$writer->startElement($cs . 'user');
147
-			$writer->writeElement('{DAV:}href', $user['href']);
148
-			if (isset($user['commonName']) && $user['commonName']) {
149
-				$writer->writeElement($cs . 'common-name', $user['commonName']);
150
-			}
151
-			$writer->writeElement($cs . 'invite-accepted');
152
-
153
-			$writer->startElement($cs . 'access');
154
-			if ($user['readOnly']) {
155
-				$writer->writeElement($cs . 'read');
156
-			} else {
157
-				$writer->writeElement($cs . 'read-write');
158
-			}
159
-			$writer->endElement(); // access
160
-
161
-			if (isset($user['summary']) && $user['summary']) {
162
-				$writer->writeElement($cs . 'summary', $user['summary']);
163
-			}
164
-
165
-			$writer->endElement(); //user
166
-
167
-		}
168
-
169
-	}
44
+    /**
45
+     * The list of users a calendar has been shared to.
46
+     *
47
+     * @var array
48
+     */
49
+    protected $users;
50
+
51
+    /**
52
+     * The organizer contains information about the person who shared the
53
+     * object.
54
+     *
55
+     * @var array|null
56
+     */
57
+    protected $organizer;
58
+
59
+    /**
60
+     * Creates the property.
61
+     *
62
+     * Users is an array. Each element of the array has the following
63
+     * properties:
64
+     *
65
+     *   * href - Often a mailto: address
66
+     *   * commonName - Optional, for example a first and lastname for a user.
67
+     *   * status - One of the SharingPlugin::STATUS_* constants.
68
+     *   * readOnly - true or false
69
+     *   * summary - Optional, description of the share
70
+     *
71
+     * The organizer key is optional to specify. It's only useful when a
72
+     * 'sharee' requests the sharing information.
73
+     *
74
+     * The organizer may have the following properties:
75
+     *   * href - Often a mailto: address.
76
+     *   * commonName - Optional human-readable name.
77
+     *   * firstName - Optional first name.
78
+     *   * lastName - Optional last name.
79
+     *
80
+     * If you wonder why these two structures are so different, I guess a
81
+     * valid answer is that the current spec is still a draft.
82
+     *
83
+     * @param array $users
84
+     */
85
+    function __construct(array $users, array $organizer = null) {
86
+
87
+        $this->users = $users;
88
+        $this->organizer = $organizer;
89
+
90
+    }
91
+
92
+    /**
93
+     * Returns the list of users, as it was passed to the constructor.
94
+     *
95
+     * @return array
96
+     */
97
+    function getValue() {
98
+
99
+        return $this->users;
100
+
101
+    }
102
+
103
+    /**
104
+     * The xmlSerialize metod is called during xml writing.
105
+     *
106
+     * Use the $writer argument to write its own xml serialization.
107
+     *
108
+     * An important note: do _not_ create a parent element. Any element
109
+     * implementing XmlSerializble should only ever write what's considered
110
+     * its 'inner xml'.
111
+     *
112
+     * The parent of the current element is responsible for writing a
113
+     * containing element.
114
+     *
115
+     * This allows serializers to be re-used for different element names.
116
+     *
117
+     * If you are opening new elements, you must also close them again.
118
+     *
119
+     * @param Writer $writer
120
+     * @return void
121
+     */
122
+    function xmlSerialize(Writer $writer) {
123
+
124
+        $cs = '{' . Plugin::NS_OWNCLOUD . '}';
125
+
126
+        if (!is_null($this->organizer)) {
127
+
128
+            $writer->startElement($cs . 'organizer');
129
+            $writer->writeElement('{DAV:}href', $this->organizer['href']);
130
+
131
+            if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
132
+                $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
133
+            }
134
+            if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
135
+                $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
136
+            }
137
+            if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
138
+                $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
139
+            }
140
+            $writer->endElement(); // organizer
141
+
142
+        }
143
+
144
+        foreach ($this->users as $user) {
145
+
146
+            $writer->startElement($cs . 'user');
147
+            $writer->writeElement('{DAV:}href', $user['href']);
148
+            if (isset($user['commonName']) && $user['commonName']) {
149
+                $writer->writeElement($cs . 'common-name', $user['commonName']);
150
+            }
151
+            $writer->writeElement($cs . 'invite-accepted');
152
+
153
+            $writer->startElement($cs . 'access');
154
+            if ($user['readOnly']) {
155
+                $writer->writeElement($cs . 'read');
156
+            } else {
157
+                $writer->writeElement($cs . 'read-write');
158
+            }
159
+            $writer->endElement(); // access
160
+
161
+            if (isset($user['summary']) && $user['summary']) {
162
+                $writer->writeElement($cs . 'summary', $user['summary']);
163
+            }
164
+
165
+            $writer->endElement(); //user
166
+
167
+        }
168
+
169
+    }
170 170
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -121,21 +121,21 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	function xmlSerialize(Writer $writer) {
123 123
 
124
-		$cs = '{' . Plugin::NS_OWNCLOUD . '}';
124
+		$cs = '{'.Plugin::NS_OWNCLOUD.'}';
125 125
 
126 126
 		if (!is_null($this->organizer)) {
127 127
 
128
-			$writer->startElement($cs . 'organizer');
128
+			$writer->startElement($cs.'organizer');
129 129
 			$writer->writeElement('{DAV:}href', $this->organizer['href']);
130 130
 
131 131
 			if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
132
-				$writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
132
+				$writer->writeElement($cs.'common-name', $this->organizer['commonName']);
133 133
 			}
134 134
 			if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
135
-				$writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
135
+				$writer->writeElement($cs.'first-name', $this->organizer['firstName']);
136 136
 			}
137 137
 			if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
138
-				$writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
138
+				$writer->writeElement($cs.'last-name', $this->organizer['lastName']);
139 139
 			}
140 140
 			$writer->endElement(); // organizer
141 141
 
@@ -143,23 +143,23 @@  discard block
 block discarded – undo
143 143
 
144 144
 		foreach ($this->users as $user) {
145 145
 
146
-			$writer->startElement($cs . 'user');
146
+			$writer->startElement($cs.'user');
147 147
 			$writer->writeElement('{DAV:}href', $user['href']);
148 148
 			if (isset($user['commonName']) && $user['commonName']) {
149
-				$writer->writeElement($cs . 'common-name', $user['commonName']);
149
+				$writer->writeElement($cs.'common-name', $user['commonName']);
150 150
 			}
151
-			$writer->writeElement($cs . 'invite-accepted');
151
+			$writer->writeElement($cs.'invite-accepted');
152 152
 
153
-			$writer->startElement($cs . 'access');
153
+			$writer->startElement($cs.'access');
154 154
 			if ($user['readOnly']) {
155
-				$writer->writeElement($cs . 'read');
155
+				$writer->writeElement($cs.'read');
156 156
 			} else {
157
-				$writer->writeElement($cs . 'read-write');
157
+				$writer->writeElement($cs.'read-write');
158 158
 			}
159 159
 			$writer->endElement(); // access
160 160
 
161 161
 			if (isset($user['summary']) && $user['summary']) {
162
-				$writer->writeElement($cs . 'summary', $user['summary']);
162
+				$writer->writeElement($cs.'summary', $user['summary']);
163 163
 			}
164 164
 
165 165
 			$writer->endElement(); //user
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Plugin.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	function initialize(Server $server) {
101 101
 		$this->server = $server;
102
-		$this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest';
103
-		$this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite';
102
+		$this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest';
103
+		$this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite';
104 104
 
105 105
 		$this->server->on('method:POST', [$this, 'httpPost']);
106
-		$this->server->on('propFind',    [$this, 'propFind']);
106
+		$this->server->on('propFind', [$this, 'propFind']);
107 107
 	}
108 108
 
109 109
 	/**
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
 			// Dealing with the 'share' document, which modified invitees on a
148 148
 			// calendar.
149
-			case '{' . self::NS_OWNCLOUD . '}share' :
149
+			case '{'.self::NS_OWNCLOUD.'}share' :
150 150
 
151 151
 				// We can only deal with IShareableCalendar objects
152 152
 				if (!$node instanceof IShareable) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	function propFind(PropFind $propFind, INode $node) {
190 190
 		if ($node instanceof IShareable) {
191 191
 
192
-			$propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) {
192
+			$propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) {
193 193
 				return new Invite(
194 194
 					$node->getShares()
195 195
 				);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -119,8 +119,9 @@
 block discarded – undo
119 119
 
120 120
 		// Only handling xml
121 121
 		$contentType = $request->getHeader('Content-Type');
122
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false)
123
-			return;
122
+		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
123
+					return;
124
+		}
124 125
 
125 126
 		// Making sure the node exists
126 127
 		try {
Please login to merge, or discard this patch.
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -36,167 +36,167 @@
 block discarded – undo
36 36
 
37 37
 class Plugin extends ServerPlugin {
38 38
 
39
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
40
-	const NS_NEXTCLOUD = 'http://nextcloud.com/ns';
41
-
42
-	/** @var Auth */
43
-	private $auth;
44
-
45
-	/** @var IRequest */
46
-	private $request;
47
-
48
-	/**
49
-	 * Plugin constructor.
50
-	 *
51
-	 * @param Auth $authBackEnd
52
-	 * @param IRequest $request
53
-	 */
54
-	public function __construct(Auth $authBackEnd, IRequest $request) {
55
-		$this->auth = $authBackEnd;
56
-		$this->request = $request;
57
-	}
58
-
59
-	/**
60
-	 * Reference to SabreDAV server object.
61
-	 *
62
-	 * @var \Sabre\DAV\Server
63
-	 */
64
-	protected $server;
65
-
66
-	/**
67
-	 * This method should return a list of server-features.
68
-	 *
69
-	 * This is for example 'versioning' and is added to the DAV: header
70
-	 * in an OPTIONS response.
71
-	 *
72
-	 * @return string[]
73
-	 */
74
-	function getFeatures() {
75
-		return ['oc-resource-sharing'];
76
-	}
77
-
78
-	/**
79
-	 * Returns a plugin name.
80
-	 *
81
-	 * Using this name other plugins will be able to access other plugins
82
-	 * using Sabre\DAV\Server::getPlugin
83
-	 *
84
-	 * @return string
85
-	 */
86
-	function getPluginName() {
87
-		return 'oc-resource-sharing';
88
-	}
89
-
90
-	/**
91
-	 * This initializes the plugin.
92
-	 *
93
-	 * This function is called by Sabre\DAV\Server, after
94
-	 * addPlugin is called.
95
-	 *
96
-	 * This method should set up the required event subscriptions.
97
-	 *
98
-	 * @param Server $server
99
-	 * @return void
100
-	 */
101
-	function initialize(Server $server) {
102
-		$this->server = $server;
103
-		$this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest';
104
-		$this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite';
105
-
106
-		$this->server->on('method:POST', [$this, 'httpPost']);
107
-		$this->server->on('propFind',    [$this, 'propFind']);
108
-	}
109
-
110
-	/**
111
-	 * We intercept this to handle POST requests on a dav resource.
112
-	 *
113
-	 * @param RequestInterface $request
114
-	 * @param ResponseInterface $response
115
-	 * @return null|false
116
-	 */
117
-	function httpPost(RequestInterface $request, ResponseInterface $response) {
118
-
119
-		$path = $request->getPath();
120
-
121
-		// Only handling xml
122
-		$contentType = $request->getHeader('Content-Type');
123
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false)
124
-			return;
125
-
126
-		// Making sure the node exists
127
-		try {
128
-			$node = $this->server->tree->getNodeForPath($path);
129
-		} catch (NotFound $e) {
130
-			return;
131
-		}
132
-
133
-		$requestBody = $request->getBodyAsString();
134
-
135
-		// If this request handler could not deal with this POST request, it
136
-		// will return 'null' and other plugins get a chance to handle the
137
-		// request.
138
-		//
139
-		// However, we already requested the full body. This is a problem,
140
-		// because a body can only be read once. This is why we preemptively
141
-		// re-populated the request body with the existing data.
142
-		$request->setBody($requestBody);
143
-
144
-		$message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
145
-
146
-		switch ($documentType) {
147
-
148
-			// Dealing with the 'share' document, which modified invitees on a
149
-			// calendar.
150
-			case '{' . self::NS_OWNCLOUD . '}share' :
151
-
152
-				// We can only deal with IShareableCalendar objects
153
-				if (!$node instanceof IShareable) {
154
-					return;
155
-				}
156
-
157
-				$this->server->transactionType = 'post-oc-resource-share';
158
-
159
-				// Getting ACL info
160
-				$acl = $this->server->getPlugin('acl');
161
-
162
-				// If there's no ACL support, we allow everything
163
-				if ($acl) {
164
-					/** @var \Sabre\DAVACL\Plugin $acl */
165
-					$acl->checkPrivileges($path, '{DAV:}write');
166
-				}
167
-
168
-				$node->updateShares($message->set, $message->remove);
169
-
170
-				$response->setStatus(200);
171
-				// Adding this because sending a response body may cause issues,
172
-				// and I wanted some type of indicator the response was handled.
173
-				$response->setHeader('X-Sabre-Status', 'everything-went-well');
174
-
175
-				// Breaking the event chain
176
-				return false;
177
-		}
178
-	}
179
-
180
-	/**
181
-	 * This event is triggered when properties are requested for a certain
182
-	 * node.
183
-	 *
184
-	 * This allows us to inject any properties early.
185
-	 *
186
-	 * @param PropFind $propFind
187
-	 * @param INode $node
188
-	 * @return void
189
-	 */
190
-	function propFind(PropFind $propFind, INode $node) {
191
-		if ($node instanceof IShareable) {
192
-
193
-			$propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) {
194
-				return new Invite(
195
-					$node->getShares()
196
-				);
197
-			});
198
-
199
-		}
200
-	}
39
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
40
+    const NS_NEXTCLOUD = 'http://nextcloud.com/ns';
41
+
42
+    /** @var Auth */
43
+    private $auth;
44
+
45
+    /** @var IRequest */
46
+    private $request;
47
+
48
+    /**
49
+     * Plugin constructor.
50
+     *
51
+     * @param Auth $authBackEnd
52
+     * @param IRequest $request
53
+     */
54
+    public function __construct(Auth $authBackEnd, IRequest $request) {
55
+        $this->auth = $authBackEnd;
56
+        $this->request = $request;
57
+    }
58
+
59
+    /**
60
+     * Reference to SabreDAV server object.
61
+     *
62
+     * @var \Sabre\DAV\Server
63
+     */
64
+    protected $server;
65
+
66
+    /**
67
+     * This method should return a list of server-features.
68
+     *
69
+     * This is for example 'versioning' and is added to the DAV: header
70
+     * in an OPTIONS response.
71
+     *
72
+     * @return string[]
73
+     */
74
+    function getFeatures() {
75
+        return ['oc-resource-sharing'];
76
+    }
77
+
78
+    /**
79
+     * Returns a plugin name.
80
+     *
81
+     * Using this name other plugins will be able to access other plugins
82
+     * using Sabre\DAV\Server::getPlugin
83
+     *
84
+     * @return string
85
+     */
86
+    function getPluginName() {
87
+        return 'oc-resource-sharing';
88
+    }
89
+
90
+    /**
91
+     * This initializes the plugin.
92
+     *
93
+     * This function is called by Sabre\DAV\Server, after
94
+     * addPlugin is called.
95
+     *
96
+     * This method should set up the required event subscriptions.
97
+     *
98
+     * @param Server $server
99
+     * @return void
100
+     */
101
+    function initialize(Server $server) {
102
+        $this->server = $server;
103
+        $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest';
104
+        $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite';
105
+
106
+        $this->server->on('method:POST', [$this, 'httpPost']);
107
+        $this->server->on('propFind',    [$this, 'propFind']);
108
+    }
109
+
110
+    /**
111
+     * We intercept this to handle POST requests on a dav resource.
112
+     *
113
+     * @param RequestInterface $request
114
+     * @param ResponseInterface $response
115
+     * @return null|false
116
+     */
117
+    function httpPost(RequestInterface $request, ResponseInterface $response) {
118
+
119
+        $path = $request->getPath();
120
+
121
+        // Only handling xml
122
+        $contentType = $request->getHeader('Content-Type');
123
+        if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false)
124
+            return;
125
+
126
+        // Making sure the node exists
127
+        try {
128
+            $node = $this->server->tree->getNodeForPath($path);
129
+        } catch (NotFound $e) {
130
+            return;
131
+        }
132
+
133
+        $requestBody = $request->getBodyAsString();
134
+
135
+        // If this request handler could not deal with this POST request, it
136
+        // will return 'null' and other plugins get a chance to handle the
137
+        // request.
138
+        //
139
+        // However, we already requested the full body. This is a problem,
140
+        // because a body can only be read once. This is why we preemptively
141
+        // re-populated the request body with the existing data.
142
+        $request->setBody($requestBody);
143
+
144
+        $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
145
+
146
+        switch ($documentType) {
147
+
148
+            // Dealing with the 'share' document, which modified invitees on a
149
+            // calendar.
150
+            case '{' . self::NS_OWNCLOUD . '}share' :
151
+
152
+                // We can only deal with IShareableCalendar objects
153
+                if (!$node instanceof IShareable) {
154
+                    return;
155
+                }
156
+
157
+                $this->server->transactionType = 'post-oc-resource-share';
158
+
159
+                // Getting ACL info
160
+                $acl = $this->server->getPlugin('acl');
161
+
162
+                // If there's no ACL support, we allow everything
163
+                if ($acl) {
164
+                    /** @var \Sabre\DAVACL\Plugin $acl */
165
+                    $acl->checkPrivileges($path, '{DAV:}write');
166
+                }
167
+
168
+                $node->updateShares($message->set, $message->remove);
169
+
170
+                $response->setStatus(200);
171
+                // Adding this because sending a response body may cause issues,
172
+                // and I wanted some type of indicator the response was handled.
173
+                $response->setHeader('X-Sabre-Status', 'everything-went-well');
174
+
175
+                // Breaking the event chain
176
+                return false;
177
+        }
178
+    }
179
+
180
+    /**
181
+     * This event is triggered when properties are requested for a certain
182
+     * node.
183
+     *
184
+     * This allows us to inject any properties early.
185
+     *
186
+     * @param PropFind $propFind
187
+     * @param INode $node
188
+     * @return void
189
+     */
190
+    function propFind(PropFind $propFind, INode $node) {
191
+        if ($node instanceof IShareable) {
192
+
193
+            $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) {
194
+                return new Invite(
195
+                    $node->getShares()
196
+                );
197
+            });
198
+
199
+        }
200
+    }
201 201
 
202 202
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/IShareable.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -28,48 +28,48 @@
 block discarded – undo
28 28
  */
29 29
 interface IShareable extends INode {
30 30
 
31
-	/**
32
-	 * Updates the list of shares.
33
-	 *
34
-	 * The first array is a list of people that are to be added to the
35
-	 * resource.
36
-	 *
37
-	 * Every element in the add array has the following properties:
38
-	 *   * href - A url. Usually a mailto: address
39
-	 *   * commonName - Usually a first and last name, or false
40
-	 *   * summary - A description of the share, can also be false
41
-	 *   * readOnly - A boolean value
42
-	 *
43
-	 * Every element in the remove array is just the address string.
44
-	 *
45
-	 * @param array $add
46
-	 * @param array $remove
47
-	 * @return void
48
-	 */
49
-	function updateShares(array $add, array $remove);
31
+    /**
32
+     * Updates the list of shares.
33
+     *
34
+     * The first array is a list of people that are to be added to the
35
+     * resource.
36
+     *
37
+     * Every element in the add array has the following properties:
38
+     *   * href - A url. Usually a mailto: address
39
+     *   * commonName - Usually a first and last name, or false
40
+     *   * summary - A description of the share, can also be false
41
+     *   * readOnly - A boolean value
42
+     *
43
+     * Every element in the remove array is just the address string.
44
+     *
45
+     * @param array $add
46
+     * @param array $remove
47
+     * @return void
48
+     */
49
+    function updateShares(array $add, array $remove);
50 50
 
51
-	/**
52
-	 * Returns the list of people whom this resource is shared with.
53
-	 *
54
-	 * Every element in this array should have the following properties:
55
-	 *   * href - Often a mailto: address
56
-	 *   * commonName - Optional, for example a first + last name
57
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
58
-	 *   * readOnly - boolean
59
-	 *   * summary - Optional, a description for the share
60
-	 *
61
-	 * @return array
62
-	 */
63
-	function getShares();
51
+    /**
52
+     * Returns the list of people whom this resource is shared with.
53
+     *
54
+     * Every element in this array should have the following properties:
55
+     *   * href - Often a mailto: address
56
+     *   * commonName - Optional, for example a first + last name
57
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
58
+     *   * readOnly - boolean
59
+     *   * summary - Optional, a description for the share
60
+     *
61
+     * @return array
62
+     */
63
+    function getShares();
64 64
 
65
-	/**
66
-	 * @return int
67
-	 */
68
-	public function getResourceId();
65
+    /**
66
+     * @return int
67
+     */
68
+    public function getResourceId();
69 69
 
70
-	/**
71
-	 * @return string
72
-	 */
73
-	public function getOwner();
70
+    /**
71
+     * @return string
72
+     */
73
+    public function getOwner();
74 74
 
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.