Skip to content

Commit a091373

Browse files
authored
Merge pull request #44202 from nextcloud/fix/migrate-webdav-check-to-setupcheck
2 parents c16d42f + 5ee8913 commit a091373

File tree

9 files changed

+101
-75
lines changed

9 files changed

+101
-75
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php',
335335
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
336336
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
337+
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => $baseDir . '/../lib/SetupChecks/WebdavEndpoint.php',
337338
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
338339
'OCA\\DAV\\SystemTag\\SystemTagList' => $baseDir . '/../lib/SystemTag/SystemTagList.php',
339340
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => $baseDir . '/../lib/SystemTag/SystemTagMappingNode.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class ComposerStaticInitDAV
349349
'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php',
350350
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
351351
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
352+
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => __DIR__ . '/..' . '/../lib/SetupChecks/WebdavEndpoint.php',
352353
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
353354
'OCA\\DAV\\SystemTag\\SystemTagList' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagList.php',
354355
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagMappingNode.php',

apps/dav/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
use OCA\DAV\Search\EventsSearchProvider;
8989
use OCA\DAV\Search\TasksSearchProvider;
9090
use OCA\DAV\SetupChecks\NeedsSystemAddressBookSync;
91+
use OCA\DAV\SetupChecks\WebdavEndpoint;
9192
use OCA\DAV\UserMigration\CalendarMigrator;
9293
use OCA\DAV\UserMigration\ContactsMigrator;
9394
use OCP\Accounts\UserUpdatedEvent;
@@ -211,6 +212,7 @@ public function register(IRegistrationContext $context): void {
211212
$context->registerUserMigrator(ContactsMigrator::class);
212213

213214
$context->registerSetupCheck(NeedsSystemAddressBookSync::class);
215+
$context->registerSetupCheck(WebdavEndpoint::class);
214216
}
215217

