From a5796c8b41548482c7152e7ee6604d55cdf559ad Mon Sep 17 00:00:00 2001 From: ralf Date: Wed, 15 May 2024 19:52:37 +0200 Subject: [PATCH] add missing @type: Card(Group) in Addressbook REST API --- api/src/Contacts/JsContact.php | 14 ++++++++++---- doc/REST-CalDAV-CardDAV/Addressbook.md | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/src/Contacts/JsContact.php b/api/src/Contacts/JsContact.php index 530271a68f..f29a52073b 100644 --- a/api/src/Contacts/JsContact.php +++ b/api/src/Contacts/JsContact.php @@ -16,8 +16,8 @@ use EGroupware\Api; /** * Rendering contacts as JSON using new JsContact format * - * @link https://datatracker.ietf.org/doc/html/draft-ietf-jmap-jscontact-07 (newer, here implemented format) - * @link https://datatracker.ietf.org/doc/html/rfc7095 jCard (older vCard compatible contact data as JSON, NOT implemented here!) + * @link https://datatracker.ietf.org/doc/html/rfc9553 rfc9553: JSContact: A JSON Representation of Contact Data + * @link https://datatracker.ietf.org/doc/html/rfc9555 rfc9555: JSContact: Converting from and to vCard */ class JsContact extends Api\CalDAV\JsBase { @@ -27,11 +27,13 @@ class JsContact extends Api\CalDAV\JsBase const MIME_TYPE_JSCARD = "application/jscontact+json;type=card"; const MIME_TYPE_JSCARDGROUP = "application/jscontact+json;type=cardgroup"; + const TYPE_CARD = 'Card'; + /** * Get jsCard for given contact * * @param int|array $contact - * @param bool|"pretty" $encode=true true: JSON encode, "pretty": JSON encode with pretty-print, false: return raw data eg. from listing + * @param bool|"pretty" $encode true: JSON encode, "pretty": JSON encode with pretty-print, false: return raw data eg. from listing * @return string|array * @throws Api\Exception\NotFound */ @@ -42,6 +44,7 @@ class JsContact extends Api\CalDAV\JsBase throw new Api\Exception\NotFound(); } $data = array_filter([ + self::AT_TYPE => self::TYPE_CARD, 'uid' => self::uid($contact['uid']), 'prodId' => 'EGroupware Addressbook '.$GLOBALS['egw_info']['apps']['api']['version'], 'created' => self::UTCDateTime($contact['created']), @@ -1067,11 +1070,13 @@ class JsContact extends Api\CalDAV\JsBase return $value; } + const TYPE_CARDGROUP = 'CardGroup'; + /** * Get jsCardGroup for given group * * @param int|array $group - * @param bool|"pretty" $encode=true true: JSON, "pretty": JSON pretty-print, false: array + * @param bool|"pretty" $encode true: JSON, "pretty": JSON pretty-print, false: array * @return array|string * @throws Api\Exception\NotFound */ @@ -1082,6 +1087,7 @@ class JsContact extends Api\CalDAV\JsBase throw new Api\Exception\NotFound(); } $data = array_filter([ + self::AT_TYPE => self::TYPE_CARDGROUP, 'uid' => self::uid($group['list_uid']), 'name' => $group['list_name'], 'card' => self::getJsCard([ diff --git a/doc/REST-CalDAV-CardDAV/Addressbook.md b/doc/REST-CalDAV-CardDAV/Addressbook.md index f2062eec96..2602149a4b 100644 --- a/doc/REST-CalDAV-CardDAV/Addressbook.md +++ b/doc/REST-CalDAV-CardDAV/Addressbook.md @@ -22,6 +22,7 @@ curl https://example.org/egroupware/groupdav.php//addressbook/ -H "Acc { "responses": { "//addressbook/1833": { + "@type": "Card", "uid": "5638-8623c4830472a8ede9f9f8b30d435ea4", "prodId": "EGroupware Addressbook 21.1.001", "created": "2010-10-21T09:55:42Z", @@ -55,6 +56,7 @@ curl https://example.org/egroupware/groupdav.php//addressbook/ -H "Acc ], }, "//addressbook/list-36": { + "@type": "CardGroup", "uid": "urn:uuid:dfa5cac5-987b-448b-85d7-6c8b529a835c", "name": "Example distribution list", "card": { @@ -160,6 +162,7 @@ curl 'https://example.org/egroupware/groupdav.php/addressbook/?sync-token=https: "responses": { "/addressbook/5597": null, "/addressbook/5593": { + "@type": "Card", "uid": "5638-8623c4830472a8ede9f9f8b30d435ea4", "prodId": "EGroupware Addressbook 21.1.001", "created": "2010-10-21T09:55:42Z", @@ -184,6 +187,7 @@ curl 'https://example.org/egroupware/groupdav.php/addressbook/?sync-token=https: ``` curl 'https://example.org/egroupware/groupdav.php/addressbook/6502' -H "Accept: application/pretty+json" --user { + "@type": "Card", "uid": "addressbook-6502-8623c4830472a8ede9f9f8b30d435ea4", "prodId": "EGroupware Addressbook 21.1.003", "created": "2022-12-14T13:35:02Z", @@ -506,5 +510,5 @@ HTTP/1.1 204 No content * [Vendor-specific Property Extensions and Values](https://datatracker.ietf.org/doc/html/draft-ietf-jmap-jscontact-07#section-1.3) use `:` like in JsCalendar * top-level objects need a `@type` attribute with one of the following values: -`NameComponent`, `Organization`, `Title`, `Phone`, `Resource`, `File`, `ContactLanguage`, +`Card`, `CardGroup`, `NameComponent`, `Organization`, `Title`, `Phone`, `Resource`, `File`, `ContactLanguage`, `Address`, `StreetComponent`, `Anniversary`, `PersonalInformation` \ No newline at end of file