Skip to content

Commit eed9a0c

Browse files
Merge pull request #2431 from nextcloud/fix/nextcloud/webdav-namespaces
2 parents 03418cb + 63330c5 commit eed9a0c

File tree

5 files changed

+106
-15
lines changed

5 files changed

+106
-15
lines changed

packages/nextcloud/lib/src/api/webdav/models/webdav.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class WebDavOcChecksums with _$WebDavOcChecksumsXmlSerializableMixin {
248248

249249
factory WebDavOcChecksums.fromXmlElement(XmlElement element) => _$WebDavOcChecksumsFromXmlElement(element);
250250

251-
@annotation.XmlElement(name: 'checksum', namespace: namespaceNextcloud)
251+
@annotation.XmlElement(name: 'checksum', namespace: namespaceOwncloud)
252252
final List<String>? checksums;
253253
}
254254

@@ -262,7 +262,7 @@ class WebDavOcShareTypes with _$WebDavOcShareTypesXmlSerializableMixin {
262262

263263
factory WebDavOcShareTypes.fromXmlElement(XmlElement element) => _$WebDavOcShareTypesFromXmlElement(element);
264264

265-
@annotation.XmlElement(name: 'share-type', namespace: namespaceNextcloud)
265+
@annotation.XmlElement(name: 'share-type', namespace: namespaceOwncloud)
266266
final List<int>? shareTypes;
267267
}
268268

@@ -276,6 +276,6 @@ class WebDavOcTags with _$WebDavOcTagsXmlSerializableMixin {
276276

277277
factory WebDavOcTags.fromXmlElement(XmlElement element) => _$WebDavOcTagsFromXmlElement(element);
278278

279-
@annotation.XmlElement(name: 'tag', namespace: namespaceNextcloud)
279+
@annotation.XmlElement(name: 'tag', namespace: namespaceOwncloud)
280280
final List<String>? tags;
281281
}

packages/nextcloud/lib/src/api/webdav/models/webdav.g.dart

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

packages/nextcloud/test/api/webdav/webdav_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'dart:math';
33
import 'dart:typed_data';
44

55
import 'package:mocktail/mocktail.dart';
6+
import 'package:nextcloud/core.dart' as core;
7+
import 'package:nextcloud/files_sharing.dart' as files_sharing;
68
import 'package:nextcloud/nextcloud.dart';
79
import 'package:nextcloud/src/utils/date_time.dart';
810
import 'package:nextcloud/webdav.dart';
@@ -281,6 +283,35 @@ void main() {
281283
expect(response.props.ocSize, data.lengthInBytes);
282284
});
283285

