Skip to content

Commit

Permalink
fix(event): user was considered busy for an event he has delegated
Browse files Browse the repository at this point in the history
  • Loading branch information
QHivert committed Mar 7, 2024
1 parent e4cb0a3 commit 815a87d
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions SoObjects/Appointments/SOGoAppointmentObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,11 @@ - (NSException *) _handleAttendeesConflicts: (NSArray *) theAttendees
{
NSMutableDictionary *info;
NSMutableArray *conflicts;
NSArray *emails, *partstates;
NSString *formattedEnd;
SOGoUser *ownerUser;
id o;
BOOL hasDelegated = NO;

info = [NSMutableDictionary dictionary];
conflicts = [NSMutableArray array];
Expand All @@ -855,23 +857,50 @@ - (NSException *) _handleAttendeesConflicts: (NSArray *) theAttendees
}

for (i = 0; i < [fbInfo count]; i++)
{
o = [fbInfo objectAtIndex: i];
//Check if the user has delegated the event
hasDelegated = NO;
emails = [[o objectForKey: @"c_partmails"] componentsSeparatedByString: @"\n"];
for (j = 0; j < [emails count]; j++)
{
o = [fbInfo objectAtIndex: i];
end = [o objectForKey: @"endDate"];
if ([[o objectForKey: @"startDate"] isDateOnSameDay: end])
formattedEnd = [formatter formattedTime: end];
else
formattedEnd = [formatter formattedDateAndTime: end];

[conflicts addObject: [NSDictionary dictionaryWithObjectsAndKeys: [formatter formattedDateAndTime: [o objectForKey: @"startDate"]], @"startDate",
formattedEnd, @"endDate", nil]];
if ([[info objectForKey:@"attendee_email"] isEqualToString: [emails objectAtIndex: j]])
{
// We now fetch the c_partstates array and get the participation status of the user for the event
partstates = [[o objectForKey: @"c_partstates"] componentsSeparatedByString: @"\n"];
if (i < [partstates count])
{
// 0: needs action (considered busy)
// 1: accepted (busy)
// 2: declined (free)
// 3: tentative (free)
// 4: delegated (free)
hasDelegated = ([[partstates objectAtIndex: j] intValue] == 4);
}
break;
}
}
if(hasDelegated)
continue;

[info setObject: conflicts forKey: @"conflicts"];
end = [o objectForKey: @"endDate"];
if ([[o objectForKey: @"startDate"] isDateOnSameDay: end])
formattedEnd = [formatter formattedTime: end];
else
formattedEnd = [formatter formattedDateAndTime: end];

// We immediately raise an exception, without processing the possible other attendees.
return [self exceptionWithHTTPStatus: 409
reason: [info jsonRepresentation]];
[conflicts addObject: [NSDictionary dictionaryWithObjectsAndKeys: [formatter formattedDateAndTime: [o objectForKey: @"startDate"]], @"startDate",
formattedEnd, @"endDate", nil]];
}

if([conflicts count] > 0)
{
[info setObject: conflicts forKey: @"conflicts"];

// We immediately raise an exception, without processing the possible other attendees.
return [self exceptionWithHTTPStatus: 409
reason: [info jsonRepresentation]];
}
}
} // if ([fbInfo count]) ...
else if (currentAttendee && [user isResource])
Expand Down

0 comments on commit 815a87d

Please sign in to comment.