/
SOGoUserHomePage.m
749 lines (665 loc) · 29.9 KB
/
SOGoUserHomePage.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
/* SOGoUserHomePage.m - this file is part of SOGo
*
* Copyright (C) 2007-2017 Inverse inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/WOCookie.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
#import <NGExtensions/NSCalendarDate+misc.h>
#import <NGExtensions/NSObject+Logs.h>
#import <Appointments/SOGoFreeBusyObject.h>
#import <Mailer/SOGoMailAccount.h>
#import <Mailer/SOGoMailAccounts.h>
#import <SOGo/SOGoCache.h>
#import <SOGo/SOGoCASSession.h>
#if defined(SAML2_CONFIG)
#import <SOGo/SOGoSAML2Session.h>
#endif
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoWebAuthenticator.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserProfile.h>
#import <SOGo/SOGoSession.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/NSCalendarDate+SOGo.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGoUI/UIxComponent.h>
#import <SBJson/NSObject+SBJSON.h>
#define INTERVALSECONDS 900 /* 15 minutes */
#define PADDING 8
#define HALFPADDING PADDING/2
@interface SOGoUserHomePage : UIxComponent
@end
@implementation SOGoUserHomePage
- (id <WOActionResults>) defaultAction
{
SOGoUserFolder *co;
NSString *loginModule;
SOGoSystemDefaults *sd;
SOGoDomainDefaults *dd;
SOGoUserDefaults *ud;
NSArray *filters;
NSURL *moduleURL;
sd = [SOGoSystemDefaults sharedSystemDefaults];
dd = [[context activeUser] domainDefaults];
ud = [[context activeUser] userDefaults];
loginModule = [ud loginModule];
if (!([loginModule isEqualToString: @"Calendar"]
|| [loginModule isEqualToString: @"Contacts"]
|| [loginModule isEqualToString: @"Mail"])
|| ![[context activeUser] canAccessModule: loginModule])
{
[self errorWithFormat: @"login module '%@' not accepted (must be"
@"'Calendar', 'Contacts' or 'Mail')", loginModule];
loginModule = @"Contacts";
}
// We check if we must write the Sieve scripts to the server
// upon first login if no user preferences are found, and the SOGo
// admin has defined SOGoSieveFilters in the domain or system settings
if ([dd sieveScriptsEnabled] && [[[ud source] values] count] == 0 &&
((filters = [[dd source] objectForKey: @"SOGoSieveFilters"]) || (filters = [[sd source] objectForKey: @"SOGoSieveFilters"])))
{
SOGoMailAccount *account;
SOGoMailAccounts *folder;
[ud setSieveFilters: filters];
[ud synchronize];
folder = [[self clientObject] mailAccountsFolder: @"Mail"
inContext: context];
account = [folder lookupName: @"0" inContext: context acquire: NO];
[account updateFilters];
}
co = [self clientObject];
moduleURL = [NSURL URLWithString: loginModule
relativeToURL: [co soURL]];
return [self redirectToLocation: [moduleURL absoluteString]];
}
- (NSDictionary *) _freeBusyFromStartDate: (NSCalendarDate *) startDate
toEndDate: (NSCalendarDate *) endDate
forFreeBusy: (SOGoFreeBusyObject *) fb
andContact: (NSString *) uid
{
NSCalendarDate *start, *end;
NSMutableDictionary *freeBusy, *dayData, *hourData;
NSArray *records;
NSArray *emails, *partstates;
NSCalendarDate *currentDate, *currentStartDate, *currentEndDate;
NSDictionary *record;
NSString *dayKey, *hourKey, *minuteKey;
NSEnumerator *freeBusyList, *dayList, *hourList;
SOGoUser *user;
int quarter, lastQuarter, recordCount, recordMax, count, i, type, maxBookings, isResource;
// We "copy" the start/end date because -fetchFreeBusyInfosFrom will mess
// with the timezone and we don't want that to properly calculate the delta
// DO NOT USE -copy HERE - it'll simply return [self retain].
start = [NSCalendarDate dateWithYear: [startDate yearOfCommonEra]
month: [startDate monthOfYear]
day: [startDate dayOfMonth]
hour: [startDate hourOfDay]
minute: [startDate minuteOfHour]
second: [startDate secondOfMinute]
timeZone: [startDate timeZone]];
end = [NSCalendarDate dateWithYear: [endDate yearOfCommonEra]
month: [endDate monthOfYear]
day: [endDate dayOfMonth]
hour: [endDate hourOfDay]
minute: [endDate minuteOfHour]
second: [endDate secondOfMinute]
timeZone: [endDate timeZone]];
freeBusy = [NSMutableDictionary dictionary];
user = [SOGoUser userWithLogin: [[self clientObject] ownerInContext: context] roles: nil];
maxBookings = [user numberOfSimultaneousBookings];
isResource = [user isResource];
// Fetch freebusy information if the user is NOT a resource or if multiplebookings isn't unlimited
if (!isResource || maxBookings != 0)
{
records = [fb fetchFreeBusyInfosFrom: start to: end forContact: uid];
recordMax = [records count];
for (recordCount = 0; recordCount < recordMax; recordCount++)
{
record = [records objectAtIndex: recordCount];
user = [record objectForKey: @"owner"];
if ([[record objectForKey: @"c_isopaque"] boolValue])
{
type = 0;
// If the event has NO organizer (which means it's the user that has created it) OR
// If we are the organizer of the event THEN we are automatically busy
if ([[record objectForKey: @"c_orgmail"] length] == 0 ||
[user hasEmail: [record objectForKey: @"c_orgmail"]])
{
type = 1;
}
else
{
// We check if the user has accepted/declined or needs action
// on the current event.
emails = [[record objectForKey: @"c_partmails"] componentsSeparatedByString: @"\n"];
for (i = 0; i < [emails count]; i++)
{
if ([user hasEmail: [emails objectAtIndex: i]])
{
// We now fetch the c_partstates array and get the participation
// status of the user for the event
partstates = [[record objectForKey: @"c_partstates"] componentsSeparatedByString: @"\n"];
if (i < [partstates count])
{
// 0: needs action (considered busy)
// 1: accepted (busy)
// 2: declined (free)
// 3: tentative (free)
// 4: delegated (free)
type = ([[partstates objectAtIndex: i] intValue] < 2 ? 1 : 0);
}
break;
}
}
}
if (type == 1)
{
// User is busy for this event
currentStartDate = [record objectForKey: @"startDate"];
currentEndDate = [record objectForKey: @"endDate"];
if ([currentStartDate earlierDate: startDate] == currentStartDate)
currentStartDate = startDate;
dayKey = [currentStartDate shortDateString];
dayData = [freeBusy objectForKey: dayKey];
if (!dayData)
{
dayData = [NSMutableDictionary dictionary];
[freeBusy setObject: dayData forKey: dayKey];
}
currentDate = [NSCalendarDate dateWithYear: [currentStartDate yearOfCommonEra]
month: [currentStartDate monthOfYear]
day: [currentStartDate dayOfMonth]
hour: [currentStartDate hourOfDay]
minute: 0
second: 0
timeZone: [currentStartDate timeZone]];
// Increment counters for quarters of first hour
hourKey = [NSString stringWithFormat: @"%u", (unsigned int)[currentDate hourOfDay]];
hourData = [dayData objectForKey: hourKey];
if (!hourData)
{
hourData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: 0], @"0",
[NSNumber numberWithInt: 0], @"15",
[NSNumber numberWithInt: 0], @"30",
[NSNumber numberWithInt: 0], @"45",
nil];
[dayData setObject: hourData forKey: hourKey];
}
quarter = (int)([currentStartDate minuteOfHour] / 15 + 0.5);
if ([currentEndDate timeIntervalSinceDate: currentDate] < 3600)
lastQuarter = (int)([currentEndDate minuteOfHour] / 15 + 0.5);
else
lastQuarter = 4;
for (i = 0; i < lastQuarter; i++) {
if (i >= quarter)
{
minuteKey = [NSString stringWithFormat: @"%u", i*15];
count = [[hourData objectForKey: minuteKey] intValue] + 1;
[hourData setObject: [NSNumber numberWithInt: count] forKey: minuteKey];
}
}
currentDate = [currentDate dateByAddingYears:0 months:0 days:0 hours:1 minutes:0 seconds:0];
// Increment counters of fully busy hours
while ([currentDate compare: currentEndDate] == NSOrderedAscending &&
[currentEndDate timeIntervalSinceDate: currentDate] >= 3600) // 1 hour
{
if ([currentDate hourOfDay] == 0)
{
// New day
dayKey = [currentDate shortDateString];
dayData = [freeBusy objectForKey: dayKey];
if (!dayData)
{
dayData = [NSMutableDictionary dictionary];
[freeBusy setObject: dayData forKey: dayKey];
}
}
hourKey = [NSString stringWithFormat: @"%u", (unsigned int)[currentDate hourOfDay]];
hourData = [dayData objectForKey: hourKey];
if (!hourData)
{
hourData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: 1], @"0",
[NSNumber numberWithInt: 1], @"15",
[NSNumber numberWithInt: 1], @"30",
[NSNumber numberWithInt: 1], @"45",
nil];
[dayData setObject: hourData forKey: hourKey];
}
else
{
for (i = 0; i < 4; i++)
{
minuteKey = [NSString stringWithFormat: @"%u", i*15];
count = [[hourData objectForKey: minuteKey] intValue] + 1;
[hourData setObject: [NSNumber numberWithInt: count] forKey: minuteKey];
}
}
currentDate = [currentDate dateByAddingYears:0 months:0 days:0 hours:1 minutes:0 seconds:0];
}
// Increment counters for quarters of last hour
if ([currentEndDate timeIntervalSinceDate: currentDate] > 0)
{
hourKey = [NSString stringWithFormat: @"%u", (unsigned int)[currentDate hourOfDay]];
hourData = [dayData objectForKey: hourKey];
if (!hourData)
{
hourData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: 0], @"0",
[NSNumber numberWithInt: 0], @"15",
[NSNumber numberWithInt: 0], @"30",
[NSNumber numberWithInt: 0], @"45",
nil];
[dayData setObject: hourData forKey: hourKey];
}
quarter = (int)([currentEndDate minuteOfHour] / 15 + 0.5);
for (i = 0; i < 4; i++)
{
if (i < quarter)
{
minuteKey = [NSString stringWithFormat: @"%u", i*15];
if (isResource)
count = [[hourData objectForKey: minuteKey] intValue] + 1;
else
count = 1;
[hourData setObject: [NSNumber numberWithInt: count] forKey: minuteKey];
}
}
}
}
}
}
if (maxBookings > 0)
{
// Reset the freebusy for the periods that are bellow the maximum number of bookings
freeBusyList = [freeBusy objectEnumerator];
while ((dayData = [freeBusyList nextObject]))
{
dayList = [dayData objectEnumerator];
while ((hourData = [dayList nextObject]))
{
hourList = [hourData keyEnumerator];
while ((minuteKey = [hourList nextObject]))
{
count = [[hourData objectForKey: minuteKey] intValue];
if (count < maxBookings)
i = 0;
else
i = 1;
if (i != count)
[hourData setObject: [NSNumber numberWithInt: i] forKey: minuteKey];
}
}
}
}
}
return freeBusy;
}
- (id <WOActionResults>) readFreeBusyAction
{
SOGoFreeBusyObject *freebusy;
NSCalendarDate *startDate, *endDate;
NSDictionary *jsonResponse;
NSString *queryDay, *uid;
NSTimeZone *uTZ;
SOGoUser *user;
unsigned int httpStatus;
user = [context activeUser];
uTZ = [[user userDefaults] timeZone];
httpStatus = 200;
uid = [self queryParameterForKey: @"uid"];
queryDay = [self queryParameterForKey: @"sday"];
if ([queryDay length] == 8)
{
startDate = [NSCalendarDate dateFromShortDateString: queryDay
andShortTimeString: @"0000"
inTimeZone: uTZ];
queryDay = [self queryParameterForKey: @"eday"];
if ([queryDay length] == 8)
{
endDate = [NSCalendarDate dateFromShortDateString: queryDay
andShortTimeString: @"2359"
inTimeZone: uTZ];
if ([startDate earlierDate: endDate] == endDate)
{
httpStatus = 403;
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"failure", @"status",
@"Start date is later than end date.", @"message",
nil];
}
else
{
freebusy = [self clientObject];
jsonResponse = [self _freeBusyFromStartDate: startDate
toEndDate: endDate
forFreeBusy: freebusy
andContact: uid];
}
}
else
{
httpStatus = 403;
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"failure", @"status",
@"Invalid end date.", @"message",
nil];
}
}
else
{
httpStatus = 403;
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
@"failure", @"status",
@"Invalid start date.", @"message",
nil];
}
return [self responseWithStatus: httpStatus
andJSONRepresentation: jsonResponse];
}
- (NSString *) _logoutRedirectURL
{
NSString *redirectURL;
SOGoSystemDefaults *sd;
id container;
sd = [SOGoSystemDefaults sharedSystemDefaults];
if ([[sd authenticationType] isEqualToString: @"cas"])
{
redirectURL = [SOGoCASSession CASURLWithAction: @"logout"
andParameters: nil];
}
#if defined(SAML2_CONFIG)
else if ([[sd authenticationType] isEqualToString: @"saml2"])
{
NSString *username, *password, *domain, *value;
SOGoSAML2Session *saml2Session;
SOGoWebAuthenticator *auth;
LassoServer *server;
LassoLogout *logout;
NSArray *creds;
auth = [[self clientObject] authenticatorInContext: context];
value = [[context request] cookieValueForKey: [auth cookieNameInContext: context]];
creds = [auth parseCredentials: value];
value = [SOGoSession valueForSessionKey: [creds lastObject]];
domain = nil;
[SOGoSession decodeValue: value
usingKey: [creds objectAtIndex: 0]
login: &username
domain: &domain
password: &password];
saml2Session = [SOGoSAML2Session SAML2SessionWithIdentifier: password
inContext: context];
server = [SOGoSAML2Session lassoServerInContext: context];
logout = lasso_logout_new(server);
lasso_profile_set_session_from_dump(LASSO_PROFILE(logout), [[saml2Session session] UTF8String]);
lasso_profile_set_identity_from_dump(LASSO_PROFILE(logout), [[saml2Session session] UTF8String]);
lasso_logout_init_request(logout, NULL, LASSO_HTTP_METHOD_REDIRECT);
lasso_logout_build_request_msg(logout);
redirectURL = [NSString stringWithFormat: @"%s", LASSO_PROFILE(logout)->msg_url];
// We destroy our cache entry, the session will be taken care by the caller
[[SOGoCache sharedCache] removeSAML2LoginDumpsForIdentifier: password];
}
#endif
else
{
container = [[self clientObject] container];
redirectURL = [container baseURLInContext: context];
}
return redirectURL;
}
- (WOCookie *) _logoutCookieWithDate: (NSCalendarDate *) date
{
SOGoWebAuthenticator *auth;
NSString *cookieName, *appName;
WOCookie *cookie;
cookie = nil;
auth = [[self clientObject] authenticatorInContext: context];
if ([auth respondsToSelector: @selector (cookieNameInContext:)])
{
cookieName = [auth cookieNameInContext: context];
if ([cookieName length])
{
cookie = [WOCookie cookieWithName: cookieName value: @"discard"];
appName = [[context request] applicationName];
[cookie setPath: [NSString stringWithFormat: @"/%@/", appName]];
[cookie setExpires: [date yesterday]];
}
}
return cookie;
}
- (id <WOActionResults>) logoffAction
{
NSString *userName, *value;
SOGoWebAuthenticator *auth;
WOResponse *response;
NSCalendarDate *date;
WOCookie *cookie;
NSArray *creds;
userName = [[context activeUser] login];
[self logWithFormat: @"user '%@' logged off", userName];
response = [self redirectToLocation: [self _logoutRedirectURL]];
date = [NSCalendarDate calendarDate];
[date setTimeZone: [NSTimeZone timeZoneForSecondsFromGMT: 0]];
// We cleanup the memecached/database session cache. We do this before
// invoking _logoutCookieWithDate: in order to obtain its value.
auth = [[self clientObject] authenticatorInContext: context];
if ([auth respondsToSelector: @selector (cookieNameInContext:)])
{
value = [[context request] cookieValueForKey: [auth cookieNameInContext: context]];
creds = [auth parseCredentials: value];
if ([creds count] > 1)
[SOGoSession deleteValueForSessionKey: [creds objectAtIndex: 1]];
}
cookie = [self _logoutCookieWithDate: date];
if (cookie)
[response addCookie: cookie];
// We remove the XSRF cookie
cookie = [WOCookie cookieWithName: @"XSRF-TOKEN" value: @"discard"];
[cookie setPath: [NSString stringWithFormat: @"/%@/", [[context request] applicationName]]];
[cookie setExpires: [date yesterday]];
[response addCookie: cookie];
[response setHeader: [date rfc822DateString] forKey: @"Last-Modified"];
[response setHeader: @"no-store, no-cache, must-revalidate,"
@" max-age=0, post-check=0, pre-check=0"
forKey: @"Cache-Control"];
[response setHeader: @"no-cache" forKey: @"Pragma"];
return response;
}
- (NSMutableArray *) _usersForResults: (NSArray *) users
inDomain: (NSString *) domain
{
NSString *uid;
NSDictionary *contact;
NSString *contactInfo, *owner;
NSMutableArray *jsonResponse;
NSMutableDictionary *jsonLine;
NSArray *allUsers;
int count, max;
BOOL activeUserIsInDomain;
owner = [[self clientObject] ownerInContext: context];
activeUserIsInDomain = ([domain length] == 0 || [[[context activeUser] domain] isEqualToString: domain]);
// We sort our array - this is pretty useful for the Web
// interface of SOGo.
allUsers = [users sortedArrayUsingSelector: @selector (caseInsensitiveDisplayNameCompare:)];
max = [allUsers count];
jsonResponse = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
contact = [allUsers objectAtIndex: count];
uid = [contact objectForKey: @"c_uid"];
// We do NOT return the owner from which the search is performed
if (!activeUserIsInDomain || ![uid isEqualToString: owner])
{
jsonLine = [NSMutableDictionary dictionary];
if ([domain length])
uid = [NSString stringWithFormat: @"%@@%@", uid, domain];
[jsonLine setObject: uid forKey: @"uid"];
[jsonLine setObject: [contact objectForKey: @"cn"] forKey: @"cn"];
[jsonLine setObject: [contact objectForKey: @"c_email"] forKey: @"c_email"];
[jsonLine setObject: [NSNumber numberWithBool: [[contact objectForKey: @"isGroup"] boolValue]] forKey: @"isGroup"];
contactInfo = [contact objectForKey: @"c_info"];
if (contactInfo)
[jsonLine setObject: contactInfo forKey: @"c_info"];
[jsonResponse addObject: jsonLine];
}
}
return jsonResponse;
}
/**
* @api {get} /so/:username/usersSearch?search=:search Search for users
* @apiVersion 1.0.0
* @apiName GetUsersSearch
* @apiGroup Common
* @apiExample {curl} Example usage:
* curl -i http://localhost/SOGo/so/sogo1/usersSearch?search=john
*
* @apiParam {String} search Substring to match against username or email address
*
* @apiSuccess (Success 200) {Object[]} users List of matching users
* @apiSuccess (Success 200) {String} users.uid User ID
* @apiSuccess (Success 200) {String} users.c_email Main email address
* @apiSuccess (Success 200) {String} users.cn Common name
* @apiSuccess (Success 200) {Number} users.isGroup 1 if the user is a group
* @apiError (Error 400) {Object} error The error message
*/
- (id <WOActionResults>) usersSearchAction
{
NSMutableArray *users;
NSArray *currentUsers;
NSDictionary *message;
NSString *contact, *domain, *uidDomain;
NSEnumerator *visibleDomains;
id <WOActionResults> result;
SOGoUserManager *um;
SOGoSystemDefaults *sd;
contact = [self queryParameterForKey: @"search"];
if ([contact length])
{
um = [SOGoUserManager sharedUserManager];
sd = [SOGoSystemDefaults sharedSystemDefaults];
domain = [[context activeUser] domain];
uidDomain = [sd enableDomainBasedUID]? domain : nil;
users = [self _usersForResults: [um fetchUsersMatching: contact
inDomain: domain]
inDomain: uidDomain];
if ([domain length])
{
// Add results from visible domains
visibleDomains = [[sd visibleDomainsForDomain: domain] objectEnumerator];
while ((domain = [visibleDomains nextObject]))
{
currentUsers = [self _usersForResults: [um fetchUsersMatching: contact
inDomain: domain]
inDomain: uidDomain];
[users addObjectsFromArray: currentUsers];
}
}
result = [self responseWithStatus: 200
andJSONRepresentation: [NSDictionary dictionaryWithObject: users forKey: @"users"]];
}
else
{
message = [NSDictionary dictionaryWithObject: [self labelForKey: @"Missing search parameter"]
forKey: @"error"];
result = [self responseWithStatus: 400 andJSONRepresentation: message];
}
return result;
}
- (WOResponse *) _foldersResponseForResults: (NSArray *) folders
{
WOResponse *response;
response = [context response];
[response setStatus: 200];
[response setHeader: @"text/plain; charset=utf-8"
forKey: @"Content-Type"];
[response appendContentString: [[NSDictionary dictionaryWithObject: folders
forKey: @"folders"] JSONRepresentation]];
return response;
}
/**
* @api {get} /so/:username/foldersSearch?type=:type Search for folders
* @apiVersion 1.0.0
* @apiName GetFoldersSearch
* @apiGroup Common
* @apiExample {curl} Example usage:
* curl -i http://localhost/SOGo/so/sogo1/foldersSearch?type=contact
*
* @apiParam {String} type Either 'calendar' or 'contact'. If nothing is specifed, its both.
*
* @apiSuccess (Success 200) {Object[]} folders List of matching folders
* @apiSuccess (Success 200) {String} folders.name Path of folder
* @apiSuccess (Success 200) {String} folders.displayName Human readable name
* @apiSuccess (Success 200) {String} folders.owner Username of owner
* @apiSuccess (Success 200) {String} folders.type Either 'calendar' or 'contact'
* @apiError (Error 400) {Object} error The error message
*/
- (id <WOActionResults>) foldersSearchAction
{
NSString *folderType;
NSMutableArray *folders;
id <WOActionResults> result;
SOGoUserFolder *userFolder;
folderType = [self queryParameterForKey: @"type"];
folders = [NSMutableArray array];
userFolder = [self clientObject];
if ([folderType length])
{
[folders addObjectsFromArray: [userFolder foldersOfType: folderType
forUID: [userFolder ownerInContext: context]]];
}
else
{
[folders addObjectsFromArray: [userFolder foldersOfType: @"calendar"
forUID: [userFolder ownerInContext: context]]];
[folders addObjectsFromArray: [userFolder foldersOfType: @"contact"
forUID: [userFolder ownerInContext: context]]];
}
result = [self _foldersResponseForResults: folders];
return result;
}
/**
* @api {get} /so/:username/date Get current day
* @apiVersion 1.0.0
* @apiName GetCurrentDate
* @apiGroup Common
* @apiExample {curl} Example usage:
* curl -i http://localhost/SOGo/so/sogo1/date
*
* @apiSuccess (Success 200) {String} weekday Full weekday name according to user's locale
* @apiSuccess (Success 200) {String} month Full month name according to user's locale
* @apiSuccess (Success 200) {String} day Day of month as two digit decimal number (leading zero)
* @apiSuccess (Success 200) {String} year Year as a decimal number with century
* @apiSuccess (Success 200) {Object} abbr Abbreviations
* @apiSuccess (Success 200) {String} abbr.weekday Abbreviated weekday name according to user's locale
* @apiSuccess (Success 200) {String} abbr.month Abbreviated month name according to user's locale
*/
- (id <WOActionResults>) dateAction
{
return [self responseWithStatus: 200 andJSONRepresentation: [[context activeUser] currentDay]];
}
- (id) recoverAction
{
return [self responseWithStatus: 200
andString: @"Full recovery in place."];
}
@end