/
SOGoAppointmentFolder.m
3799 lines (3256 loc) · 123 KB
/
SOGoAppointmentFolder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2007-2019 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
SOGo 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.
SOGo 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.
*/
#import <Foundation/NSCalendarDate.h>
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/SoObject+SoDAV.h>
#import <NGObjWeb/WOApplication.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGExtensions/NSString+misc.h>
#import <GDLContentStore/GCSFolder.h>
#import <EOControl/EOQualifier.h>
#import <NGCards/iCalAlarm.h>
#import <NGCards/iCalFreeBusy.h>
#import <NGCards/iCalDateTime.h>
#import <NGCards/iCalRecurrenceCalculator.h>
#import <NGCards/iCalTimeZone.h>
#import <NGCards/iCalTimeZonePeriod.h>
#import <NGCards/iCalToDo.h>
#import <NGCards/NSString+NGCards.h>
#import <NGExtensions/NSCalendarDate+misc.h>
#import <NGExtensions/NGCalendarDateRange.h>
#import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSObject+Logs.h>
#import <SaxObjC/XMLNamespaces.h>
#import <SOGo/DOMNode+SOGo.h>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSObject+DAV.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoBuild.h>
#import <SOGo/SOGoCache.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoGroup.h>
#import <SOGo/SOGoPermissions.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoWebDAVAclManager.h>
#import <SOGo/SOGoWebDAVValue.h>
#import <SOGo/WORequest+SOGo.h>
#import <SOGo/WOResponse+SOGo.h>
#import <SOGo/SOGoSource.h>
#import "iCalCalendar+SOGo.h"
#import "iCalRepeatableEntityObject+SOGo.h"
#import "iCalEvent+SOGo.h"
#import "iCalPerson+SOGo.h"
#import "SOGoAppointmentObject.h"
#import "SOGoAppointmentFolders.h"
#import "SOGoFreeBusyObject.h"
#import "SOGoTaskObject.h"
#import "SOGoWebAppointmentFolder.h"
#define defaultColor @"#AAAAAA"
@interface SOGoGCSFolder (SOGoPrivate)
- (void) appendObject: (NSDictionary *) object
properties: (NSString **) properties
count: (unsigned int) propertiesCount
withBaseURL: (NSString *) baseURL
toBuffer: (NSMutableString *) r;
@end
@implementation SOGoAppointmentFolder
static NSNumber *sharedYes = nil;
static Class iCalEventK = nil;
+ (void) initialize
{
static BOOL didInit = NO;
if (!didInit)
{
didInit = YES;
sharedYes = [[NSNumber numberWithBool: YES] retain];
[iCalEntityObject initializeSOGoExtensions];
iCalEventK = [iCalEvent class];
}
}
+ (SOGoWebDAVAclManager *) webdavAclManager
{
static SOGoWebDAVAclManager *aclManager = nil;
NSString *nsI;
if (!aclManager)
{
nsI = @"urn:inverse:params:xml:ns:inverse-dav";
aclManager = [SOGoWebDAVAclManager new];
[aclManager registerDAVPermission: davElement (@"read", XMLNS_WEBDAV)
abstract: YES
withEquivalent: SoPerm_WebDAVAccess
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
[aclManager
registerDAVPermission: davElement (@"read-current-user-privilege-set", XMLNS_WEBDAV)
abstract: YES
withEquivalent: SoPerm_WebDAVAccess
asChildOf: davElement (@"read", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"read-free-busy", XMLNS_CALDAV)
abstract: NO
withEquivalent: SOGoCalendarPerm_ReadFreeBusy
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"write", XMLNS_WEBDAV)
abstract: YES
withEquivalent: nil
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"bind", XMLNS_WEBDAV)
abstract: NO
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"schedule",
XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"bind", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"schedule-post",
XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-post-vevent", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-post-vtodo", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-post-vjournal", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-post-vfreebusy", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
[aclManager registerDAVPermission: davElement (@"schedule-deliver",
XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-deliver-vevent", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-deliver-vtodo", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-deliver-vjournal", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-deliver-vfreebusy", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
[aclManager registerDAVPermission: davElement (@"schedule-respond",
XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-respond-vevent", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-respond", XMLNS_CALDAV)];
[aclManager registerDAVPermission:
davElement (@"schedule-respond-vtodo", XMLNS_CALDAV)
abstract: NO
withEquivalent: nil
asChildOf: davElement (@"schedule-respond", XMLNS_CALDAV)];
[aclManager registerDAVPermission: davElement (@"unbind", XMLNS_WEBDAV)
abstract: NO
withEquivalent: SoPerm_DeleteObjects
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
[aclManager
registerDAVPermission: davElement (@"write-properties", XMLNS_WEBDAV)
abstract: NO
withEquivalent: SoPerm_ChangePermissions /* hackish */
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
[aclManager
registerDAVPermission: davElement (@"write-content", XMLNS_WEBDAV)
abstract: NO
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
/* read-acl and write-acl are defined in RFC3744 */
[aclManager registerDAVPermission: davElement (@"admin", nsI)
abstract: YES
withEquivalent: nil
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
[aclManager registerDAVPermission: davElement (@"read-acl", XMLNS_WEBDAV)
abstract: YES
withEquivalent: SOGoPerm_ReadAcls
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"write-acl", XMLNS_WEBDAV)
abstract: YES
withEquivalent: SoPerm_ChangePermissions
asChildOf: davElement (@"admin", nsI)];
/* Default permissions for calendars. These are very important so that DAV client can
detect permission changes on calendars and reload all items, if necessary */
/* Public ones */
[aclManager registerDAVPermission: davElement (@"viewwhole-public-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewWholePublicRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"viewdant-public-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewDAndTOfPublicRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"modify-public-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ModifyPublicRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"respondto-public-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_RespondToPublicRecords
asChildOf: davElement (@"admin", nsI)];
/* Private ones */
[aclManager registerDAVPermission: davElement (@"viewwhole-private-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewWholePrivateRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"viewdant-private-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewDAndTOfPrivateRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"modify-private-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ModifyPrivateRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"respondto-private-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_RespondToPrivateRecords
asChildOf: davElement (@"admin", nsI)];
/* Condifential ones */
[aclManager registerDAVPermission: davElement (@"viewwhole-confidential-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewWholeConfidentialRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"viewdant-confidential-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ViewDAndTOfConfidentialRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"modify-confidential-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_ModifyConfidentialRecords
asChildOf: davElement (@"admin", nsI)];
[aclManager registerDAVPermission: davElement (@"respondto-confidential-records", nsI)
abstract: YES
withEquivalent: SOGoCalendarPerm_RespondToConfidentialRecords
asChildOf: davElement (@"admin", nsI)];
}
return aclManager;
}
- (id) initWithName: (NSString *) name
inContainer: (id) newContainer
{
SOGoUser *user;
if ((self = [super initWithName: name inContainer: newContainer]))
{
user = [context activeUser];
timeZone = [[user userDefaults] timeZone];
aclMatrix = [NSMutableDictionary new];
stripFields = nil;
uidToFilename = nil;
memset (userCanAccessObjectsClassifiedAs, NO,
iCalAccessClassCount * sizeof (BOOL));
davCalendarStartTimeLimit = [[user domainDefaults] davCalendarStartTimeLimit];
davTimeLimitSeconds = davCalendarStartTimeLimit * 86400;
/* 86400 / 2 = 43200. We hardcode that value in order to avoid
integer and float confusion. */
davTimeHalfLimitSeconds = davCalendarStartTimeLimit * 43200;
componentSet = nil;
baseCalDAVURL = nil;
basePublicCalDAVURL = nil;
}
return self;
}
- (void) dealloc
{
[aclMatrix release];
[stripFields release];
[uidToFilename release];
[componentSet release];
[baseCalDAVURL release];
[basePublicCalDAVURL release];
[super dealloc];
}
- (Class) objectClassForComponentName: (NSString *) componentName
{
Class objectClass;
if ([componentName isEqualToString: @"vevent"])
objectClass = [SOGoAppointmentObject class];
else if ([componentName isEqualToString: @"vtodo"])
objectClass = [SOGoTaskObject class];
else
objectClass = Nil;
return objectClass;
}
- (NSString *) calendarColor
{
NSString *color;
color = [self folderPropertyValueInCategory: @"FolderColors"];
if (!color)
color = defaultColor;
return color;
}
- (void) setCalendarColor: (NSString *) newColor
{
if (![newColor length])
newColor = nil;
[self setFolderPropertyValue: newColor
inCategory: @"FolderColors"];
}
- (BOOL) showCalendarAlarms
{
NSNumber *showAlarms;
showAlarms = [self folderPropertyValueInCategory: @"FolderShowAlarms"];
return (showAlarms ? [showAlarms boolValue] : YES);
}
- (void) setShowCalendarAlarms: (BOOL) new
{
NSNumber *showAlarms;
if (new)
showAlarms = nil;
else
showAlarms = [NSNumber numberWithBool: NO];
[self setFolderPropertyValue: showAlarms
inCategory: @"FolderShowAlarms"];
}
- (BOOL) showCalendarTasks
{
NSNumber *showTasks;
showTasks = [self folderPropertyValueInCategory: @"FolderShowTasks"];
return (showTasks ? [showTasks boolValue] : YES);
}
- (void) setShowCalendarTasks: (BOOL) new
{
NSNumber *showTasks;
/* the default value is "YES", so we keep only those with a value of "NO"... */
if (new)
showTasks = nil;
else
showTasks = [NSNumber numberWithBool: NO];
[self setFolderPropertyValue: showTasks
inCategory: @"FolderShowTasks"];
}
- (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier
reallyDo: (BOOL) reallyDo
response: (WOResponse *) theResponse
{
NSMutableDictionary *moduleSettings, *folderShowAlarms, *freeBusyExclusions;
NSString *subscriptionPointer, *domain;
NSMutableArray *allUsers;
SOGoUserSettings *us;
NSDictionary *dict;
SOGoUser *sogoUser;
BOOL rc;
int i;
rc = [super subscribeUserOrGroup: theIdentifier reallyDo: reallyDo response: theResponse];
if (rc)
{
#warning Duplicated code from SOGoGCSFolder subscribeUserOrGroup
domain = [[context activeUser] domain];
dict = [[SOGoUserManager sharedUserManager] contactInfosForUserWithUIDorEmail: theIdentifier
inDomain: domain];
if (dict && [[dict objectForKey: @"isGroup"] boolValue])
{
id <SOGoSource> source;
source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]];
if ([source conformsToProtocol:@protocol(SOGoMembershipSource)])
{
NSArray *members = [(id<SOGoMembershipSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]];
allUsers = [NSMutableArray array];
for (i = 0; i < [members count]; i++)
{
[allUsers addObject: [[members objectAtIndex: i] objectForKey: @"c_uid"]];
}
// We remove the active user from the group (if present) in order to
// not subscribe him to their own resource!
[allUsers removeObject: [[context activeUser] login]];
}
}
else
{
if (dict)
allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]];
else
allUsers = [NSArray array];
}
for (i = 0; i < [allUsers count]; i++)
{
us = [SOGoUserSettings settingsForUser: [allUsers objectAtIndex: i]];
moduleSettings = [us objectForKey: [container nameInContainer]];
if (!(moduleSettings
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
{
moduleSettings = [NSMutableDictionary dictionary];
[us setObject: moduleSettings forKey: [container nameInContainer]];
}
subscriptionPointer = [self folderReference];
folderShowAlarms = [moduleSettings objectForKey: @"FolderShowAlarms"];
freeBusyExclusions = [moduleSettings objectForKey: @"FreeBusyExclusions"];
if (reallyDo)
{
if (!(folderShowAlarms
&& [folderShowAlarms isKindOfClass: [NSMutableDictionary class]]))
{
folderShowAlarms = [NSMutableDictionary dictionary];
[moduleSettings setObject: folderShowAlarms
forKey: @"FolderShowAlarms"];
}
// By default, we disable alarms on subscribed calendars
[folderShowAlarms setObject: [NSNumber numberWithBool: NO]
forKey: subscriptionPointer];
}
else
{
[folderShowAlarms removeObjectForKey: subscriptionPointer];
[freeBusyExclusions removeObjectForKey: subscriptionPointer];
}
[us synchronize];
rc = YES;
}
}
return rc;
}
//
// If the user is the owner of the calendar, by default we include the freebusy information.
//
// If the user is NOT the owner of the calendar, by default we exclude the freebusy information.
//
// We must include the freebusy information of other users if we are actually looking at their freebusy information
// but we aren't necessarily subscribed to their calendars.
//
- (BOOL) includeInFreeBusy
{
NSNumber *excludeFromFreeBusy;
NSString *userLogin, *ownerInContext;
BOOL is_owner;
userLogin = [[context activeUser] login];
ownerInContext = [[self container] ownerInContext: context];
is_owner = [userLogin isEqualToString: ownerInContext];
if (is_owner)
excludeFromFreeBusy
= [self folderPropertyValueInCategory: @"FreeBusyExclusions"
forUser: [context activeUser]];
else
excludeFromFreeBusy
= [self folderPropertyValueInCategory: @"FreeBusyExclusions"
forUser: [SOGoUser userWithLogin: ownerInContext]];
// 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)
{
if ([self isSubscription])
return NO;
else
return YES;
}
return ![excludeFromFreeBusy boolValue];
}
- (void) setIncludeInFreeBusy: (BOOL) newInclude
{
NSNumber *excludeFromFreeBusy;
excludeFromFreeBusy = [NSNumber numberWithBool: !newInclude];
[self setFolderPropertyValue: excludeFromFreeBusy
inCategory: @"FreeBusyExclusions"];
}
- (BOOL) _notificationValueForKey: (NSString *) theKey
defaultDomainKey: (NSString *) theDomainKey
{
SOGoUser *ownerUser;
NSNumber *notify;
ownerUser = [SOGoUser userWithLogin: self->owner];
notify = [self folderPropertyValueInCategory: theKey
forUser: ownerUser];
if (!notify && theDomainKey)
notify = [NSNumber numberWithBool: [[[context activeUser] domainDefaults]
boolForKey: theDomainKey]];
return [notify boolValue];
}
//
// We MUST keep the 'NO' value here, because we will always
// fallback to the domain defaults otherwise.
//
- (void) _setNotificationValue: (BOOL) b
forKey: (NSString *) theKey
{
[self setFolderPropertyValue: [NSNumber numberWithBool: b]
inCategory: theKey];
}
- (BOOL) notifyOnPersonalModifications
{
return [self _notificationValueForKey: @"NotifyOnPersonalModifications"
defaultDomainKey: @"SOGoNotifyOnPersonalModifications"];
}
- (void) setNotifyOnPersonalModifications: (BOOL) b
{
[self _setNotificationValue: b forKey: @"NotifyOnPersonalModifications"];
}
- (BOOL) notifyOnExternalModifications
{
return [self _notificationValueForKey: @"NotifyOnExternalModifications"
defaultDomainKey: @"SOGoNotifyOnExternalModifications"];
}
- (void) setNotifyOnExternalModifications: (BOOL) b
{
[self _setNotificationValue: b forKey: @"NotifyOnExternalModifications"];
}
- (BOOL) notifyUserOnPersonalModifications
{
return [self _notificationValueForKey: @"NotifyUserOnPersonalModifications"
defaultDomainKey: nil];
}
- (void) setNotifyUserOnPersonalModifications: (BOOL) b
{
[self _setNotificationValue: b forKey: @"NotifyUserOnPersonalModifications"];
}
- (NSString *) notifiedUserOnPersonalModifications
{
SOGoUser *ownerUser;
ownerUser = [SOGoUser userWithLogin: self->owner];
return [self folderPropertyValueInCategory: @"NotifiedUserOnPersonalModifications"
forUser: ownerUser];
}
- (void) setNotifiedUserOnPersonalModifications: (NSString *) theUser
{
[self setFolderPropertyValue: theUser
inCategory: @"NotifiedUserOnPersonalModifications"];
}
/* selection */
- (NSArray *) calendarUIDs
{
/* this is used for group calendars (this folder just returns itself) */
NSString *s;
s = [[self container] nameInContainer];
// [self logWithFormat:@"CAL UID: %@", s];
return [s isNotNull] ? [NSArray arrayWithObjects:&s count:1] : nil;
}
/* fetching */
- (NSString *) _sqlStringRangeFrom: (NSCalendarDate *) _startDate
to: (NSCalendarDate *) _endDate
cycle: (BOOL) _isCycle
{
NSString *format;
unsigned int start, end;
start = (unsigned int) [_startDate timeIntervalSince1970];
end = (unsigned int) [_endDate timeIntervalSince1970];
// vTODOs don't necessarily have start/end dates
if (_isCycle)
format = (@"(c_startdate = NULL OR c_startdate <= %u)"
@" AND (c_cycleenddate = NULL OR c_cycleenddate >= %u)");
else
format = (@"(c_startdate = NULL OR c_startdate <= %u)"
@" AND (c_enddate = NULL OR c_enddate >= %u)");
return [NSString stringWithFormat: format, end, start];
}
- (NSString *) aclSQLListingFilter
{
NSString *filter;
NSMutableArray *grantedClasses, *deniedClasses;
NSNumber *classNumber;
unsigned int grantedCount;
iCalAccessClass currentClass;
WOContext *localContext;
/* FIXME: The stored context from initialisation may have changed
by setContext by other operations in OpenChange library,
so we keep tighly to use the current session one. Without
this, the login is set to nil and a NSException is raised
at [SOGoAppointmentFolder:roleForComponentsWithAccessClass:forUser]
inside [SOGoAppointmentFolder:initializeQuickTablesAclsInContext]. */
localContext = [[WOApplication application] context];
[self initializeQuickTablesAclsInContext: localContext];
grantedClasses = [NSMutableArray arrayWithCapacity: 3];
deniedClasses = [NSMutableArray arrayWithCapacity: 3];
for (currentClass = 0;
currentClass < iCalAccessClassCount; currentClass++)
{
classNumber = [NSNumber numberWithInt: currentClass];
if (userCanAccessObjectsClassifiedAs[currentClass])
[grantedClasses addObject: classNumber];
else
[deniedClasses addObject: classNumber];
}
grantedCount = [grantedClasses count];
if (grantedCount == 3)
{
// User have access to all three classifications
filter = @"";
}
else if (grantedCount == 2)
{
// User has access to all but one of the classifications
filter = [NSString stringWithFormat: @"c_classification != %@",
[deniedClasses objectAtIndex: 0]];
}
else if (grantedCount == 1)
{
// User has access to only one classification
filter = [NSString stringWithFormat: @"c_classification = %@",
[grantedClasses objectAtIndex: 0]];
}
else
{
// User has access to no classification
filter = nil;
}
return filter;
}
- (NSString *) componentSQLFilter
{
NSString *filter;
if ([self showCalendarTasks])
filter = nil;
else
filter = @"c_component != 'vtodo'";
return filter;
}
- (BOOL) _checkIfWeCanRememberRecords: (NSArray *) fields
{
return ([fields containsObject: @"c_name"]
&& [fields containsObject: @"c_version"]
&& [fields containsObject: @"c_lastmodified"]
&& [fields containsObject: @"c_creationdate"]
&& [fields containsObject: @"c_component"]);
}
- (void) _rememberRecords: (NSArray *) records
{
NSEnumerator *recordsEnum;
NSDictionary *currentRecord;
recordsEnum = [records objectEnumerator];
while ((currentRecord = [recordsEnum nextObject]))
[childRecords setObject: currentRecord
forKey: [currentRecord objectForKey: @"c_name"]];
}
#warning filters should make use of EOQualifier
- (NSArray *) bareFetchFields: (NSArray *) fields
from: (NSCalendarDate *) startDate
to: (NSCalendarDate *) endDate
title: (NSString *) title
component: (NSString *) component
additionalFilters: (NSString *) filters
{
EOQualifier *qualifier;
GCSFolder *folder;
NSMutableArray *baseWhere;
NSString *where, *privacySQLString;
NSArray *records;
folder = [self ocsFolder];
baseWhere = [NSMutableArray arrayWithCapacity: 32];
if (startDate && endDate)
[baseWhere addObject: [self _sqlStringRangeFrom: startDate to: endDate
cycle: NO]];
if ([title length])
[baseWhere
addObject: [NSString stringWithFormat: @"c_title isCaseInsensitiveLike: '%%%@%%'",
[title asSafeSQLString]]];
if (component)
{
if ([component isEqualToString: @"vtodo"] && ![self showCalendarTasks])
return [NSArray array];
else
[baseWhere addObject: [NSString stringWithFormat: @"c_component = '%@'",
component]];
}
else if (![self showCalendarTasks])
[baseWhere addObject: @"c_component != 'vtodo'"];
if ([filters length])
[baseWhere addObject: filters];
privacySQLString = [self aclSQLListingFilter];
if (privacySQLString)
{
if ([privacySQLString length])
[baseWhere addObject: privacySQLString];
/* sql is empty when we fetch everything (all parameters are nil) */
if ([baseWhere count] > 0)
{
where = [baseWhere componentsJoinedByString: @" AND "];
qualifier = [EOQualifier qualifierWithQualifierFormat: where];
}
else
qualifier = nil;
/* fetch non-recurrent apts first */
records = [folder fetchFields: fields matchingQualifier: qualifier];
}
else
records = [NSArray array];
if ([self _checkIfWeCanRememberRecords: fields])
[self _rememberRecords: records];
return records;
}
/**
* Set the timezone of the event start and end dates to the user's timezone.
* @param theRecord a dictionary with the attributes of the event.
* @return a copy of theRecord with adjusted dates.
*/
- (NSMutableDictionary *) _fixupRecord: (NSDictionary *) theRecord
{
NSMutableDictionary *record;
static NSString *fields[] = { @"c_startdate", @"startDate",
@"c_enddate", @"endDate" };
unsigned int count;
NSCalendarDate *date;
NSNumber *dateValue;
BOOL isAllDay;
NSInteger offset;
isAllDay = [[theRecord objectForKey: @"c_isallday"] boolValue];
record = [[theRecord mutableCopy] autorelease];
for (count = 0; count < 2; count++)
{
dateValue = [theRecord objectForKey: fields[count * 2]];
if (dateValue)
{
date = [NSCalendarDate dateWithTimeIntervalSince1970: [dateValue unsignedIntValue]];
if (date)
{
[date setTimeZone: timeZone];
if (isAllDay)
{
// Since there's no timezone associated to all-day events,
// their time must be adjusted for the user's timezone.
offset = [timeZone secondsFromGMTForDate: date];
date = (NSCalendarDate*)[date dateByAddingYears:0 months:0 days:0 hours:0 minutes:0
seconds:-offset];
[record setObject: [NSNumber numberWithInt: [dateValue intValue] - offset] forKey: fields[count * 2]];
}
[record setObject: date forKey: fields[count * 2 + 1]];
}
}
else
[self logWithFormat: @"missing '%@' in record?", fields[count * 2]];
}
return record;
}
//
//
//
- (NSArray *) _fixupRecords: (NSArray *) theRecords
{
// TODO: is the result supposed to be sorted by date?
NSMutableArray *ma;
unsigned count, max;
id row;
if (theRecords)
{
max = [theRecords count];
ma = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
row = [self _fixupRecord: [theRecords objectAtIndex: count]];
if (row)
[ma addObject: row];
}
}
else
ma = nil;
return ma;
}
/**
* Adjust the timezone of the start and end dates to the user's timezone.
* The event is recurrent and the dates must first be adjusted with respect to
* the event's timezone.
* @param theRecord
* @param theCycle
* @param theFirstCycle
* @param theEventTimeZone
* @see fixupRecord:
* @return a copy of theRecord with adjusted dates.
*/
- (NSMutableDictionary *) fixupCycleRecord: (NSDictionary *) theRecord
cycleRange: (NGCalendarDateRange *) theCycle
firstInstanceCalendarDateRange: (NGCalendarDateRange *) theFirstCycle
withEventTimeZone: (iCalTimeZone *) theEventTimeZone
{
NSMutableDictionary *record;
NSNumber *dateSecs;
id date;
int secondsOffsetFromGMT;
record = [[theRecord mutableCopy] autorelease];
date = [theCycle startDate];
if (theEventTimeZone)
{
secondsOffsetFromGMT = (int) [[theEventTimeZone periodForDate: date] secondsOffsetFromGMT];
date = [date dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: -secondsOffsetFromGMT];
}
[date setTimeZone: timeZone];
[record setObject: date forKey: @"startDate"];
dateSecs = [NSNumber numberWithInt: [date timeIntervalSince1970]];
[record setObject: dateSecs forKey: @"c_startdate"];
if ([[record valueForKey: @"c_isallday"] boolValue])
{
// Refer to all-day recurrence id by their GMT-based start date
date = [theCycle startDate];
secondsOffsetFromGMT = (int) [[date timeZone] secondsFromGMTForDate: date];
date = [date dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: secondsOffsetFromGMT];
dateSecs = [NSNumber numberWithInt: [date timeIntervalSince1970]];
}
[record setObject: dateSecs forKey: @"c_recurrence_id"];
date = [record valueForKey: @"c_enddate"];
if ([date isNotNull])
{
date = [theCycle endDate];
if (theEventTimeZone)
{
secondsOffsetFromGMT = (int) [[theEventTimeZone periodForDate: date] secondsOffsetFromGMT];
date = [date dateByAddingYears: 0 months: 0 days: 0 hours: 0 minutes: 0 seconds: -secondsOffsetFromGMT];
}
[date setTimeZone: timeZone];
[record setObject: date forKey: @"endDate"];
dateSecs = [NSNumber numberWithInt: [date timeIntervalSince1970]];
[record setObject: dateSecs forKey: @"c_enddate"];
}
else
[record removeObjectForKey: @"endDate"];
return record;
}
//
//
//
- (int) _indexOfRecordMatchingDate: (NSCalendarDate *) matchDate
inArray: (NSArray *) recordArray
{
int count, max, recordIndex;
NSDictionary *currentRecord;
recordIndex = -1;
count = 0;
max = [recordArray count];
while (recordIndex == -1 && count < max)
{
currentRecord = [recordArray objectAtIndex: count];
if ([[currentRecord objectForKey: @"startDate"]
compare: matchDate] == NSOrderedSame)
recordIndex = count;
else
count++;
}
return recordIndex;
}
//
//
//