From eb9c15bee5e22d6adf2b4c80ca78c784e33c9ef8 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Thu, 17 Aug 2023 12:31:46 +0200 Subject: [PATCH] feat(attendee): expose member parameter Idea and original code by Jonas Heinrich (@onny). Signed-off-by: Richard Steinmetz --- src/properties/attendeeProperty.js | 20 ++++++++++++ .../unit/properties/attendeeProperty.test.js | 31 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/properties/attendeeProperty.js b/src/properties/attendeeProperty.js index ff94bd22..db6b1bcb 100644 --- a/src/properties/attendeeProperty.js +++ b/src/properties/attendeeProperty.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2019 Georg Ehrke * * @author Georg Ehrke + * @author Richard Steinmetz * * @license AGPL-3.0-or-later * @@ -207,6 +208,25 @@ export default class AttendeeProperty extends Property { this.value = startStringWith(email, 'mailto:') } + /** + * Gets the email addresses of groups the attendee is a part of + * + * @return {string[]|null} The email addresses of the groups + */ + get member() { + return this.getParameter('MEMBER')?.value ?? null + } + + /** + * Sets the email addresses of groups the attendee is a part of + * + * @param {string[]} members The email addresses of the groups + */ + set member(members) { + members = members.map(member => startStringWith(member, 'mailto:')) + this.updateParameterIfExist('MEMBER', members) + } + /** * Is this attendee the organizer? * diff --git a/tests/unit/properties/attendeeProperty.test.js b/tests/unit/properties/attendeeProperty.test.js index bdd57bf0..53f56873 100644 --- a/tests/unit/properties/attendeeProperty.test.js +++ b/tests/unit/properties/attendeeProperty.test.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2019 Georg Ehrke * * @author Georg Ehrke + * @author Richard Steinmetz * * @license AGPL-3.0-or-later * @@ -265,6 +266,36 @@ it('AttendeeProperty should provide easy getter/setter for email', () => { expect(property.email).toEqual('mailto:bar@example.com') }) +it('AttendeeProperty should provide easy getter/setter for member', () => { + const icalValue = ICAL.Property.fromString('ATTENDEE;MEMBER="mailto:projectA@example.com","mailto:projectB@example.com";CN=janedoe:mailto:janedoe@example.com') + const property = AttendeeProperty.fromICALJs(icalValue) + + expect(property.member).toEqual(['mailto:projectA@example.com', 'mailto:projectB@example.com']) + + property.member = ['foo@bar.com'] + expect(property.member).toEqual(['mailto:foo@bar.com']) + + property.lock() + expect(property.isLocked()).toEqual(true) + + expect(() => { + property.member = ['mailto:projc@example.com'] + }).toThrow(ModificationNotAllowedError) + expect(property.member).toEqual(['mailto:foo@bar.com']) + + property.unlock() + + property.member = ['bar@example.com', 'mailto:foo@example.com'] + expect(property.member).toEqual(['mailto:bar@example.com', 'mailto:foo@example.com']) +}) + +it('AttendeeProperty should handle missing member gracefully', () => { + const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:mrbig@example.com') + const property = AttendeeProperty.fromICALJs(icalValue) + + expect(property.member).toEqual(null) +}) + it('AttendeeProperty should provide easy getter/setter for commonName', () => { const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:mrbig@example.com') const property = AttendeeProperty.fromICALJs(icalValue)