From 398ef4dcde5182825e3641eb29b235e118debb1f Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 13 Sep 2018 15:56:31 -0400 Subject: [PATCH] Fix time conflict validation Fixes #4539 --- NEWS | 1 + .../Appointments/SOGoAppointmentFolder.m | 2 +- .../Appointments/SOGoAppointmentObject.m | 22 ++++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 06180a76b..48102e971 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ Bug fixes - [web] fixed popup window detection in message viewer (#4518) - [web] fixed behaviour of return receipt actions - [core] fixed email reminders support for tasks + - [core] fixed time conflict validation (#4539) 4.0.2 (2018-08-24) ------------------ diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index 6c8d9f4d5..6e6861d78 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -534,7 +534,7 @@ static Class iCalEventK = nil; = [self folderPropertyValueInCategory: @"FreeBusyExclusions" forUser: [SOGoUser userWithLogin: ownerInContext]]; - // User has not setting for freebusy inclusion/exclusion, + // User has no setting for freebusy inclusion/exclusion, // * include it if it's a personal folder; // * exclude it if it's a subscription. if (!excludeFromFreeBusy) diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index cbee61678..a15837e5b 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import #import @@ -59,6 +60,7 @@ #import "NSArray+Appointments.h" #import "SOGoAppointmentFolder.h" #import "SOGoAppointmentOccurence.h" +#import "SOGoFreeBusyObject.h" #import "SOGoAppointmentObject.h" @@ -627,6 +629,7 @@ { NSCalendarDate *start, *end, *rangeStartDate, *rangeEndDate; SOGoAppointmentFolder *folder; + SOGoFreeBusyObject *fb; NGCalendarDateRange *range; NSMutableArray *fbInfo; NSArray *allOccurences; @@ -642,7 +645,7 @@ end = [[theEvent endDate] dateByAddingYears: ([theEvent isRecurrent] ? 1 : 0) months: 0 days: 0 hours: 0 minutes: 0 seconds: -1]; folder = [user personalCalendarFolderInContext: context]; - + // Deny access to the resource if the ACLs don't allow the user if ([user isResource] && ![folder aclSQLListingFilter]) { @@ -656,8 +659,9 @@ return [NSException exceptionWithHTTPStatus:409 reason: reason]; } - fbInfo = [NSMutableArray arrayWithArray: [folder fetchFreeBusyInfosFrom: start - to: end]]; + fb = [SOGoFreeBusyObject objectWithName: @"freebusy.ifb" inContainer: [user homeFolderInContext: context]]; + fbInfo = [fb fetchFreeBusyInfosFrom: start to: end]; + // // We must also check here for repetitive events that don't overlap our event. // We remove all events that don't overlap. The events here are already @@ -778,6 +782,7 @@ { NSMutableDictionary *info; NSMutableArray *conflicts; + NSString *formattedEnd; id o; info = [NSMutableDictionary dictionary]; @@ -795,12 +800,19 @@ for (i = 0; i < [fbInfo count]; i++) { o = [fbInfo objectAtIndex: i]; + end = [o objectForKey: @"endDate"]; + if ([[o objectForKey: @"startDate"] isDateOnSameDay: end]) + formattedEnd = [formatter formattedTime: end]; + else + [formatter formattedDateAndTime: end]; + [conflicts addObject: [NSDictionary dictionaryWithObjectsAndKeys: [formatter formattedDateAndTime: [o objectForKey: @"startDate"]], @"startDate", - [formatter formattedDateAndTime: [o objectForKey: @"endDate"]], @"endDate", nil]]; + formattedEnd, @"endDate", nil]]; } [info setObject: conflicts forKey: @"conflicts"]; + // We immediately raise an exception, without processing the possible other attendees. return [NSException exceptionWithHTTPStatus: 409 reason: [info jsonRepresentation]]; } @@ -814,7 +826,7 @@ [currentAttendee setParticipationStatus: iCalPersonPartStatAccepted]; _resourceHasAutoAccepted = YES; } - } // if ([user isResource]) ... + } return nil; }