Skip to content

Commit

Permalink
feat(calendar): optionally remove attendees that can't be invited
Browse files Browse the repository at this point in the history
If some attendees have prevented others to invite them, offer the
organizer to remove them when saving the invitation.
  • Loading branch information
cgx committed Apr 15, 2022
1 parent 59eda2f commit 4e5c865
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
15 changes: 12 additions & 3 deletions SoObjects/Appointments/SOGoAppointmentObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ - (NSException *) _handleAttendeesAvailability: (NSArray *) theAttendees
iCalPerson *currentAttendee;
SOGoUser *user;
SOGoUserSettings *us;
NSMutableArray *unavailableAttendees;
NSMutableArray *unavailableAttendees, *unavailableEmails;
NSEnumerator *enumerator;
NSString *currentUID, *ownerUID;
NSMutableString *reason;
NSDictionary *values;
NSDictionary *values, *info;
NSMutableDictionary *value, *moduleSettings;
id whiteList;

Expand All @@ -545,6 +545,7 @@ - (NSException *) _handleAttendeesAvailability: (NSArray *) theAttendees

// Build list of the attendees uids
unavailableAttendees = [[NSMutableArray alloc] init];
unavailableEmails = [NSMutableArray array];
enumerator = [theAttendees objectEnumerator];
ownerUID = [[[self context] activeUser] login];

Expand Down Expand Up @@ -573,6 +574,7 @@ - (NSException *) _handleAttendeesAvailability: (NSArray *) theAttendees
{
values = [NSDictionary dictionaryWithObject:[user cn] forKey:@"Cn"];
[unavailableAttendees addObject:values];
[unavailableEmails addObject: [currentAttendee rfc822Email]];
}
}
}
Expand All @@ -592,7 +594,14 @@ - (NSException *) _handleAttendeesAvailability: (NSArray *) theAttendees
if (i < count-2)
[reason appendString:@", "];
}


if (count < [theAttendees count])
{
info = [NSDictionary dictionaryWithObjectsAndKeys:
reason, @"reject",
unavailableEmails, @"unavailableAttendees", nil];
reason = [NSMutableString stringWithString: [info jsonRepresentation]];
}
[unavailableAttendees release];

return [self exceptionWithHTTPStatus:409 reason: reason];
Expand Down
2 changes: 2 additions & 0 deletions UI/Scheduler/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ validate_untilbeforeend = "The recurrence must end after the first occurrence
"and" = "and";
"A time conflict exists with one or more attendees.\nWould you like to keep the current settings anyway?"
= "A time conflict exists with one or more attendees.\nWould you like to keep the current settings anyway?";
"Would you like to remove them and send the invitation to the remaining attendees?"
= "Would you like to remove them and send the invitation to the remaining attendees?";

/* events list */
"Due" = "Due";
Expand Down
26 changes: 26 additions & 0 deletions UI/Scheduler/UIxAppointmentEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ - (NSException *) _adjustRecurrentRules
return ex;
}

- (void) _removeAttendees: (NSArray *) emails
{
NSString *email;
iCalEvent *event;
iCalPerson *attendee;
unsigned int i;

event = [self event];
attendee = [[[iCalPerson alloc] init] autorelease];

for (i = 0; i < [emails count]; i++)
{
email = [emails objectAtIndex: i];
[attendee setEmail: email];
[event removeFromAttendees: attendee];
}
}

/**
* @api {post} /so/:username/Calendar/:calendarId/:appointmentId/rsvpAppointment Set participation state
* @apiVersion 1.0.0
Expand Down Expand Up @@ -512,6 +530,7 @@ - (NSException *) _adjustRecurrentRules
*/
- (id <WOActionResults>) saveAction
{
NSArray *removeAttendees;
NSDictionary *params;
NSString *jsonResponse;
NSException *ex;
Expand Down Expand Up @@ -545,12 +564,19 @@ - (NSException *) _adjustRecurrentRules
{
[self setAttributes: params];
forceSave = [[params objectForKey: @"ignoreConflicts"] boolValue];
removeAttendees = [params objectForKey: @"removeAttendees"];

if ([event hasRecurrenceRules])
ex = [self _adjustRecurrentRules];

if (!ex)
{
if (removeAttendees)
{
[co expandGroupsInEvent: event];
[self _removeAttendees: removeAttendees];
}

if ([co isNew])
{
if (componentCalendar
Expand Down
18 changes: 13 additions & 5 deletions UI/Templates/SchedulerUI/UIxAppointmentEditorTemplate.wox
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,15 @@
</md-dialog-actions>

<!-- rejected attendee invitation -->
<md-dialog-content class="md-default-theme md-bg md-warn md-padding sg-dialog-message ng-hide" layout="row"
<md-dialog-content class="md-default-theme md-bg md-warn md-padding sg-dialog-message ng-hide" layout="column"
ng-show="editor.attendeeConflictError.reject">
<div class="md-flex">{{editor.attendeeConflictError.reject}}</div>
<md-button class="md-icon-button" ng-click="editor.edit(eventForm)">
<md-icon label:aria-label="Close">close</md-icon>
</md-button>
<div layout="row" layout-align="space-between start" layout-fill="layout-fill">
<div ng-bind-html="editor.attendeeConflictError.reject | txt2html"><!-- error --></div>
<md-button class="md-icon-button" ng-click="editor.edit(eventForm)">
<md-icon label:aria-label="Close">close</md-icon>
</md-button>
</div>
<div class="sg-padded--top"><var:string label:value="Would you like to remove them and send the invitation to the remaining attendees?"/></div>
</md-dialog-content>
<md-dialog-actions ng-show="editor.attendeeConflictError.reject">
<md-button type="button" ng-click="editor.cancel(eventForm)">
Expand All @@ -381,6 +384,11 @@
ng-click="editor.edit(eventForm)">
<var:string label:value="Edit"/>
</md-button>
<md-button class="md-warn" type="button"
ng-click="editor.save(eventForm, { removeAttendees: editor.attendeeConflictError.unavailableAttendees })"
ng-disabled="editor.eventForm.$invalid">
<var:string label:value="Save"/>
</md-button>
</md-dialog-actions>
</form>
</md-dialog>
Expand Down

0 comments on commit 4e5c865

Please sign in to comment.