2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
2008-12-23 19:43:37 +01:00
|
|
|
Copyright (C) 2007-2008 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-07-05 00:25:27 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-09-06 22:51:59 +02:00
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2006-10-11 20:58:16 +02:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalEvent.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGCards/iCalEventChanges.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
2008-07-05 00:25:27 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2006-10-31 19:54:56 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <SoObjects/SOGo/iCalEntityObject+Utilities.h>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/LDAPUserManager.h>
|
2007-11-13 23:38:05 +01:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <SoObjects/SOGo/NSObject+DAV.h>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoObject.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoWebDAVAclManager.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoWebDAVValue.h>
|
2007-11-08 20:56:18 +01:00
|
|
|
#import <SoObjects/SOGo/WORequest+SOGo.h>
|
2006-10-31 19:54:56 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
#import "iCalEventChanges+SOGo.h"
|
|
|
|
#import "iCalEntityObject+SOGo.h"
|
|
|
|
#import "iCalPerson+SOGo.h"
|
2008-07-17 23:12:43 +02:00
|
|
|
#import "NSArray+Appointments.h"
|
|
|
|
#import "SOGoAppointmentFolder.h"
|
|
|
|
#import "SOGoAppointmentOccurence.h"
|
2008-11-22 08:20:22 +01:00
|
|
|
#import "SOGoCalendarComponent.h"
|
2007-09-15 00:01:02 +02:00
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import "SOGoAppointmentObject.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoAppointmentObject
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
+ (SOGoWebDAVAclManager *) webdavAclManager
|
|
|
|
{
|
2008-12-15 23:27:45 +01:00
|
|
|
static SOGoWebDAVAclManager *aclManager = nil;
|
2008-05-03 01:08:15 +02:00
|
|
|
NSString *nsD, *nsI;
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
if (!aclManager)
|
2008-05-03 01:08:15 +02:00
|
|
|
{
|
|
|
|
nsD = @"DAV:";
|
|
|
|
nsI = @"urn:inverse:params:xml:ns:inverse-dav";
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
aclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-current-user-privilege-set", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"read", nsD)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"view-whole-component", nsI)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SOGoCalendarPerm_ViewAllComponent
|
|
|
|
asChildOf: davElement (@"read", nsD)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"view-date-and-time", nsI)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SOGoCalendarPerm_ViewDAndT
|
|
|
|
asChildOf: davElement (@"view-whole-component", nsI)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write", nsD)
|
|
|
|
abstract: YES
|
2008-08-07 15:31:09 +02:00
|
|
|
withEquivalent: SOGoCalendarPerm_ModifyComponent
|
2008-07-29 18:36:16 +02:00
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[aclManager
|
2008-05-03 01:08:15 +02:00
|
|
|
registerDAVPermission: davElement (@"write-properties", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions /* hackish */
|
|
|
|
asChildOf: davElement (@"write", nsD)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-05-03 01:08:15 +02:00
|
|
|
registerDAVPermission: davElement (@"write-content", nsD)
|
|
|
|
abstract: YES
|
2008-08-07 15:31:09 +02:00
|
|
|
withEquivalent: nil
|
2008-05-03 01:08:15 +02:00
|
|
|
asChildOf: davElement (@"write", nsD)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-05-03 01:08:15 +02:00
|
|
|
registerDAVPermission: davElement (@"respond-to-component", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoCalendarPerm_RespondToComponent
|
|
|
|
asChildOf: davElement (@"write-content", nsD)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager registerDAVPermission: davElement (@"admin", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[aclManager
|
2008-05-03 01:08:15 +02:00
|
|
|
registerDAVPermission: davElement (@"read-acl", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoPerm_ReadAcls
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-05-03 01:08:15 +02:00
|
|
|
registerDAVPermission: davElement (@"write-acl", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
}
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
return aclManager;
|
2008-05-03 01:08:15 +02:00
|
|
|
}
|
|
|
|
|
2007-02-15 21:59:02 +01:00
|
|
|
- (NSString *) componentTag
|
2006-11-07 19:15:42 +01:00
|
|
|
{
|
2007-02-15 21:59:02 +01:00
|
|
|
return @"vevent";
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
- (SOGoComponentOccurence *) occurence: (iCalRepeatableEntityObject *) occ
|
|
|
|
{
|
2009-03-16 22:08:19 +01:00
|
|
|
NSArray *allEvents;
|
|
|
|
|
|
|
|
allEvents = [[occ parent] events];
|
|
|
|
|
|
|
|
return [SOGoAppointmentOccurence
|
|
|
|
occurenceWithComponent: occ
|
|
|
|
withMasterComponent: [allEvents objectAtIndex: 0]
|
|
|
|
inContainer: self];
|
2008-07-17 23:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalRepeatableEntityObject *) newOccurenceWithID: (NSString *) recID
|
|
|
|
{
|
|
|
|
iCalEvent *newOccurence;
|
|
|
|
NSCalendarDate *date;
|
2008-12-30 17:57:46 +01:00
|
|
|
unsigned int interval, nbrDays;
|
2008-07-17 23:12:43 +02:00
|
|
|
|
|
|
|
newOccurence = (iCalEvent *) [super newOccurenceWithID: recID];
|
|
|
|
date = [newOccurence recurrenceId];
|
|
|
|
interval = [[newOccurence endDate]
|
|
|
|
timeIntervalSinceDate: [newOccurence startDate]];
|
2008-12-30 17:57:46 +01:00
|
|
|
if ([newOccurence isAllDay])
|
|
|
|
{
|
|
|
|
nbrDays = ((float) abs (interval) / 86400) + 1;
|
|
|
|
[newOccurence setAllDayWithStartDate: date
|
|
|
|
duration: nbrDays];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[newOccurence setStartDate: date];
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
[newOccurence setEndDate: [date addYear: 0
|
|
|
|
month: 0
|
|
|
|
day: 0
|
|
|
|
hour: 0
|
|
|
|
minute: 0
|
|
|
|
second: interval]];
|
|
|
|
|
|
|
|
return newOccurence;
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (SOGoAppointmentObject *) _lookupEvent: (NSString *) eventUID
|
|
|
|
forUID: (NSString *) uid
|
2007-01-31 21:15:28 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
SOGoAppointmentObject *object;
|
2009-03-23 22:19:55 +01:00
|
|
|
NSArray *folders;
|
|
|
|
NSEnumerator *e;
|
2007-11-18 11:16:25 +01:00
|
|
|
NSString *possibleName;
|
|
|
|
|
2009-03-23 22:19:55 +01:00
|
|
|
object = nil;
|
|
|
|
folders = [container lookupCalendarFoldersForUID: uid];
|
|
|
|
e = [folders objectEnumerator];
|
|
|
|
while ( object == nil && (folder = [e nextObject]) )
|
2007-02-15 21:59:02 +01:00
|
|
|
{
|
2009-03-23 22:19:55 +01:00
|
|
|
object = [folder lookupName: nameInContainer
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
if ([object isKindOfClass: [NSException class]])
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
2009-03-23 22:19:55 +01:00
|
|
|
possibleName = [folder resourceNameForEventUID: eventUID];
|
|
|
|
if (possibleName)
|
|
|
|
{
|
|
|
|
object = [folder lookupName: possibleName
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if ([object isKindOfClass: [NSException class]])
|
|
|
|
object = nil;
|
|
|
|
}
|
|
|
|
else
|
2007-11-18 11:16:25 +01:00
|
|
|
object = nil;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-02-15 21:59:02 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!object)
|
2008-07-14 18:47:10 +02:00
|
|
|
{
|
2009-03-24 16:50:50 +01:00
|
|
|
folder = [container lookupCalendarFolderForUID: uid];
|
2008-07-14 18:47:10 +02:00
|
|
|
object = [SOGoAppointmentObject objectWithName: nameInContainer
|
|
|
|
inContainer: folder];
|
|
|
|
[object setIsNew: YES];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
return object;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-11-26 13:20:26 +01:00
|
|
|
- (void) _addOrUpdateEvent: (iCalEvent *) theEvent
|
|
|
|
forUID: (NSString *) theUID
|
|
|
|
owner: (NSString *) theOwner
|
2007-08-24 00:11:19 +02:00
|
|
|
{
|
2008-11-26 13:20:26 +01:00
|
|
|
if (![theUID isEqualToString: theOwner])
|
2007-11-08 00:35:26 +01:00
|
|
|
{
|
2008-11-26 13:20:26 +01:00
|
|
|
SOGoAppointmentObject *object;
|
|
|
|
NSString *iCalString;
|
|
|
|
|
|
|
|
object = [self _lookupEvent: [theEvent uid] forUID: theUID];
|
2008-12-20 00:04:26 +01:00
|
|
|
|
|
|
|
// We must add an occurence to a non-existing event. We have
|
|
|
|
// to handle this with care, as in the postCalDAVEventRequestTo:from:
|
|
|
|
if ([object isNew] && [theEvent recurrenceId])
|
|
|
|
{
|
|
|
|
SOGoAppointmentObject *ownerEventObject;
|
|
|
|
NSArray *attendees;
|
|
|
|
iCalPerson *person;
|
|
|
|
SOGoUser *user;
|
|
|
|
BOOL found;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: theUID roles: nil];
|
|
|
|
person = [iCalPerson elementWithTag: @"attendee"];
|
|
|
|
[person setCn: [user cn]];
|
|
|
|
[person setEmail: [[user allEmails] objectAtIndex: 0]];
|
|
|
|
[person setParticipationStatus: iCalPersonPartStatDeclined];
|
|
|
|
[person setRsvp: @"TRUE"];
|
|
|
|
[person setRole: @"REQ-PARTICIPANT"];
|
|
|
|
|
|
|
|
ownerEventObject = [self _lookupEvent: [theEvent uid] forUID: theOwner];
|
|
|
|
theEvent = [[[theEvent parent] events] objectAtIndex: 0];
|
|
|
|
attendees = [theEvent attendees];
|
|
|
|
found = NO;
|
|
|
|
|
|
|
|
// We check if the attendee that was added to a single occurence is
|
|
|
|
// present in the master component. If not, we add it with a participation
|
|
|
|
// status set to "DECLINED"
|
|
|
|
for (i = 0; i < [attendees count]; i++)
|
|
|
|
{
|
|
|
|
if ([[attendees objectAtIndex: i] hasSameEmailAddress: person])
|
|
|
|
{
|
|
|
|
found = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
[theEvent addToAttendees: person];
|
|
|
|
iCalString = [[theEvent parent] versitString];
|
|
|
|
[ownerEventObject saveContentString: iCalString];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iCalString = [[theEvent parent] versitString];
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[object saveContentString: iCalString];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
2007-01-31 21:15:28 +01:00
|
|
|
|
2008-11-26 13:20:26 +01:00
|
|
|
- (void) _removeEventFromUID: (NSString *) theUID
|
|
|
|
owner: (NSString *) theOwner
|
2008-12-04 00:08:37 +01:00
|
|
|
withRecurrenceId: (NSCalendarDate *) recurrenceId
|
2007-11-07 16:58:43 +01:00
|
|
|
{
|
2008-11-26 13:20:26 +01:00
|
|
|
if (![theUID isEqualToString: theOwner])
|
2007-11-07 16:58:43 +01:00
|
|
|
{
|
2008-11-26 13:20:26 +01:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
SOGoAppointmentObject *object;
|
2008-12-05 17:11:41 +01:00
|
|
|
iCalEntityObject *currentOccurence;
|
2008-12-04 00:08:37 +01:00
|
|
|
iCalRepeatableEntityObject *event;
|
|
|
|
iCalCalendar *calendar;
|
2008-12-05 17:11:41 +01:00
|
|
|
NSCalendarDate *currentId;
|
|
|
|
NSString *calendarContent;
|
2009-04-01 15:49:24 +02:00
|
|
|
NSArray *occurences;
|
2008-12-05 17:11:41 +01:00
|
|
|
int max, count;
|
2009-03-23 22:19:55 +01:00
|
|
|
|
|
|
|
// Invitations are always written to the personal folder; it's not necessay
|
|
|
|
// to look into all folders of the user
|
2008-11-26 13:20:26 +01:00
|
|
|
folder = [container lookupCalendarFolderForUID: theUID];
|
2007-11-18 11:16:25 +01:00
|
|
|
object = [folder lookupName: nameInContainer
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if (![object isKindOfClass: [NSException class]])
|
2008-12-04 00:08:37 +01:00
|
|
|
{
|
|
|
|
if (recurrenceId == nil)
|
|
|
|
[object delete];
|
|
|
|
else
|
|
|
|
{
|
2008-12-05 17:11:41 +01:00
|
|
|
calendar = [object calendar: NO secure: NO];
|
2009-03-23 22:19:55 +01:00
|
|
|
|
2008-12-05 17:11:41 +01:00
|
|
|
// If recurrenceId is defined, remove the occurence from
|
|
|
|
// the repeating event.
|
|
|
|
occurences = [calendar events];
|
|
|
|
max = [occurences count];
|
|
|
|
count = 1;
|
|
|
|
while (count < max)
|
2008-12-04 00:08:37 +01:00
|
|
|
{
|
2008-12-05 17:11:41 +01:00
|
|
|
currentOccurence = [occurences objectAtIndex: count];
|
|
|
|
currentId = [currentOccurence recurrenceId];
|
|
|
|
if ([currentId compare: recurrenceId] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
[[calendar children] removeObject: currentOccurence];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
2008-12-04 00:08:37 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 17:11:41 +01:00
|
|
|
// Add an date exception.
|
2008-12-04 00:08:37 +01:00
|
|
|
event = (iCalRepeatableEntityObject*)[calendar firstChildWithTag: [object componentTag]];
|
|
|
|
[event addToExceptionDates: recurrenceId];
|
2009-03-23 22:19:55 +01:00
|
|
|
|
2008-12-05 17:11:41 +01:00
|
|
|
[event increaseSequence];
|
2009-03-23 22:19:55 +01:00
|
|
|
|
2008-12-04 00:08:37 +01:00
|
|
|
// We generate the updated iCalendar file and we save it
|
|
|
|
// in the database.
|
|
|
|
calendarContent = [calendar versitString];
|
|
|
|
[object saveContentString: calendarContent];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _handleRemovedUsers: (NSArray *) attendees
|
2008-12-04 00:08:37 +01:00
|
|
|
withRecurrenceId: (NSCalendarDate *) recurrenceId
|
2007-09-06 22:51:59 +02:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
NSEnumerator *enumerator;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *currentUID;
|
2007-09-06 22:51:59 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
enumerator = [attendees objectEnumerator];
|
|
|
|
while ((currentAttendee = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
currentUID = [currentAttendee uid];
|
|
|
|
if (currentUID)
|
2008-11-26 13:20:26 +01:00
|
|
|
[self _removeEventFromUID: currentUID
|
2008-12-04 00:08:37 +01:00
|
|
|
owner: owner
|
|
|
|
withRecurrenceId: recurrenceId];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
2007-09-06 22:51:59 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _requireResponseFromAttendees: (NSArray *) attendees
|
2006-09-28 19:23:39 +02:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
NSEnumerator *enumerator;
|
|
|
|
iCalPerson *currentAttendee;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
enumerator = [attendees objectEnumerator];
|
|
|
|
while ((currentAttendee = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
[currentAttendee setRsvp: @"TRUE"];
|
|
|
|
[currentAttendee setParticipationStatus: iCalPersonPartStatNeedsAction];
|
|
|
|
}
|
|
|
|
}
|
2007-11-08 20:56:18 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _handleSequenceUpdateInEvent: (iCalEvent *) newEvent
|
|
|
|
ignoringAttendees: (NSArray *) attendees
|
|
|
|
fromOldEvent: (iCalEvent *) oldEvent
|
|
|
|
{
|
|
|
|
NSMutableArray *updateAttendees, *updateUIDs;
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *currentUID;
|
2007-11-08 20:56:18 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
updateAttendees = [NSMutableArray arrayWithArray: [newEvent attendees]];
|
|
|
|
[updateAttendees removeObjectsInArray: attendees];
|
2007-11-08 20:56:18 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
updateUIDs = [NSMutableArray arrayWithCapacity: [updateAttendees count]];
|
|
|
|
enumerator = [updateAttendees objectEnumerator];
|
|
|
|
while ((currentAttendee = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
currentUID = [currentAttendee uid];
|
|
|
|
if (currentUID)
|
|
|
|
[self _addOrUpdateEvent: newEvent
|
2008-11-26 13:20:26 +01:00
|
|
|
forUID: currentUID
|
|
|
|
owner: owner];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-11-18 01:06:37 +01:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Update"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: [newEvent itipEntryWithMethod: @"request"]
|
2008-11-18 01:06:37 +01:00
|
|
|
previousObject: oldEvent
|
2007-11-18 11:16:25 +01:00
|
|
|
toAttendees: updateAttendees];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _handleAddedUsers: (NSArray *) attendees
|
|
|
|
fromEvent: (iCalEvent *) newEvent
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *currentUID;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
enumerator = [attendees objectEnumerator];
|
|
|
|
while ((currentAttendee = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
currentUID = [currentAttendee uid];
|
|
|
|
if (currentUID)
|
|
|
|
[self _addOrUpdateEvent: newEvent
|
2008-11-26 13:20:26 +01:00
|
|
|
forUID: currentUID
|
|
|
|
owner: owner];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _handleUpdatedEvent: (iCalEvent *) newEvent
|
|
|
|
fromOldEvent: (iCalEvent *) oldEvent
|
|
|
|
{
|
|
|
|
NSArray *attendees;
|
|
|
|
iCalEventChanges *changes;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
changes = [newEvent getChangesRelativeToEvent: oldEvent];
|
|
|
|
attendees = [changes deletedAttendees];
|
|
|
|
if ([attendees count])
|
|
|
|
{
|
2008-12-04 00:08:37 +01:00
|
|
|
[self _handleRemovedUsers: attendees
|
|
|
|
withRecurrenceId: [newEvent recurrenceId]];
|
2007-11-18 11:16:25 +01:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Deletion"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: [newEvent itipEntryWithMethod: @"cancel"]
|
2008-11-18 01:06:37 +01:00
|
|
|
previousObject: oldEvent
|
2007-11-18 11:16:25 +01:00
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
attendees = [changes insertedAttendees];
|
|
|
|
if ([changes sequenceShouldBeIncreased])
|
|
|
|
{
|
|
|
|
[newEvent increaseSequence];
|
2008-12-09 16:29:39 +01:00
|
|
|
// Set new attendees status to "needs action"
|
2007-11-18 11:16:25 +01:00
|
|
|
[self _requireResponseFromAttendees: [newEvent attendees]];
|
2008-12-09 16:29:39 +01:00
|
|
|
// Update attendees calendars and send them an update
|
|
|
|
// notification by email
|
2007-11-18 11:16:25 +01:00
|
|
|
[self _handleSequenceUpdateInEvent: newEvent
|
|
|
|
ignoringAttendees: attendees
|
|
|
|
fromOldEvent: oldEvent];
|
|
|
|
}
|
|
|
|
else
|
2008-11-29 00:10:41 +01:00
|
|
|
{
|
|
|
|
// If other attributes have changed, update the event
|
|
|
|
// in each attendee's calendar
|
|
|
|
if ([[changes updatedProperties] count])
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
iCalPerson *currentAttendee;
|
|
|
|
NSString *currentUID;
|
|
|
|
|
|
|
|
enumerator = [[newEvent attendees] objectEnumerator];
|
|
|
|
while ((currentAttendee = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
currentUID = [currentAttendee uid];
|
|
|
|
if (currentUID)
|
|
|
|
[self _addOrUpdateEvent: newEvent
|
|
|
|
forUID: currentUID
|
|
|
|
owner: owner];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if ([attendees count])
|
|
|
|
{
|
2008-11-29 00:10:41 +01:00
|
|
|
// Send an invitation to new attendees
|
2007-11-18 11:16:25 +01:00
|
|
|
[self _handleAddedUsers: attendees fromEvent: newEvent];
|
2008-11-29 00:10:41 +01:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Invitation"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: [newEvent itipEntryWithMethod: @"request"]
|
2008-11-18 01:06:37 +01:00
|
|
|
previousObject: oldEvent
|
2007-11-18 11:16:25 +01:00
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) saveComponent: (iCalEvent *) newEvent
|
|
|
|
{
|
|
|
|
iCalEvent *oldEvent;
|
|
|
|
NSArray *attendees;
|
2008-12-03 17:18:12 +01:00
|
|
|
NSCalendarDate *recurrenceId;
|
|
|
|
NSString *recurrenceTime;
|
2008-08-14 00:30:55 +02:00
|
|
|
SOGoUser *ownerUser;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[[newEvent parent] setMethod: @""];
|
2008-08-14 00:30:55 +02:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
2008-12-17 16:35:53 +01:00
|
|
|
|
2008-12-01 20:20:25 +01:00
|
|
|
// We first save the event. It is important to this initially
|
|
|
|
// as the event's UID might get modified in SOGoCalendarComponent: -saveComponent:
|
2008-12-17 16:35:53 +01:00
|
|
|
[super saveComponent: newEvent];
|
2008-11-26 17:26:32 +01:00
|
|
|
|
2008-08-14 00:30:55 +02:00
|
|
|
if ([newEvent userIsOrganizer: ownerUser])
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
2008-11-28 20:54:51 +01:00
|
|
|
if ([self isNew])
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2008-11-28 20:54:51 +01:00
|
|
|
// New event -- send invitation to all attendees
|
2008-11-26 17:26:32 +01:00
|
|
|
attendees = [newEvent attendeesWithoutUser: ownerUser];
|
2007-11-08 20:56:18 +01:00
|
|
|
if ([attendees count])
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
[self _handleAddedUsers: attendees fromEvent: newEvent];
|
|
|
|
[self sendEMailUsingTemplateNamed: @"Invitation"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: [newEvent itipEntryWithMethod: @"request"]
|
2008-11-28 20:54:51 +01:00
|
|
|
previousObject: nil
|
2007-11-08 20:56:18 +01:00
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2008-08-14 00:30:55 +02:00
|
|
|
if (![[newEvent attendees] count])
|
2007-11-18 11:16:25 +01:00
|
|
|
[[newEvent uniqueChildWithTag: @"organizer"] setValue: 0
|
|
|
|
to: @""];
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
2008-11-28 20:54:51 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Event is modified -- sent update status to all attendees
|
2008-12-05 17:11:41 +01:00
|
|
|
// and modify their calendars.
|
2008-12-03 17:18:12 +01:00
|
|
|
recurrenceId = [newEvent recurrenceId];
|
|
|
|
if (recurrenceId == nil)
|
|
|
|
oldEvent = [self component: NO secure: NO];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If recurrenceId is defined, find the specified occurence
|
|
|
|
// within the repeating vEvent.
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]];
|
|
|
|
oldEvent = (iCalEvent*)[self lookupOccurence: recurrenceTime];
|
|
|
|
if (oldEvent == nil)
|
|
|
|
// If no occurence found, create one
|
|
|
|
oldEvent = (iCalEvent*)[self newOccurenceWithID: recurrenceTime];
|
|
|
|
}
|
2008-11-28 20:54:51 +01:00
|
|
|
[self _handleUpdatedEvent: newEvent fromOldEvent: oldEvent];
|
2008-12-03 17:18:12 +01:00
|
|
|
|
|
|
|
// The sequence has possibly been increased -- resave the event
|
|
|
|
[super saveComponent: newEvent];
|
2008-11-28 20:54:51 +01:00
|
|
|
}
|
2007-01-31 21:15:28 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-11-10 16:38:05 +01:00
|
|
|
//
|
|
|
|
// This method is used to update the status of an attendee.
|
|
|
|
//
|
|
|
|
// - theOwnerUser is owner of the calendar where the attendee
|
|
|
|
// participation state has changed.
|
|
|
|
// - uid is the actual UID of the user for whom we must
|
|
|
|
// update the calendar event (with the participation change)
|
|
|
|
//
|
|
|
|
// This method is called multiple times, in order to update the
|
|
|
|
// status of the attendee in calendars for the particular event UID.
|
|
|
|
//
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSException *) _updateAttendee: (iCalPerson *) attendee
|
2008-11-05 22:04:16 +01:00
|
|
|
ownerUser: (SOGoUser *) theOwnerUser
|
2007-11-18 11:16:25 +01:00
|
|
|
forEventUID: (NSString *) eventUID
|
2008-11-22 08:20:22 +01:00
|
|
|
withRecurrenceId: (NSCalendarDate *) recurrenceId
|
2007-11-18 11:16:25 +01:00
|
|
|
withSequence: (NSNumber *) sequence
|
|
|
|
forUID: (NSString *) uid
|
2008-11-05 22:04:16 +01:00
|
|
|
shouldAddSentBy: (BOOL) b
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentObject *eventObject;
|
2008-11-22 08:20:22 +01:00
|
|
|
iCalCalendar *calendar;
|
|
|
|
iCalEntityObject *event;
|
2007-11-18 11:16:25 +01:00
|
|
|
iCalPerson *otherAttendee;
|
2008-11-22 08:20:22 +01:00
|
|
|
NSString *iCalString, *recurrenceTime;
|
2007-11-08 20:56:18 +01:00
|
|
|
NSException *error;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
error = nil;
|
|
|
|
|
|
|
|
eventObject = [self _lookupEvent: eventUID forUID: uid];
|
|
|
|
if (![eventObject isNew])
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2008-11-22 08:20:22 +01:00
|
|
|
if (recurrenceId == nil)
|
|
|
|
{
|
|
|
|
// We must update main event and all its occurences (if any).
|
|
|
|
calendar = [eventObject calendar: NO secure: NO];
|
2008-12-03 17:18:12 +01:00
|
|
|
event = (iCalEntityObject*)[calendar firstChildWithTag: [self componentTag]];
|
2008-11-22 08:20:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If recurrenceId is defined, find the specified occurence
|
|
|
|
// within the repeating vEvent.
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]];
|
|
|
|
event = [eventObject lookupOccurence: recurrenceTime];
|
|
|
|
|
|
|
|
if (event == nil)
|
2008-12-01 17:24:15 +01:00
|
|
|
// If no occurence found, create one
|
2008-11-22 08:20:22 +01:00
|
|
|
event = [eventObject newOccurenceWithID: recurrenceTime];
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if ([[event sequence] compare: sequence]
|
|
|
|
== NSOrderedSame)
|
|
|
|
{
|
2008-11-05 22:04:16 +01:00
|
|
|
SOGoUser *currentUser;
|
2008-11-22 08:20:22 +01:00
|
|
|
|
2008-12-02 04:35:34 +01:00
|
|
|
currentUser = [context activeUser];
|
2008-12-09 16:29:39 +01:00
|
|
|
otherAttendee = [event findParticipant: theOwnerUser];
|
|
|
|
[otherAttendee setPartStat: [attendee partStat]];
|
2008-12-02 04:35:34 +01:00
|
|
|
|
2008-12-09 16:29:39 +01:00
|
|
|
// If one has accepted / declined an invitation on behalf of
|
|
|
|
// the attendee, we add the user to the SENT-BY attribute.
|
|
|
|
if (b && ![[currentUser login] isEqualToString: [theOwnerUser login]])
|
2008-11-13 14:41:43 +01:00
|
|
|
{
|
2008-12-09 16:29:39 +01:00
|
|
|
NSString *currentEmail;
|
|
|
|
currentEmail = [[currentUser allEmails] objectAtIndex: 0];
|
|
|
|
[otherAttendee addAttribute: @"SENT-BY"
|
|
|
|
value: [NSString stringWithFormat: @"\"MAILTO:%@\"", currentEmail]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We must REMOVE any SENT-BY here. This is important since if A accepted
|
|
|
|
// the event for B and then, B changes by himself his participation status,
|
|
|
|
// we don't want to keep the previous SENT-BY attribute there.
|
|
|
|
[(NSMutableDictionary *)[otherAttendee attributes] removeObjectForKey: @"SENT-BY"];
|
2008-11-13 14:41:43 +01:00
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
2008-12-09 16:29:39 +01:00
|
|
|
|
|
|
|
// We generate the updated iCalendar file and we save it
|
|
|
|
// in the database.
|
|
|
|
iCalString = [[event parent] versitString];
|
|
|
|
error = [eventObject saveContentString: iCalString];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
2008-12-09 16:29:39 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-11-10 16:38:05 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// This method is invoked only from the SOGo Web interface.
|
|
|
|
//
|
|
|
|
// - theOwnerUser is owner of the calendar where the attendee
|
|
|
|
// participation state has changed.
|
|
|
|
//
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSException *) _handleAttendee: (iCalPerson *) attendee
|
2008-11-05 22:04:16 +01:00
|
|
|
ownerUser: (SOGoUser *) theOwnerUser
|
2007-11-18 11:16:25 +01:00
|
|
|
statusChange: (NSString *) newStatus
|
|
|
|
inEvent: (iCalEvent *) event
|
|
|
|
{
|
2008-11-18 01:06:37 +01:00
|
|
|
NSString *newContent, *currentStatus, *organizerUID;
|
|
|
|
SOGoUser *ownerUser, *currentUser;
|
2008-11-10 16:38:05 +01:00
|
|
|
NSException *ex;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
ex = nil;
|
|
|
|
|
|
|
|
currentStatus = [attendee partStat];
|
|
|
|
if ([currentStatus caseInsensitiveCompare: newStatus]
|
|
|
|
!= NSOrderedSame)
|
|
|
|
{
|
|
|
|
[attendee setPartStat: newStatus];
|
2008-11-05 22:04:16 +01:00
|
|
|
|
|
|
|
// If one has accepted / declined an invitation on behalf of
|
|
|
|
// the attendee, we add the user to the SENT-BY attribute.
|
|
|
|
currentUser = [context activeUser];
|
|
|
|
if (![[currentUser login] isEqualToString: [theOwnerUser login]])
|
|
|
|
{
|
|
|
|
NSString *currentEmail;
|
|
|
|
currentEmail = [[currentUser allEmails] objectAtIndex: 0];
|
|
|
|
[attendee addAttribute: @"SENT-BY"
|
|
|
|
value: [NSString stringWithFormat: @"\"MAILTO:%@\"", currentEmail]];
|
|
|
|
}
|
2008-11-13 14:41:43 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// We must REMOVE any SENT-BY here. This is important since if A accepted
|
|
|
|
// the event for B and then, B changes by himself his participation status,
|
|
|
|
// we don't want to keep the previous SENT-BY attribute there.
|
|
|
|
[(NSMutableDictionary *)[attendee attributes] removeObjectForKey: @"SENT-BY"];
|
|
|
|
}
|
2008-11-05 22:04:16 +01:00
|
|
|
|
|
|
|
// We generate the updated iCalendar file and we save it
|
|
|
|
// in the database.
|
2007-11-18 11:16:25 +01:00
|
|
|
newContent = [[event parent] versitString];
|
|
|
|
ex = [self saveContentString: newContent];
|
2008-11-05 22:04:16 +01:00
|
|
|
|
2008-11-10 16:38:05 +01:00
|
|
|
// If the current user isn't the organizer of the event
|
|
|
|
// that has just been updated, we update the event and
|
|
|
|
// send a notification
|
2008-08-09 18:48:18 +02:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
2008-08-09 18:47:13 +02:00
|
|
|
if (!(ex || [event userIsOrganizer: ownerUser]))
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2007-11-20 15:47:05 +01:00
|
|
|
if ([[attendee rsvp] isEqualToString: @"true"]
|
|
|
|
&& [event isStillRelevant])
|
2008-11-10 16:38:05 +01:00
|
|
|
[self sendResponseToOrganizer: event
|
|
|
|
from: ownerUser];
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
organizerUID = [[event organizer] uid];
|
2008-11-22 08:20:22 +01:00
|
|
|
|
|
|
|
if (!organizerUID)
|
|
|
|
// event is an recurrence; retrieve organizer from master event
|
|
|
|
organizerUID = [[(iCalEntityObject*)[[event parent] firstChildWithTag: [self componentTag]] organizer] uid];
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if (organizerUID)
|
2008-12-09 16:29:39 +01:00
|
|
|
// Update the attendee in organizer's calendar.
|
2007-11-18 11:16:25 +01:00
|
|
|
ex = [self _updateAttendee: attendee
|
2008-11-05 22:04:16 +01:00
|
|
|
ownerUser: theOwnerUser
|
2007-11-18 11:16:25 +01:00
|
|
|
forEventUID: [event uid]
|
2008-11-22 08:20:22 +01:00
|
|
|
withRecurrenceId: [event recurrenceId]
|
2007-11-18 11:16:25 +01:00
|
|
|
withSequence: [event sequence]
|
2008-11-05 22:04:16 +01:00
|
|
|
forUID: organizerUID
|
|
|
|
shouldAddSentBy: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
// We update the calendar of all participants that are
|
|
|
|
// local to the system. This is useful in case user A accepts
|
|
|
|
// invitation from organizer B and users C, D, E who are also
|
|
|
|
// attendees need to verify if A has accepted.
|
|
|
|
NSArray *attendees;
|
|
|
|
iCalPerson *att;
|
|
|
|
NSString *uid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
attendees = [event attendees];
|
|
|
|
|
|
|
|
for (i = 0; i < [attendees count]; i++)
|
|
|
|
{
|
|
|
|
att = [attendees objectAtIndex: i];
|
|
|
|
|
|
|
|
if (att == attendee) continue;
|
|
|
|
|
|
|
|
uid = [[LDAPUserManager sharedUserManager]
|
|
|
|
getUIDForEmail: [att rfc822Email]];
|
|
|
|
|
|
|
|
if (uid)
|
|
|
|
{
|
|
|
|
[self _updateAttendee: attendee
|
|
|
|
ownerUser: theOwnerUser
|
|
|
|
forEventUID: [event uid]
|
2008-11-22 08:20:22 +01:00
|
|
|
withRecurrenceId: [event recurrenceId]
|
2008-11-05 22:04:16 +01:00
|
|
|
withSequence: [event sequence]
|
|
|
|
forUID: uid
|
|
|
|
shouldAddSentBy: YES];
|
|
|
|
}
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ex;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-07-09 17:43:48 +02:00
|
|
|
- (NSDictionary *) _caldavSuccessCodeWithRecipient: (NSString *) recipient
|
|
|
|
{
|
|
|
|
NSMutableArray *element;
|
|
|
|
NSDictionary *code;
|
|
|
|
|
|
|
|
element = [NSMutableArray new];
|
|
|
|
[element addObject: davElementWithContent (@"recipient", XMLNS_CALDAV,
|
|
|
|
recipient)];
|
|
|
|
[element addObject: davElementWithContent (@"request-status",
|
|
|
|
XMLNS_CALDAV,
|
|
|
|
@"2.0;Success")];
|
|
|
|
code = davElementWithContent (@"response", XMLNS_CALDAV,
|
|
|
|
element);
|
|
|
|
[element release];
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2008-11-26 13:20:26 +01:00
|
|
|
//
|
|
|
|
// The originator here is the owner of the calendar where
|
|
|
|
// the event was created. Lightning sends us exactly this
|
|
|
|
// and handles the SENT-BY itself. We might have to review
|
|
|
|
// this if the originator ever becomes the user on whom
|
|
|
|
// the act is performed (ie. Alice creates an event in Bob's
|
|
|
|
// calendar and invites Thomas).
|
|
|
|
//
|
2008-07-05 00:25:27 +02:00
|
|
|
- (NSArray *) postCalDAVEventRequestTo: (NSArray *) recipients
|
2008-11-10 16:38:05 +01:00
|
|
|
from: (NSString *) originator
|
2008-07-05 00:25:27 +02:00
|
|
|
{
|
2008-07-09 17:43:48 +02:00
|
|
|
NSMutableArray *elements;
|
2008-07-05 00:25:27 +02:00
|
|
|
NSEnumerator *recipientsEnum;
|
2008-12-09 16:29:39 +01:00
|
|
|
NSString *recipient, *uid, *ownerUID;
|
2008-12-09 18:28:08 +01:00
|
|
|
iCalEvent *newEvent, *oldEvent, *emailEvent;
|
2008-07-05 00:25:27 +02:00
|
|
|
iCalPerson *person;
|
2008-11-18 21:59:08 +01:00
|
|
|
BOOL isUpdate, hasChanged;
|
|
|
|
|
2008-07-05 00:25:27 +02:00
|
|
|
elements = [NSMutableArray array];
|
2008-12-09 16:29:39 +01:00
|
|
|
ownerUID = [[LDAPUserManager sharedUserManager]
|
|
|
|
getUIDForEmail: originator];
|
2008-12-09 18:28:08 +01:00
|
|
|
emailEvent = [self component: NO secure: NO];
|
|
|
|
newEvent = [self component: NO secure: NO];
|
|
|
|
[[newEvent parent] setMethod: @""];
|
|
|
|
|
2008-07-05 00:25:27 +02:00
|
|
|
recipientsEnum = [recipients objectEnumerator];
|
|
|
|
while ((recipient = [recipientsEnum nextObject]))
|
2008-07-08 17:42:40 +02:00
|
|
|
if ([[recipient lowercaseString] hasPrefix: @"mailto:"])
|
|
|
|
{
|
2008-11-20 20:17:59 +01:00
|
|
|
person = [iCalPerson new];
|
2008-07-08 17:42:40 +02:00
|
|
|
[person setValue: 0 to: recipient];
|
|
|
|
uid = [person uid];
|
2008-11-18 21:59:08 +01:00
|
|
|
oldEvent = nil;
|
|
|
|
hasChanged = YES;
|
|
|
|
isUpdate = NO;
|
|
|
|
|
|
|
|
if (uid)
|
|
|
|
{
|
|
|
|
// We check if we must send an invitation update
|
2008-12-09 19:23:35 +01:00
|
|
|
// rather than just a normal invitation.
|
2008-12-19 03:40:24 +01:00
|
|
|
NSCalendarDate *recurrenceId;
|
2008-12-09 16:29:39 +01:00
|
|
|
NSString *iCalString;
|
2008-12-19 03:40:24 +01:00
|
|
|
SOGoAppointmentObject *oldEventObject, *ownerEventObject;
|
|
|
|
iCalCalendar *calendar;
|
2008-11-18 21:59:08 +01:00
|
|
|
|
2008-12-09 18:28:08 +01:00
|
|
|
oldEventObject = [self _lookupEvent: [newEvent uid] forUID: uid];
|
2008-12-19 03:40:24 +01:00
|
|
|
calendar = [oldEventObject calendar: NO secure: NO];
|
|
|
|
ownerEventObject = nil;
|
|
|
|
|
|
|
|
recurrenceId = [newEvent recurrenceId];
|
|
|
|
|
2008-12-09 16:29:39 +01:00
|
|
|
if (![oldEventObject isNew])
|
2008-11-18 21:59:08 +01:00
|
|
|
{
|
2008-12-09 16:29:39 +01:00
|
|
|
// We are updating an existing event.
|
|
|
|
// If the event containts a recurrence-id, replace the proper
|
|
|
|
// occurrence of the recurrent event.
|
|
|
|
iCalEvent *currentOccurence;
|
|
|
|
iCalEventChanges *changes;
|
|
|
|
NSArray *occurences;
|
2008-12-19 03:40:24 +01:00
|
|
|
NSCalendarDate *currentId;
|
2008-12-09 19:23:35 +01:00
|
|
|
NSString *recurrenceTime;
|
2008-12-09 16:29:39 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (recurrenceId == nil)
|
|
|
|
oldEvent = [oldEventObject component: NO secure: NO];
|
2008-11-18 21:59:08 +01:00
|
|
|
else
|
2008-12-09 16:29:39 +01:00
|
|
|
{
|
|
|
|
// If recurrenceId is defined, find the specified occurence
|
2008-12-09 19:23:35 +01:00
|
|
|
// within the repeating vEvent and remove it.
|
2008-12-09 16:29:39 +01:00
|
|
|
occurences = [calendar events];
|
2008-12-09 19:23:35 +01:00
|
|
|
for (i = 1; i < [occurences count]; i++)
|
2008-12-09 16:29:39 +01:00
|
|
|
{
|
|
|
|
currentOccurence = [occurences objectAtIndex: i];
|
|
|
|
currentId = [currentOccurence recurrenceId];
|
|
|
|
if ([currentId compare: recurrenceId] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
oldEvent = currentOccurence;
|
2008-12-09 18:28:08 +01:00
|
|
|
[[calendar children] removeObject: currentOccurence];
|
2008-12-09 16:29:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 19:23:35 +01:00
|
|
|
|
|
|
|
if (oldEvent == nil)
|
|
|
|
{
|
|
|
|
// If no occurence found, create one.
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]];
|
2009-04-01 15:49:24 +02:00
|
|
|
oldEvent = (iCalEvent *)[oldEventObject newOccurenceWithID: recurrenceTime];
|
2008-12-09 19:23:35 +01:00
|
|
|
}
|
|
|
|
|
2008-12-09 16:29:39 +01:00
|
|
|
// Add the event as a new occurrence, without the organizer.
|
2008-12-09 18:28:08 +01:00
|
|
|
[newEvent setOrganizer: nil];
|
|
|
|
[calendar addChild: newEvent];
|
2008-12-09 16:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identify changes in order to send a notification to the attendee
|
|
|
|
// if necessary and with the proper template.
|
2008-12-09 18:28:08 +01:00
|
|
|
changes = [newEvent getChangesRelativeToEvent: oldEvent];
|
2008-12-09 22:56:24 +01:00
|
|
|
if ([[oldEvent sequence] compare: [newEvent sequence]] != NSOrderedSame
|
2008-12-19 03:40:24 +01:00
|
|
|
&& [changes sequenceShouldBeIncreased])
|
2008-12-09 22:56:24 +01:00
|
|
|
isUpdate = YES;
|
|
|
|
else
|
|
|
|
hasChanged = NO;
|
2008-11-18 21:59:08 +01:00
|
|
|
}
|
2008-12-19 03:40:24 +01:00
|
|
|
else if (recurrenceId)
|
|
|
|
{
|
2008-12-19 20:49:07 +01:00
|
|
|
NSArray *attendees;
|
|
|
|
unsigned int i;
|
|
|
|
BOOL found;
|
|
|
|
|
|
|
|
// We must add an occurence to a non-existing event -- simply retrieve
|
2008-12-19 03:40:24 +01:00
|
|
|
// the event from the organizer's calendar
|
|
|
|
if (ownerEventObject == nil)
|
|
|
|
ownerEventObject = [self _lookupEvent: [newEvent uid] forUID: ownerUID];
|
2008-12-19 20:49:07 +01:00
|
|
|
|
2008-12-19 03:40:24 +01:00
|
|
|
newEvent = [ownerEventObject component: NO secure: NO];
|
2008-12-19 20:49:07 +01:00
|
|
|
attendees = [newEvent attendees];
|
|
|
|
found = NO;
|
|
|
|
|
|
|
|
// We check if the attendee that was added to a single occurence is
|
|
|
|
// present in the master component. If not, we add it with a participation
|
|
|
|
// status set to "DECLINED"
|
|
|
|
for (i = 0; i < [attendees count]; i++)
|
|
|
|
{
|
|
|
|
if ([[attendees objectAtIndex: i] hasSameEmailAddress: person])
|
|
|
|
{
|
|
|
|
found = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
[person setParticipationStatus: iCalPersonPartStatDeclined];
|
|
|
|
[person setRsvp: @"TRUE"];
|
|
|
|
[person setRole: @"REQ-PARTICIPANT"];
|
|
|
|
[newEvent addToAttendees: person];
|
|
|
|
[ownerEventObject saveContentString: [[newEvent parent] versitString]];
|
|
|
|
}
|
2008-12-19 03:40:24 +01:00
|
|
|
}
|
2008-12-09 16:29:39 +01:00
|
|
|
|
|
|
|
// We generate the updated iCalendar file and we save it
|
|
|
|
// in the database.
|
2008-12-09 18:28:08 +01:00
|
|
|
iCalString = [[newEvent parent] versitString];
|
2008-12-09 16:29:39 +01:00
|
|
|
[oldEventObject saveContentString: iCalString];
|
2008-11-18 21:59:08 +01:00
|
|
|
}
|
2008-07-05 00:25:27 +02:00
|
|
|
#warning fix this when sendEmailUsing blabla has been cleaned up
|
2008-11-18 21:59:08 +01:00
|
|
|
if (hasChanged)
|
2008-12-09 18:28:08 +01:00
|
|
|
{
|
|
|
|
[self sendEMailUsingTemplateNamed: (isUpdate ? @"Update" : @"Invitation")
|
|
|
|
forObject: emailEvent
|
|
|
|
previousObject: oldEvent
|
|
|
|
toAttendees: [NSArray arrayWithObject: person]];
|
|
|
|
}
|
|
|
|
|
2008-07-08 17:42:40 +02:00
|
|
|
[person release];
|
2008-07-09 17:43:48 +02:00
|
|
|
[elements
|
|
|
|
addObject: [self _caldavSuccessCodeWithRecipient: recipient]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2008-11-26 13:20:26 +01:00
|
|
|
//
|
|
|
|
// See our comment about the originator in the method above.
|
|
|
|
//
|
2008-07-09 17:43:48 +02:00
|
|
|
- (NSArray *) postCalDAVEventCancelTo: (NSArray *) recipients
|
2008-11-10 16:38:05 +01:00
|
|
|
from: (NSString *) originator
|
2008-07-09 17:43:48 +02:00
|
|
|
{
|
|
|
|
NSMutableArray *elements;
|
|
|
|
NSEnumerator *recipientsEnum;
|
2008-12-09 16:29:39 +01:00
|
|
|
NSString *recipient, *ownerUID, *uid;
|
2008-07-09 17:43:48 +02:00
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *person;
|
|
|
|
|
|
|
|
elements = [NSMutableArray array];
|
|
|
|
|
2008-12-09 16:29:39 +01:00
|
|
|
ownerUID = [[LDAPUserManager sharedUserManager]
|
|
|
|
getUIDForEmail: originator];
|
2008-07-09 17:43:48 +02:00
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
recipientsEnum = [recipients objectEnumerator];
|
|
|
|
while ((recipient = [recipientsEnum nextObject]))
|
|
|
|
if ([[recipient lowercaseString] hasPrefix: @"mailto:"])
|
|
|
|
{
|
|
|
|
person = [iCalPerson new];
|
|
|
|
[person setValue: 0 to: recipient];
|
|
|
|
uid = [person uid];
|
|
|
|
if (uid)
|
2008-11-26 13:20:26 +01:00
|
|
|
[self _removeEventFromUID: uid
|
2008-12-09 16:29:39 +01:00
|
|
|
owner: ownerUID
|
2008-12-04 00:08:37 +01:00
|
|
|
withRecurrenceId: [event recurrenceId]];
|
2008-07-09 17:43:48 +02:00
|
|
|
#warning fix this when sendEmailUsing blabla has been cleaned up
|
|
|
|
[self sendEMailUsingTemplateNamed: @"Deletion"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: event
|
2008-11-18 01:06:37 +01:00
|
|
|
previousObject: nil
|
2008-07-09 17:43:48 +02:00
|
|
|
toAttendees: [NSArray arrayWithObject: person]];
|
|
|
|
[person release];
|
|
|
|
[elements
|
|
|
|
addObject: [self _caldavSuccessCodeWithRecipient: recipient]];
|
2008-07-08 17:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2008-11-10 16:38:05 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// This method is invoked by CalDAV clients such as
|
|
|
|
// Mozilla Lightning. We assume the SENT-BY has
|
|
|
|
// already been added, if required.
|
|
|
|
//
|
2009-04-01 15:49:24 +02:00
|
|
|
// It is used to update the status of an attendee.
|
2008-11-10 16:38:05 +01:00
|
|
|
// The originator is the actualy owner of the calendar
|
|
|
|
// where the update took place. The status must then
|
|
|
|
// be propagated to the organizer and the other attendees.
|
|
|
|
//
|
2008-07-08 17:42:40 +02:00
|
|
|
- (void) takeAttendeeStatus: (iCalPerson *) attendee
|
2009-04-01 15:49:24 +02:00
|
|
|
from: (SOGoUser *) ownerUser
|
2008-12-09 16:29:39 +01:00
|
|
|
withRecurrenceId: (NSCalendarDate*) recurrenceId
|
2008-07-08 17:42:40 +02:00
|
|
|
{
|
|
|
|
iCalPerson *localAttendee;
|
|
|
|
iCalEvent *event;
|
2008-12-09 16:29:39 +01:00
|
|
|
NSString *recurrenceTime;
|
2008-07-08 17:42:40 +02:00
|
|
|
|
2008-12-09 16:29:39 +01:00
|
|
|
if (recurrenceId == nil)
|
|
|
|
// We must update the master event only.
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If recurrenceId is defined, find the specified occurence
|
|
|
|
// within the repeating vEvent.
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]];
|
2008-12-09 18:28:08 +01:00
|
|
|
event = (iCalEvent*)[self lookupOccurence: recurrenceTime];
|
2008-12-09 16:29:39 +01:00
|
|
|
|
|
|
|
if (event == nil)
|
|
|
|
// If no occurence found, create one
|
2008-12-09 18:28:08 +01:00
|
|
|
event = (iCalEvent*)[self newOccurenceWithID: recurrenceTime];
|
2008-12-09 16:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find attendee within event
|
2008-07-08 17:42:40 +02:00
|
|
|
localAttendee = [event findParticipantWithEmail: [attendee rfc822Email]];
|
|
|
|
if (localAttendee)
|
|
|
|
{
|
2008-12-09 16:29:39 +01:00
|
|
|
// Update the attendee's status
|
2008-07-08 17:42:40 +02:00
|
|
|
[localAttendee setPartStat: [attendee partStat]];
|
|
|
|
[self saveComponent: event];
|
2008-12-09 16:29:39 +01:00
|
|
|
|
|
|
|
NSArray *attendees;
|
|
|
|
iCalPerson *att;
|
|
|
|
NSString *uid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// We update the copy of the organizer, only
|
|
|
|
// if it's a local user.
|
2008-11-10 16:38:05 +01:00
|
|
|
#warning add a check for only local users
|
2008-12-09 16:29:39 +01:00
|
|
|
uid = [[event organizer] uid];
|
|
|
|
if (uid)
|
|
|
|
[self _updateAttendee: attendee
|
|
|
|
ownerUser: ownerUser
|
|
|
|
forEventUID: [event uid]
|
|
|
|
withRecurrenceId: [event recurrenceId]
|
|
|
|
withSequence: [event sequence]
|
|
|
|
forUID: uid
|
|
|
|
shouldAddSentBy: NO];
|
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
attendees = [event attendees];
|
|
|
|
|
|
|
|
for (i = 0; i < [attendees count]; i++)
|
|
|
|
{
|
|
|
|
att = [attendees objectAtIndex: i];
|
|
|
|
|
|
|
|
if (att == attendee) continue;
|
|
|
|
|
|
|
|
uid = [[LDAPUserManager sharedUserManager]
|
|
|
|
getUIDForEmail: [att rfc822Email]];
|
2008-12-09 16:29:39 +01:00
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
if (uid)
|
|
|
|
{
|
2008-12-09 16:29:39 +01:00
|
|
|
// We skip the update that correspond to the owner
|
2008-11-10 16:38:05 +01:00
|
|
|
// since the CalDAV client will already have updated
|
|
|
|
// the actual event.
|
|
|
|
if ([ownerUser hasEmail: [att rfc822Email]])
|
|
|
|
continue;
|
2008-12-09 16:29:39 +01:00
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
[self _updateAttendee: attendee
|
|
|
|
ownerUser: ownerUser
|
|
|
|
forEventUID: [event uid]
|
2008-11-22 08:20:22 +01:00
|
|
|
withRecurrenceId: [event recurrenceId]
|
2008-11-05 22:04:16 +01:00
|
|
|
withSequence: [event sequence]
|
|
|
|
forUID: uid
|
|
|
|
shouldAddSentBy: NO];
|
|
|
|
}
|
|
|
|
}
|
2008-07-05 00:25:27 +02:00
|
|
|
}
|
2008-07-08 17:42:40 +02:00
|
|
|
else
|
|
|
|
[self errorWithFormat: @"attendee not found: '%@'", attendee];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) postCalDAVEventReplyTo: (NSArray *) recipients
|
2008-11-10 16:38:05 +01:00
|
|
|
from: (NSString *) originator
|
2008-07-08 17:42:40 +02:00
|
|
|
{
|
2008-07-09 17:43:48 +02:00
|
|
|
NSMutableArray *elements;
|
2008-07-08 17:42:40 +02:00
|
|
|
NSEnumerator *recipientsEnum;
|
|
|
|
NSString *recipient, *uid, *eventUID;
|
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *attendee, *person;
|
|
|
|
SOGoAppointmentObject *recipientEvent;
|
|
|
|
SOGoUser *ownerUser;
|
|
|
|
|
|
|
|
elements = [NSMutableArray array];
|
|
|
|
event = [self component: NO secure: NO];
|
2008-12-09 23:51:01 +01:00
|
|
|
[[event parent] setMethod: @""];
|
2008-11-10 16:38:05 +01:00
|
|
|
ownerUser = [SOGoUser userWithLogin: [[LDAPUserManager sharedUserManager]
|
|
|
|
getUIDForEmail: originator]
|
|
|
|
roles: nil];
|
2008-07-08 17:42:40 +02:00
|
|
|
attendee = [event findParticipant: ownerUser];
|
|
|
|
eventUID = [event uid];
|
|
|
|
|
|
|
|
recipientsEnum = [recipients objectEnumerator];
|
|
|
|
while ((recipient = [recipientsEnum nextObject]))
|
|
|
|
if ([[recipient lowercaseString] hasPrefix: @"mailto:"])
|
|
|
|
{
|
|
|
|
person = [iCalPerson new];
|
|
|
|
[person setValue: 0 to: recipient];
|
|
|
|
uid = [person uid];
|
|
|
|
if (uid)
|
|
|
|
{
|
|
|
|
recipientEvent = [self _lookupEvent: eventUID forUID: uid];
|
|
|
|
if ([recipientEvent isNew])
|
|
|
|
[recipientEvent saveComponent: event];
|
|
|
|
else
|
2008-11-10 16:38:05 +01:00
|
|
|
[recipientEvent takeAttendeeStatus: attendee
|
2008-12-09 16:29:39 +01:00
|
|
|
from: ownerUser
|
|
|
|
withRecurrenceId: [event recurrenceId]];
|
2008-07-08 17:42:40 +02:00
|
|
|
}
|
2008-12-09 16:29:39 +01:00
|
|
|
|
|
|
|
// Send reply to recipient/organizer
|
2008-11-10 16:38:05 +01:00
|
|
|
[self sendIMIPReplyForEvent: event
|
|
|
|
from: ownerUser
|
|
|
|
to: person];
|
2008-07-08 17:42:40 +02:00
|
|
|
[person release];
|
2008-07-09 17:43:48 +02:00
|
|
|
[elements
|
|
|
|
addObject: [self _caldavSuccessCodeWithRecipient: recipient]];
|
2008-07-08 17:42:40 +02:00
|
|
|
}
|
2008-07-05 00:25:27 +02:00
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2008-11-10 16:38:05 +01:00
|
|
|
//
|
|
|
|
// This method is invoked only from the SOGo Web interface.
|
|
|
|
//
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSException *) changeParticipationStatus: (NSString *) _status
|
|
|
|
{
|
2008-11-22 08:20:22 +01:00
|
|
|
return [self changeParticipationStatus: _status forRecurrenceId: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *) changeParticipationStatus: (NSString *) _status forRecurrenceId: (NSCalendarDate *) _recurrenceId
|
|
|
|
{
|
|
|
|
iCalCalendar *calendar;
|
2007-11-18 11:16:25 +01:00
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *attendee;
|
|
|
|
NSException *ex;
|
2007-12-06 23:54:01 +01:00
|
|
|
SOGoUser *ownerUser;
|
2008-11-22 08:20:22 +01:00
|
|
|
NSString *recurrenceTime;
|
2008-08-09 17:21:25 +02:00
|
|
|
|
2008-11-22 08:20:22 +01:00
|
|
|
event = nil;
|
2007-11-18 11:16:25 +01:00
|
|
|
ex = nil;
|
|
|
|
|
2008-11-22 08:20:22 +01:00
|
|
|
calendar = [self calendar: NO secure: NO];
|
|
|
|
if (calendar)
|
|
|
|
{
|
|
|
|
if (_recurrenceId)
|
|
|
|
{
|
|
|
|
// If _recurrenceId is defined, find the specified occurence
|
|
|
|
// within the repeating vEvent.
|
|
|
|
recurrenceTime = [NSString stringWithFormat: @"%f", [_recurrenceId timeIntervalSince1970]];
|
2008-12-03 17:18:12 +01:00
|
|
|
event = (iCalEvent*)[self lookupOccurence: recurrenceTime];
|
2008-12-01 17:24:15 +01:00
|
|
|
|
|
|
|
if (event == nil)
|
|
|
|
// If no occurence found, create one
|
2008-12-03 17:18:12 +01:00
|
|
|
event = (iCalEvent*)[self newOccurenceWithID: recurrenceTime];
|
2008-11-22 08:20:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// No specific occurence specified; return the first vEvent of
|
|
|
|
// the vCalendar.
|
2008-12-03 17:18:12 +01:00
|
|
|
event = (iCalEvent*)[calendar firstChildWithTag: [self componentTag]];
|
2008-11-22 08:20:22 +01:00
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
if (event)
|
|
|
|
{
|
2008-11-10 16:38:05 +01:00
|
|
|
// owerUser will actually be the owner of the calendar
|
|
|
|
// where the participation change on the event has
|
|
|
|
// actually occured. The particpation change will of
|
|
|
|
// course be on the attendee that is the owner of the
|
|
|
|
// calendar where the participation change has occured.
|
2007-12-06 23:54:01 +01:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
2008-11-22 08:20:22 +01:00
|
|
|
|
2007-12-06 23:54:01 +01:00
|
|
|
attendee = [event findParticipant: ownerUser];
|
2007-11-18 11:16:25 +01:00
|
|
|
if (attendee)
|
2008-11-05 22:04:16 +01:00
|
|
|
ex = [self _handleAttendee: attendee
|
|
|
|
ownerUser: ownerUser
|
|
|
|
statusChange: _status
|
2007-11-18 11:16:25 +01:00
|
|
|
inEvent: event];
|
|
|
|
else
|
2008-11-22 08:20:22 +01:00
|
|
|
ex = [NSException exceptionWithHTTPStatus: 404 // Not Found
|
2007-11-18 11:16:25 +01:00
|
|
|
reason: @"user does not participate in this "
|
|
|
|
@"calendar event"];
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
|
|
|
else
|
2008-11-22 08:20:22 +01:00
|
|
|
ex = [NSException exceptionWithHTTPStatus: 500 // Server Error
|
2007-11-18 11:16:25 +01:00
|
|
|
reason: @"unable to parse event record"];
|
2008-11-22 08:20:22 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
return ex;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
- (void) prepareDeleteOccurence: (iCalEvent *) occurence
|
2007-01-31 21:15:28 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
iCalEvent *event;
|
2008-08-14 00:30:55 +02:00
|
|
|
SOGoUser *ownerUser, *currentUser;
|
2007-11-18 11:16:25 +01:00
|
|
|
NSArray *attendees;
|
2008-12-01 22:15:07 +01:00
|
|
|
NSCalendarDate *recurrenceId;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
if ([[context request] handledByDefaultHandler])
|
|
|
|
{
|
2008-08-14 00:30:55 +02:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
2007-11-18 11:16:25 +01:00
|
|
|
event = [self component: NO secure: NO];
|
2008-12-01 22:15:07 +01:00
|
|
|
|
|
|
|
if (occurence == nil)
|
|
|
|
{
|
|
|
|
// No occurence specified; use the master event.
|
|
|
|
occurence = event;
|
|
|
|
recurrenceId = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// Retrieve this occurence ID.
|
|
|
|
recurrenceId = [occurence recurrenceId];
|
|
|
|
|
2008-08-14 00:30:55 +02:00
|
|
|
if ([event userIsOrganizer: ownerUser])
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
2008-12-01 22:15:07 +01:00
|
|
|
// The organizer deletes an occurence.
|
|
|
|
currentUser = [context activeUser];
|
2008-07-17 23:12:43 +02:00
|
|
|
attendees = [occurence attendeesWithoutUser: currentUser];
|
2008-12-04 00:08:37 +01:00
|
|
|
|
|
|
|
#warning Make sure this is correct ..
|
2008-07-17 23:12:43 +02:00
|
|
|
if (![attendees count] && event != occurence)
|
|
|
|
attendees = [event attendeesWithoutUser: currentUser];
|
2008-12-04 00:08:37 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if ([attendees count])
|
|
|
|
{
|
2008-12-01 22:15:07 +01:00
|
|
|
// Remove the event from all attendees calendars
|
|
|
|
// and send them an email.
|
2008-12-04 00:08:37 +01:00
|
|
|
[self _handleRemovedUsers: attendees
|
|
|
|
withRecurrenceId: recurrenceId];
|
2007-11-18 11:16:25 +01:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Deletion"
|
2008-10-01 21:32:14 +02:00
|
|
|
forObject: [occurence itipEntryWithMethod: @"cancel"]
|
2008-11-18 01:06:37 +01:00
|
|
|
previousObject: nil
|
2007-11-18 11:16:25 +01:00
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
|
|
|
}
|
2008-08-14 00:30:55 +02:00
|
|
|
else if ([occurence userIsParticipant: ownerUser])
|
2008-12-01 22:15:07 +01:00
|
|
|
// The current user deletes the occurence; let the organizer know that
|
|
|
|
// the user has declined this occurence.
|
|
|
|
[self changeParticipationStatus: @"DECLINED" forRecurrenceId: recurrenceId];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-31 19:54:56 +01:00
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
- (void) prepareDelete
|
|
|
|
{
|
|
|
|
[self prepareDeleteOccurence: nil];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* message type */
|
|
|
|
|
2007-01-31 21:15:28 +01:00
|
|
|
- (NSString *) outlookMessageClass
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"IPM.Appointment";
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoAppointmentObject */
|