286+
test('Create share', () async {
287+
final file = File('test/files/test.png');
288+
await tester.client.webdav.putFile(file, file.statSync(), PathUri.parse('test/share.png'));
289+
290+
await tester.client.filesSharing.shareapi.createShare(
291+
$body: files_sharing.ShareapiCreateShareRequestApplicationJson(
292+
(b) => b
293+
..path = '/test/share.png'
294+
..shareType = core.ShareType.user.index
295+
..shareWith = 'user2',
296+
),
297+
);
298+
299+
final response = await tester.client.webdav.propfind(
300+
PathUri.parse('test/share.png'),
301+
prop: const WebDavPropWithoutValues.fromBools(
302+
ncShareAttributes: true,
303+
ncSharees: true,
304+
ocShareTypes: true,
305+
),
306+
);
307+
final props = response.responses.single.propstats.first.prop;
308+
expect(json.decode(props.ncShareAttributes!), <String>[]);
309+
expect(props.ncSharees!.sharees!.single.id, 'user2');
310+
expect(props.ncSharees!.sharees!.single.displayName, 'User Two');
311+
expect(props.ncSharees!.sharees!.single.type, core.ShareType.user.index);
312+
expect(props.ocShareTypes!.shareTypes!.single, core.ShareType.user.index);
313+
});
314+
284315
test('Filter files', () async {
285316
final response = await tester.client.webdav.put(utf8.encode('test'), PathUri.parse('test/filter.txt'));
286317
final id = response.headers['oc-fileid'];
@@ -396,6 +427,30 @@ void main() {
396427
expect(props.ocFavorite, false);
397428
});
398429

430+
test('Set and get tags', () async {
431+
await tester.client.webdav.put(
432+
utf8.encode('test'),
433+
PathUri.parse('test/tags.txt'),
434+
);
435+
436+
final updated = await tester.client.webdav.proppatch(
437+
PathUri.parse('test/tags.txt'),
438+
set: const WebDavProp(
439+
ocTags: WebDavOcTags(tags: ['example']),
440+
),
441+
);
442+
expect(updated, isTrue);
443+
444+
final response = await tester.client.webdav.propfind(
445+
PathUri.parse('test/tags.txt'),
446+
prop: const WebDavPropWithoutValues.fromBools(
447+
ocTags: true,
448+
),
449+
);
450+
final props = response.responses.single.propstats.first.prop;
451+
expect(props.ocTags!.tags!.single, 'example');
452+
});
453+
399454
test('Upload and download file', () async {
400455
final destinationDir = Directory.systemTemp.createTempSync();
401456
final destination = File('${destinationDir.path}/test.png');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PUT http://localhost/remote\.php/webdav/test/share\.png
2+
authorization: Bearer mock
3+
content-length: 8650
4+
content-type: application/xml
5+
ocs-apirequest: true
6+
requesttoken: token
7+
.+
8+
POST http://localhost/ocs/v2\.php/apps/files_sharing/api/v1/shares
9+
accept: application/json
10+
authorization: Bearer mock
11+
content-type: application/json; charset=utf-8
12+
ocs-apirequest: true
13+
\{"shareType":0,"publicUpload":"false","password":"","expireDate":"","note":"","label":"","path":"/test/share\.png","shareWith":"user2"\}
14+
PROPFIND http://localhost/remote\.php/webdav/test/share\.png
15+
authorization: Bearer mock
16+
content-type: application/xml
17+
ocs-apirequest: true
18+
requesttoken: token
19+
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud\.org/ns" xmlns:nc="http://nextcloud\.org/ns" xmlns:ocs="http://open-collaboration-services\.org/ns" xmlns:ocm="http://open-cloud-mesh\.org/ns"><d:prop><nc:share-attributes/><nc:sharees/><oc:share-types/></d:prop></d:propfind>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PUT http://localhost/remote\.php/webdav/test/tags\.txt
2+
authorization: Bearer mock
3+
content-length: 4
4+
content-type: application/xml
5+
ocs-apirequest: true
6+
requesttoken: token
7+
test
8+
PROPPATCH http://localhost/remote\.php/webdav/test/tags\.txt
9+
authorization: Bearer mock
10+
content-type: application/xml
11+
ocs-apirequest: true
12+
requesttoken: token
13+
<d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud\.org/ns" xmlns:nc="http://nextcloud\.org/ns" xmlns:ocs="http://open-collaboration-services\.org/ns" xmlns:ocm="http://open-cloud-mesh\.org/ns"><d:set><d:prop><oc:tags><oc:tag>example</oc:tag></oc:tags></d:prop></d:set></d:propertyupdate>
14+
PROPFIND http://localhost/remote\.php/webdav/test/tags\.txt
15+
authorization: Bearer mock
16+
content-type: application/xml
17+
ocs-apirequest: true
18+
requesttoken: token
19+
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud\.org/ns" xmlns:nc="http://nextcloud\.org/ns" xmlns:ocs="http://open-collaboration-services\.org/ns" xmlns:ocm="http://open-cloud-mesh\.org/ns"><d:prop><oc:tags/></d:prop></d:propfind>

0 commit comments

Comments
 (0)