From 547a5aa6051c72e7862493adfc26326b86c92f8f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 21 Sep 2021 18:50:26 +0200 Subject: [PATCH] missing @type="NameComponent" and updated examples in docu with @type --- api/src/Contacts/JsContact.php | 22 ++++++++++++++-------- doc/REST-CalDAV-CardDAV/README.md | 31 ++++++++++++++++--------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/api/src/Contacts/JsContact.php b/api/src/Contacts/JsContact.php index fd22c506f9..da494921cd 100644 --- a/api/src/Contacts/JsContact.php +++ b/api/src/Contacts/JsContact.php @@ -96,15 +96,11 @@ class JsContact switch ($name) { case 'uid': - if (!is_string($value) || empty($value)) - { - throw new \InvalidArgumentException("Missing or invalid uid value!"); - } - $contact['uid'] = $value; + $contact['uid'] = self::parseUid($value); break; case 'name': - $contact += self::parseNameComponents($value); + $contact += self::parseNameComponents($value, $check_at_type); break; case 'fullName': @@ -981,6 +977,8 @@ class JsContact 'suffix' => 'n_suffix', ]; + const TYPE_NAME_COMPONENT = 'NameComponent'; + /** * Return name-components objects with "type" and "value" attributes * @@ -996,7 +994,11 @@ class JsContact }, self::$nameType2attribute)); return array_map(function($type, $value) { - return ['type' => $type, 'value' => $value]; + return [ + self::AT_TYPE => self::TYPE_NAME_COMPONENT, + 'type' => $type, + 'value' => $value, + ]; }, array_keys($components), array_values($components)); } @@ -1006,7 +1008,7 @@ class JsContact * @param array $components * @return array */ - protected static function parseNameComponents(array $components) + protected static function parseNameComponents(array $components, bool $check_at_type=true) { $contact = array_combine(array_values(self::$nameType2attribute), array_fill(0, count(self::$nameType2attribute), null)); @@ -1017,6 +1019,10 @@ class JsContact { throw new \InvalidArgumentException("Invalid name-component (must have type and value attributes): ".json_encode($component, self::JSON_OPTIONS_ERROR)); } + if ($check_at_type && $component[self::AT_TYPE] !== self::TYPE_NAME_COMPONENT) + { + throw new \InvalidArgumentException("Missing or invalid @type: ".json_encode($component, self::JSON_OPTIONS_ERROR)); + } $contact[self::$nameType2attribute[$component['type']]] = $component['value']; } return $contact; diff --git a/doc/REST-CalDAV-CardDAV/README.md b/doc/REST-CalDAV-CardDAV/README.md index e7447b041c..8ad841ad9c 100644 --- a/doc/REST-CalDAV-CardDAV/README.md +++ b/doc/REST-CalDAV-CardDAV/README.md @@ -62,12 +62,13 @@ curl https://example.org/egroupware/groupdav.php//addressbook/ -H "Acc "created": "2010-10-21T09:55:42Z", "updated": "2014-06-02T14:45:24Z", "name": [ - { "type": "personal", "value": "Default" }, - { "type": "surname", "value": "Tester" } + { "@type": "NameComponent", "type": "personal", "value": "Default" }, + { "@type": "NameComponent", "type": "surname", "value": "Tester" } ], "fullName": { "value": "Default Tester" }, "organizations": { "org": { + "@type": "Organization", "name": "default.org", "units": { "org_unit": "department.default.org" @@ -75,30 +76,30 @@ curl https://example.org/egroupware/groupdav.php//addressbook/ -H "Acc } }, "emails": { - "work": { "email": "test@test.com", "contexts": { "work": true }, "pref": 1 } + "work": { "@type": "EmailAddress", "email": "test@test.com", "contexts": { "work": true }, "pref": 1 } }, "phones": { - "tel_work": { "phone": "+49 123 4567890", "pref": 1, "features": { "voice": true }, "contexts": { "work": true } }, - "tel_cell": { "phone": "012 3723567", "features": { "cell": true }, "contexts": { "work": true } } + "tel_work": { "@type": "Phone", "phone": "+49 123 4567890", "pref": 1, "features": { "voice": true }, "contexts": { "work": true } }, + "tel_cell": { "@type": "Phone", "phone": "012 3723567", "features": { "cell": true }, "contexts": { "work": true } } }, "online": { - "url": { "resource": "https://www.test.com/", "type": "uri", "contexts": { "work": true } } + "url": { "@type": "Resource", "resource": "https://www.test.com/", "type": "uri", "contexts": { "work": true } } }, "notes": [ "Test test TEST\n\\server\\share\n\\\nother\nblah" ], }, "//addressbook/list-36": { - "uid": "dfa5cac5-987b-448b-85d7-6c8b529a835c", + "uid": "urn:uuid:dfa5cac5-987b-448b-85d7-6c8b529a835c", "name": "Example distribution list", "card": { - "uid": "dfa5cac5-987b-448b-85d7-6c8b529a835c", + "uid": "urn:uuid:dfa5cac5-987b-448b-85d7-6c8b529a835c", "prodId": "EGroupware Addressbook 21.1.001", "updated": "2018-04-11T14:46:43Z", "fullName": { "value": "Example distribution list" } }, "members": { - "urn:uuid:5638-8623c4830472a8ede9f9f8b30d435ea4": true + "5638-8623c4830472a8ede9f9f8b30d435ea4": true } } } @@ -193,8 +194,8 @@ curl 'https://example.org/egroupware/groupdav.php/addressbook/?sync-token=https: "created": "2010-10-21T09:55:42Z", "updated": "2014-06-02T14:45:24Z", "name": [ - { "type": "personal", "value": "Default" }, - { "type": "surname", "value": "Tester" } + { "@type": "NameComponent", "type": "personal", "value": "Default" }, + { "@type": "NameComponent", "type": "surname", "value": "Tester" } ], "fullName": "Default Tester", .... @@ -217,8 +218,8 @@ curl 'https://example.org/egroupware/groupdav.php/addressbook/5593' -H "Accept: "created": "2010-10-21T09:55:42Z", "updated": "2014-06-02T14:45:24Z", "name": [ - { "type": "personal", "value": "Default" }, - { "type": "surname", "value": "Tester" } + { "@type": "NameComponent", "type": "personal", "value": "Default" }, + { "@type": "NameComponent", "type": "surname", "value": "Tester" } ], "fullName": "Default Tester", .... @@ -239,8 +240,8 @@ cat </addr "created": "2010-10-21T09:55:42Z", "updated": "2014-06-02T14:45:24Z", "name": [ - { "type": "personal", "value": "Default" }, - { "type": "surname", "value": "Tester" } + { "type": "@type": "NameComponent", "personal", "value": "Default" }, + { "type": "@type": "NameComponent", "surname", "value": "Tester" } ], "fullName": { "value": "Default Tester" }, ....