216218
public function boot(IBootContext $context): void {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2024 Côme Chilliet <[email protected]>
7+
*
8+
* @author Côme Chilliet <[email protected]>
9+
* @author Ferdinand Thiessen <[email protected]>
10+
*
11+
* @license AGPL-3.0-or-later
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Affero General Public License as
15+
* published by the Free Software Foundation, either version 3 of the
16+
* License, or (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*
26+
*/
27+
28+
namespace OCA\DAV\SetupChecks;
29+
30+
use OCA\Settings\SetupChecks\CheckServerResponseTrait;
31+
use OCP\Http\Client\IClientService;
32+
use OCP\IConfig;
33+
use OCP\IL10N;
34+
use OCP\IURLGenerator;
35+
use OCP\SetupCheck\ISetupCheck;
36+
use OCP\SetupCheck\SetupResult;
37+
use Psr\Log\LoggerInterface;
38+
39+
class WebdavEndpoint implements ISetupCheck {
40+
41+
use CheckServerResponseTrait;
42+
43+
public function __construct(
44+
protected IL10N $l10n,
45+
protected IConfig $config,
46+
protected IURLGenerator $urlGenerator,
47+
protected IClientService $clientService,
48+
protected LoggerInterface $logger,
49+
) {
50+
}
51+
52+
public function getCategory(): string {
53+
return 'network';
54+
}
55+
56+
public function getName(): string {
57+
return $this->l10n->t('WebDAV endpoint');
58+
}
59+
60+
public function run(): SetupResult {
61+
$urls = [
62+
['propfind', '/remote.php/webdav', [207, 401]],
63+
];
64+
65+
foreach ($urls as [$verb,$url,$validStatuses]) {
66+
$works = null;
67+
foreach ($this->runRequest($verb, $url, ['httpErrors' => false]) as $response) {
68+
// Check that the response status matches
69+
$works = in_array($response->getStatusCode(), $validStatuses);
70+
// Skip the other requests if one works
71+
if ($works === true) {
72+
break;
73+
}
74+
}
75+
// If 'works' is null then we could not connect to the server
76+
if ($works === null) {
77+
return SetupResult::info(
78+
$this->l10n->t('Could not check that your web server is properly set up to allow file synchronization over WebDAV. Please check manually.') . "\n" . $this->serverConfigHelp(),
79+
$this->urlGenerator->linkToDocs('admin-setup-well-known-URL'),
80+
);
81+
}
82+
// Otherwise if we fail we can abort here
83+
if ($works === false) {
84+
return SetupResult::error(
85+
$this->l10n->t('Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.') . "\n" . $this->serverConfigHelp(),
86+
);
87+
}
88+
}
89+
return SetupResult::success(
90+
$this->l10n->t('Your web server is properly set up to allow file synchronization over WebDAV.')
91+
);
92+
}
93+
}

apps/settings/src/admin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ window.addEventListener('DOMContentLoaded', () => {
101101
const setupChecks = () => {
102102
// run setup checks then gather error messages
103103
$.when(
104-
OC.SetupChecks.checkWebDAV(),
105104
OC.SetupChecks.checkSetup(),
106-
).then((check1, check2) => {
107-
const messages = [].concat(check1, check2)
105+
).then((messages) => {
108106
const $el = $('#postsetupchecks')
109107
$('#security-warning-state-loading').addClass('hidden')
110108

core/js/setupchecks.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,6 @@
1515
MESSAGE_TYPE_INFO:0,
1616
MESSAGE_TYPE_WARNING:1,
1717
MESSAGE_TYPE_ERROR:2,
18-
/**
19-
* Check whether the WebDAV connection works.
20-
*
21-
* @return $.Deferred object resolved with an array of error messages
22-
*/
23-
checkWebDAV: function() {
24-
var deferred = $.Deferred();
25-
var afterCall = function(xhr) {
26-
var messages = [];
27-
if (xhr.status !== 207 && xhr.status !== 401) {
28-
messages.push({
29-
msg: t('core', 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.'),
30-
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
31-
});
32-
}
33-
deferred.resolve(messages);
34-
};
35-
36-
$.ajax({
37-
type: 'PROPFIND',
38-
url: OC.linkToRemoteBase('webdav'),
39-
data: '<?xml version="1.0"?>' +
40-
'<d:propfind xmlns:d="DAV:">' +
41-
'<d:prop><d:resourcetype/></d:prop>' +
42-
'</d:propfind>',
43-
contentType: 'application/xml; charset=utf-8',
44-
complete: afterCall,
45-
allowAuthErrors: true
46-
});
47-
return deferred.promise();
48-
},
4918

5019
/**
5120
* Runs setup checks on the server side

core/js/tests/specs/setupchecksSpec.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,6 @@ describe('OC.SetupChecks tests', function() {
2222
protocolStub.restore();
2323
});
2424

25-
describe('checkWebDAV', function() {
26-
it('should fail with another response status code than 201 or 207', function(done) {
27-
var async = OC.SetupChecks.checkWebDAV();
28-
29-
suite.server.requests[0].respond(200);
30-
31-
async.done(function( data, s, x ){
32-
expect(data).toEqual([{
33-
msg: 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.',
34-
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
35-
}]);
36-
done();
37-
});
38-
});
39-
40-
it('should return no error with a response status code of 207', function(done) {
41-
var async = OC.SetupChecks.checkWebDAV();
42-
43-
suite.server.requests[0].respond(207);
44-
45-
async.done(function( data, s, x ){
46-
expect(data).toEqual([]);
47-
done();
48-
});
49-
});
50-
51-
it('should return no error with a response status code of 401', function(done) {
52-
var async = OC.SetupChecks.checkWebDAV();
53-
54-
suite.server.requests[0].respond(401);
55-
56-
async.done(function( data, s, x ){
57-
expect(data).toEqual([]);
58-
done();
59-
});
60-
});
61-
});
62-
6325
describe('checkSetup', function() {
6426
it('should return an error if server has no internet connection', function(done) {
6527
var async = OC.SetupChecks.checkSetup();

dist/settings-legacy-admin.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)