Skip to content

Commit

Permalink
Merge pull request #38 from nextcloud/bugfix/noid/fix_addressbook_cal…
Browse files Browse the repository at this point in the history
…endar_queries

fix sending calendar-queries, ...
  • Loading branch information
georgehrke authored Nov 4, 2018
2 parents ff47e20 + 0da6755 commit 707e62b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist/dist.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist.js.map

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/models/addressBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export class AddressBook extends davCollectionShareable(DavCollection) {
* @param {Object[]} filter
* @param {Object[]} prop
* @param {Number} limit
* @param {String} test Either anyof or allof
* @returns {Promise<VCard[]>}
*/
async addressbookQuery(filter, prop = null, limit = null) {
async addressbookQuery(filter, prop = null, limit = null, test = 'anyof') {
debug('sending an addressbook-query request');

const [skeleton] = XMLUtility.getRootSkeleton(
Expand All @@ -149,7 +150,13 @@ export class AddressBook extends davCollectionShareable(DavCollection) {
// According to the spec, every address-book query needs a filter,
// but Nextcloud just returns all elements without a filter.
if (filter) {
skeleton.children.push(...filter);
skeleton.children.push({
name: [NS.IETF_CARDDAV, 'filter'],
attributes: [
['test', test]
],
children: filter
});
}

if (limit) {
Expand Down
5 changes: 4 additions & 1 deletion src/models/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export class Calendar extends davCollectionPublishable(davCollectionShareable(Da
// According to the spec, every calendar-query needs a filter,
// but Nextcloud just returns all elements without a filter.
if (filter) {
skeleton.children.push(...filter);
skeleton.children.push({
name: [NS.IETF_CALDAV, 'filter'],
children: filter
});
}

if (timezone) {
Expand Down
40 changes: 17 additions & 23 deletions test/unit/models/addressBookTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,30 @@ describe('Address book model', () => {
// https://tools.ietf.org/html/rfc6352#section-8.6.4
const addressbook = new AddressBook(parent, request, url, props);
return addressbook.addressbookQuery([{
name: [NS.IETF_CARDDAV, 'filter'],
name: [NS.IETF_CARDDAV, 'prop-filter'],
attributes: [
['test', 'anyof']
['name', 'FN']
],
children: [{
name: [NS.IETF_CARDDAV, 'prop-filter'],
name: [NS.IETF_CARDDAV, 'text-match'],
attributes: [
['name', 'FN']
['collation', 'i;unicode-casemap'],
['match-type', 'contains'],
],
children: [{
name: [NS.IETF_CARDDAV, 'text-match'],
attributes: [
['collation', 'i;unicode-casemap'],
['match-type', 'contains'],
],
value: 'daboo'
}]
}, {
name: [NS.IETF_CARDDAV, 'prop-filter'],
value: 'daboo'
}]
}, {
name: [NS.IETF_CARDDAV, 'prop-filter'],
attributes: [
['name', 'EMAIL']
],
children: [{
name: [NS.IETF_CARDDAV, 'text-match'],
attributes: [
['name', 'EMAIL']
['collation', 'i;unicode-casemap'],
['match-type', 'contains'],
],
children: [{
name: [NS.IETF_CARDDAV, 'text-match'],
attributes: [
['collation', 'i;unicode-casemap'],
['match-type', 'contains'],
],
value: 'daboo'
}]
value: 'daboo'
}]
}]).then((res) => {
expect(res.length).toEqual(1);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/models/calendarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ END:VCALENDAR

expect(request.report).toHaveBeenCalledTimes(1);
expect(request.report).toHaveBeenCalledWith('/foo/bar/folder/', { Depth: '1' },
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"/></x0:comp-filter></x0:calendar-query>');
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:filter><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"/></x0:comp-filter></x0:filter></x0:calendar-query>');
}).catch(() => {
fail('Calendar findByType was not supposed to fail');
});
Expand Down Expand Up @@ -234,7 +234,7 @@ END:VCALENDAR

expect(request.report).toHaveBeenCalledTimes(1);
expect(request.report).toHaveBeenCalledWith('/foo/bar/folder/', { Depth: '1' },
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"><x0:time-range start="20181001T000000Z" end="20181031T000000Z"/></x0:comp-filter></x0:comp-filter></x0:calendar-query>');
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:filter><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"><x0:time-range start="20181001T000000Z" end="20181031T000000Z"/></x0:comp-filter></x0:comp-filter></x0:filter></x0:calendar-query>');
}).catch((e) => {
console.log(e);
fail('Calendar findByTypeInTimeRange was not supposed to fail');
Expand Down Expand Up @@ -349,7 +349,7 @@ END:VCALENDAR

expect(request.report).toHaveBeenCalledTimes(1);
expect(request.report).toHaveBeenCalledWith('/foo/bar/folder/', { Depth: '1' },
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"><x0:prop-filter name="ATTENDEE"><x0:text-match collation="i;ascii-casemap">mailto:[email protected]</x0:text-match><x0:param-filter name="PARTSTAT"><x0:text-match collation="i;ascii-casemap">NEEDS-ACTION</x0:text-match></x0:param-filter></x0:prop-filter></x0:comp-filter></x0:comp-filter></x0:calendar-query>');
'<x0:calendar-query xmlns:x0="urn:ietf:params:xml:ns:caldav"><x1:prop xmlns:x1="DAV:"><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x1:displayname/><x1:owner/><x1:resourcetype/><x1:sync-token/><x1:current-user-privilege-set/><x1:getcontenttype/><x1:getetag/><x1:resourcetype/><x0:calendar-data/></x1:prop><x0:filter><x0:comp-filter name="VCALENDAR"><x0:comp-filter name="VEVENT"><x0:prop-filter name="ATTENDEE"><x0:text-match collation="i;ascii-casemap">mailto:[email protected]</x0:text-match><x0:param-filter name="PARTSTAT"><x0:text-match collation="i;ascii-casemap">NEEDS-ACTION</x0:text-match></x0:param-filter></x0:prop-filter></x0:comp-filter></x0:comp-filter></x0:filter></x0:calendar-query>');
}).catch(() => {
fail('Calendar calendarQuery was not supposed to fail');
});
Expand Down

0 comments on commit 707e62b

Please sign in to comment.