2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
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
|
|
|
|
2006-10-11 20:58:16 +02:00
|
|
|
#import "NSArray+Appointments.h"
|
2007-09-15 00:01:02 +02:00
|
|
|
#import "SOGoAppointmentFolder.h"
|
2007-11-18 11:16:25 +01:00
|
|
|
#import "iCalEventChanges+SOGo.h"
|
|
|
|
#import "iCalEntityObject+SOGo.h"
|
|
|
|
#import "iCalPerson+SOGo.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
|
|
|
|
{
|
|
|
|
SOGoWebDAVAclManager *webdavAclManager = nil;
|
|
|
|
NSString *nsD, *nsI;
|
|
|
|
|
|
|
|
if (!webdavAclManager)
|
|
|
|
{
|
|
|
|
nsD = @"DAV:";
|
|
|
|
nsI = @"urn:inverse:params:xml:ns:inverse-dav";
|
|
|
|
|
|
|
|
// extern NSString *SOGoCalendarPerm_ViewAllComponent;
|
|
|
|
// extern NSString *SOGoCalendarPerm_ViewDAndT;
|
|
|
|
// extern NSString *SOGoCalendarPerm_ModifyComponent;
|
|
|
|
// extern NSString *SOGoCalendarPerm_RespondToComponent;
|
|
|
|
|
|
|
|
webdavAclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"read", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"read-current-user-privilege-set", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"read", nsD)];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"view-whole-component", nsI)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SOGoCalendarPerm_ViewAllComponent
|
|
|
|
asChildOf: davElement (@"read", nsD)];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"view-date-and-time", nsI)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SOGoCalendarPerm_ViewDAndT
|
|
|
|
asChildOf: davElement (@"view-whole-component", nsI)];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"write", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[webdavAclManager
|
|
|
|
registerDAVPermission: davElement (@"write-properties", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions /* hackish */
|
|
|
|
asChildOf: davElement (@"write", nsD)];
|
|
|
|
[webdavAclManager
|
|
|
|
registerDAVPermission: davElement (@"write-content", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoCalendarPerm_ModifyComponent
|
|
|
|
asChildOf: davElement (@"write", nsD)];
|
|
|
|
[webdavAclManager
|
|
|
|
registerDAVPermission: davElement (@"respond-to-component", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoCalendarPerm_RespondToComponent
|
|
|
|
asChildOf: davElement (@"write-content", nsD)];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"admin", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", nsD)];
|
|
|
|
[webdavAclManager
|
|
|
|
registerDAVPermission: davElement (@"read-acl", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoPerm_ReadAcls
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
[webdavAclManager
|
|
|
|
registerDAVPermission: davElement (@"write-acl", nsD)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return webdavAclManager;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
NSString *possibleName;
|
|
|
|
|
|
|
|
folder = [container lookupCalendarFolderForUID: uid];
|
|
|
|
object = [folder lookupName: nameInContainer
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if ([object isKindOfClass: [NSException class]])
|
2007-02-15 21:59:02 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
possibleName = [folder resourceNameForEventUID: eventUID];
|
|
|
|
if (possibleName)
|
|
|
|
{
|
|
|
|
object = [folder lookupName: nameInContainer
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if ([object isKindOfClass: [NSException class]])
|
|
|
|
object = nil;
|
|
|
|
}
|
2007-11-20 15:47:05 +01:00
|
|
|
else
|
|
|
|
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)
|
|
|
|
object = [SOGoAppointmentObject objectWithName: nameInContainer
|
|
|
|
inContainer: folder];
|
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
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _addOrUpdateEvent: (iCalEvent *) event
|
|
|
|
forUID: (NSString *) uid
|
2007-08-24 00:11:19 +02:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentObject *object;
|
|
|
|
NSString *iCalString, *userLogin;
|
|
|
|
|
|
|
|
userLogin = [[context activeUser] login];
|
|
|
|
if (![uid isEqualToString: userLogin])
|
2007-11-08 00:35:26 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
object = [self _lookupEvent: [event uid] forUID: uid];
|
|
|
|
iCalString = [[event parent] versitString];
|
|
|
|
[object saveContentString: iCalString];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
2007-01-31 21:15:28 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _removeEventFromUID: (NSString *) uid
|
2007-11-07 16:58:43 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
SOGoAppointmentObject *object;
|
|
|
|
NSString *userLogin;
|
|
|
|
|
|
|
|
userLogin = [[context activeUser] login];
|
|
|
|
if (![uid isEqualToString: userLogin])
|
2007-11-07 16:58:43 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
folder = [container lookupCalendarFolderForUID: uid];
|
|
|
|
object = [folder lookupName: nameInContainer
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if (![object isKindOfClass: [NSException class]])
|
|
|
|
[object delete];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _handleRemovedUsers: (NSArray *) attendees
|
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)
|
|
|
|
[self _removeEventFromUID: currentUID];
|
|
|
|
}
|
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
|
|
|
|
forUID: currentUID];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Update"
|
|
|
|
forOldObject: oldEvent
|
|
|
|
andNewObject: [newEvent itipEntryWithMethod: @"request"]
|
|
|
|
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
|
|
|
|
forUID: currentUID];
|
|
|
|
}
|
|
|
|
}
|
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])
|
|
|
|
{
|
|
|
|
[self _handleRemovedUsers: attendees];
|
|
|
|
[self sendEMailUsingTemplateNamed: @"Deletion"
|
|
|
|
forOldObject: oldEvent
|
|
|
|
andNewObject: [newEvent itipEntryWithMethod: @"cancel"]
|
|
|
|
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];
|
|
|
|
[self _requireResponseFromAttendees: [newEvent attendees]];
|
|
|
|
[self _handleSequenceUpdateInEvent: newEvent
|
|
|
|
ignoringAttendees: attendees
|
|
|
|
fromOldEvent: oldEvent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self _requireResponseFromAttendees: attendees];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if ([attendees count])
|
|
|
|
{
|
|
|
|
[self _handleAddedUsers: attendees fromEvent: newEvent];
|
|
|
|
[self sendEMailUsingTemplateNamed: @"Invitation"
|
|
|
|
forOldObject: oldEvent
|
|
|
|
andNewObject: [newEvent itipEntryWithMethod: @"request"]
|
|
|
|
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;
|
2007-11-19 22:07:54 +01:00
|
|
|
SOGoUser *currentUser;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[[newEvent parent] setMethod: @""];
|
2007-11-19 22:07:54 +01:00
|
|
|
currentUser = [context activeUser];
|
|
|
|
if ([newEvent userIsOrganizer: currentUser])
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
|
|
|
oldEvent = [self component: NO secure: NO];
|
|
|
|
if (oldEvent)
|
|
|
|
[self _handleUpdatedEvent: newEvent fromOldEvent: oldEvent];
|
|
|
|
else
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
attendees = [newEvent attendeesWithoutUser: [context activeUser]];
|
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"
|
2007-11-08 20:56:18 +01:00
|
|
|
forOldObject: nil
|
2007-11-18 11:16:25 +01:00
|
|
|
andNewObject: [newEvent itipEntryWithMethod: @"request"]
|
2007-11-08 20:56:18 +01:00
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2007-11-19 22:07:54 +01:00
|
|
|
if (![[newEvent attendees] count]
|
|
|
|
&& [[self ownerInContext: context]
|
|
|
|
isEqualToString: [currentUser login]])
|
2007-11-18 11:16:25 +01:00
|
|
|
[[newEvent uniqueChildWithTag: @"organizer"] setValue: 0
|
|
|
|
to: @""];
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
2007-01-31 21:15:28 +01:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[super saveComponent: newEvent];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSException *) _updateAttendee: (iCalPerson *) attendee
|
|
|
|
forEventUID: (NSString *) eventUID
|
|
|
|
withSequence: (NSNumber *) sequence
|
|
|
|
forUID: (NSString *) uid
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentObject *eventObject;
|
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *otherAttendee;
|
|
|
|
NSString *iCalString;
|
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
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
event = [eventObject component: NO secure: NO];
|
|
|
|
if ([[event sequence] compare: sequence]
|
|
|
|
== NSOrderedSame)
|
|
|
|
{
|
|
|
|
otherAttendee = [event findParticipant: [context activeUser]];
|
|
|
|
[otherAttendee setPartStat: [attendee partStat]];
|
|
|
|
iCalString = [[event parent] versitString];
|
|
|
|
error = [eventObject saveContentString: iCalString];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *) _handleAttendee: (iCalPerson *) attendee
|
|
|
|
statusChange: (NSString *) newStatus
|
|
|
|
inEvent: (iCalEvent *) event
|
|
|
|
{
|
|
|
|
NSString *newContent, *currentStatus, *organizerUID;
|
|
|
|
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];
|
|
|
|
newContent = [[event parent] versitString];
|
|
|
|
ex = [self saveContentString: newContent];
|
|
|
|
if (!(ex || [event userIsOrganizer: [context activeUser]]))
|
2007-11-08 20:56:18 +01:00
|
|
|
{
|
2007-11-20 15:47:05 +01:00
|
|
|
if ([[attendee rsvp] isEqualToString: @"true"]
|
|
|
|
&& [event isStillRelevant])
|
2007-11-18 11:16:25 +01:00
|
|
|
[self sendResponseToOrganizer];
|
|
|
|
organizerUID = [[event organizer] uid];
|
|
|
|
if (organizerUID)
|
|
|
|
ex = [self _updateAttendee: attendee
|
|
|
|
forEventUID: [event uid]
|
|
|
|
withSequence: [event sequence]
|
|
|
|
forUID: organizerUID];
|
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-05 00:25:27 +02:00
|
|
|
- (NSArray *) postCalDAVEventRequestTo: (NSArray *) recipients
|
|
|
|
{
|
|
|
|
NSMutableArray *elements, *element;
|
|
|
|
NSEnumerator *recipientsEnum;
|
|
|
|
NSString *recipient, *uid;
|
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *person;
|
|
|
|
|
|
|
|
elements = [NSMutableArray array];
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
recipientsEnum = [recipients objectEnumerator];
|
|
|
|
while ((recipient = [recipientsEnum nextObject]))
|
2008-07-08 17:42:40 +02:00
|
|
|
if ([[recipient lowercaseString] hasPrefix: @"mailto:"])
|
|
|
|
{
|
|
|
|
person = [iCalPerson new];
|
|
|
|
[person setValue: 0 to: recipient];
|
|
|
|
uid = [person uid];
|
|
|
|
if (uid)
|
|
|
|
[self _addOrUpdateEvent: event forUID: uid];
|
2008-07-05 00:25:27 +02:00
|
|
|
#warning fix this when sendEmailUsing blabla has been cleaned up
|
2008-07-08 17:42:40 +02:00
|
|
|
[self sendEMailUsingTemplateNamed: @"Invitation"
|
|
|
|
forOldObject: nil andNewObject: event
|
|
|
|
toAttendees: [NSArray arrayWithObject: person]];
|
|
|
|
[person release];
|
|
|
|
element = [NSMutableArray new];
|
|
|
|
[element addObject: davElementWithContent (@"recipient", XMLNS_CALDAV,
|
|
|
|
recipient)];
|
|
|
|
[element addObject: davElementWithContent (@"request-status",
|
|
|
|
XMLNS_CALDAV,
|
|
|
|
@"2.0;Success")];
|
|
|
|
[elements addObject: davElementWithContent (@"response", XMLNS_CALDAV,
|
|
|
|
element)];
|
|
|
|
[element release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) takeAttendeeStatus: (iCalPerson *) attendee
|
|
|
|
{
|
|
|
|
iCalPerson *localAttendee;
|
|
|
|
iCalEvent *event;
|
|
|
|
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
localAttendee = [event findParticipantWithEmail: [attendee rfc822Email]];
|
|
|
|
if (localAttendee)
|
|
|
|
{
|
|
|
|
[localAttendee setPartStat: [attendee partStat]];
|
|
|
|
[self saveComponent: event];
|
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
|
|
|
|
{
|
|
|
|
NSMutableArray *elements, *element;
|
|
|
|
NSEnumerator *recipientsEnum;
|
|
|
|
NSString *recipient, *uid, *eventUID;
|
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *attendee, *person;
|
|
|
|
SOGoAppointmentObject *recipientEvent;
|
|
|
|
SOGoUser *ownerUser;
|
|
|
|
|
|
|
|
elements = [NSMutableArray array];
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
|
|
|
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
|
|
|
|
[recipientEvent takeAttendeeStatus: attendee];
|
|
|
|
}
|
|
|
|
#warning fix this when sendEmailUsing blabla has been cleaned up
|
|
|
|
[self sendEMailUsingTemplateNamed: @"ICalReply"
|
|
|
|
forOldObject: nil andNewObject: event
|
|
|
|
toAttendees: [NSArray arrayWithObject: person]];
|
|
|
|
[person release];
|
|
|
|
element = [NSMutableArray new];
|
|
|
|
[element addObject: davElementWithContent (@"recipient", XMLNS_CALDAV,
|
|
|
|
recipient)];
|
|
|
|
[element addObject: davElementWithContent (@"request-status",
|
|
|
|
XMLNS_CALDAV,
|
|
|
|
@"2.0;Success")];
|
|
|
|
[elements addObject: davElementWithContent (@"response", XMLNS_CALDAV,
|
|
|
|
element)];
|
|
|
|
[element release];
|
|
|
|
}
|
2008-07-05 00:25:27 +02:00
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (NSException *) changeParticipationStatus: (NSString *) _status
|
|
|
|
{
|
|
|
|
iCalEvent *event;
|
|
|
|
iCalPerson *attendee;
|
|
|
|
NSException *ex;
|
2007-12-06 23:54:01 +01:00
|
|
|
SOGoUser *ownerUser;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
ex = nil;
|
|
|
|
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
if (event)
|
|
|
|
{
|
2007-12-06 23:54:01 +01:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner roles: nil];
|
|
|
|
attendee = [event findParticipant: ownerUser];
|
2007-11-18 11:16:25 +01:00
|
|
|
if (attendee)
|
|
|
|
ex = [self _handleAttendee: attendee statusChange: _status
|
|
|
|
inEvent: event];
|
|
|
|
else
|
|
|
|
ex = [NSException exceptionWithHTTPStatus: 404 /* Not Found */
|
|
|
|
reason: @"user does not participate in this "
|
|
|
|
@"calendar event"];
|
2007-11-08 20:56:18 +01:00
|
|
|
}
|
|
|
|
else
|
2007-11-18 11:16:25 +01:00
|
|
|
ex = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
|
|
|
|
reason: @"unable to parse event record"];
|
2007-01-31 21:15:28 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
return ex;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) prepareDelete
|
2007-01-31 21:15:28 +01:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
iCalEvent *event;
|
|
|
|
SOGoUser *currentUser;
|
|
|
|
NSArray *attendees;
|
|
|
|
|
|
|
|
if ([[context request] handledByDefaultHandler])
|
|
|
|
{
|
|
|
|
currentUser = [context activeUser];
|
|
|
|
event = [self component: NO secure: NO];
|
|
|
|
if ([event userIsOrganizer: currentUser])
|
|
|
|
{
|
|
|
|
attendees = [event attendeesWithoutUser: currentUser];
|
|
|
|
if ([attendees count])
|
|
|
|
{
|
|
|
|
[self _handleRemovedUsers: attendees];
|
|
|
|
[self sendEMailUsingTemplateNamed: @"Deletion"
|
|
|
|
forOldObject: nil
|
|
|
|
andNewObject: [event itipEntryWithMethod: @"cancel"]
|
|
|
|
toAttendees: attendees];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([event userIsParticipant: currentUser])
|
|
|
|
[self changeParticipationStatus: @"DECLINED"];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-10-31 19:54:56 +01:00
|
|
|
|
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 */
|