Skip to content

Commit

Permalink
Merge pull request #627 from onny/member
Browse files Browse the repository at this point in the history
attendeeProperty: Add member function
  • Loading branch information
st3iny authored Nov 1, 2023
2 parents 92f6635 + eb9c15b commit 2074db6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/properties/attendeeProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -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?
*
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/properties/attendeeProperty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -265,6 +266,36 @@ it('AttendeeProperty should provide easy getter/setter for email', () => {
expect(property.email).toEqual('mailto:[email protected]')
})

it('AttendeeProperty should provide easy getter/setter for member', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;MEMBER="mailto:[email protected]","mailto:[email protected]";CN=janedoe:mailto:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)

expect(property.member).toEqual(['mailto:[email protected]', 'mailto:[email protected]'])

property.member = ['[email protected]']
expect(property.member).toEqual(['mailto:[email protected]'])

property.lock()
expect(property.isLocked()).toEqual(true)

expect(() => {
property.member = ['mailto:[email protected]']
}).toThrow(ModificationNotAllowedError)
expect(property.member).toEqual(['mailto:[email protected]'])

property.unlock()

property.member = ['[email protected]', 'mailto:[email protected]']
expect(property.member).toEqual(['mailto:[email protected]', 'mailto:[email protected]'])
})

it('AttendeeProperty should handle missing member gracefully', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:[email protected]')
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:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)
Expand Down

0 comments on commit 2074db6

Please sign in to comment.