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..04eaece1 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,32 @@ 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":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() +}) + +it('AttendeeProperty should handle missing member gracefully', () => { + const property = new AttendeeProperty('ATTENDEE') + + 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)