From c2ace24b44ac612c16bc62696bb4b4f915a33cca Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 24 Nov 2008 04:12:16 +0000 Subject: [PATCH] Monotone-Parent: 763cdd65301c2ece5f7e7a480dc165fb25068f9a Monotone-Revision: c30c440a14fe8daee4210904dd0d7212fd743325 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-11-24T04:12:16 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 10 +++ UI/MainUI/SOGoUserHomePage.m | 115 +++++++++++++++++++++-------------- UI/MainUI/product.plist | 5 ++ 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 868f97c17..3e6710a79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-23 Wolfgang Sourdeau + + * UI/MainUI/SOGoUserHomePage.m ([SOGoUserHomePage + -usersSearchAction]): new method, derived from the previous + version of foldersSearchAction, but that only returns username and + contact info about matching users. + ([SOGoUserHomePage -foldersSearchAction]): new implementation that + returns the folders available for subscription of the only user + passed as parameter. + 2008-11-23 Ludovic Marcotte * UI/Scheduler/UIxComponentEditor.m - _loadAttendees diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index 308f5d990..c646a5cc5 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -36,10 +36,12 @@ #import #import +#import #import #import #import #import +#import #import #define intervalSeconds 900 /* 15 minutes */ @@ -288,35 +290,13 @@ static NSString *LDAPContactInfoAttribute = nil; return response; } -- (NSString *) _foldersStringForFolders: (NSEnumerator *) folders -{ - NSMutableString *foldersString; - NSDictionary *currentFolder; - - foldersString = [NSMutableString new]; - [foldersString autorelease]; - - currentFolder = [folders nextObject]; - while (currentFolder) - { - [foldersString appendFormat: @";%@:%@:%@", - [currentFolder objectForKey: @"displayName"], - [currentFolder objectForKey: @"name"], - [currentFolder objectForKey: @"type"]]; - currentFolder = [folders nextObject]; - } - - return foldersString; -} - -- (WOResponse *) _foldersResponseForResults: (NSDictionary *) results +- (WOResponse *) _usersResponseForResults: (NSEnumerator *) users { WOResponse *response; - NSString *uid, *foldersString; + NSString *uid; NSMutableString *responseString; NSDictionary *contact; - NSEnumerator *contacts; - NSArray *folders; + NSString *contactInfo; response = [context response]; [response setStatus: 200]; @@ -324,19 +304,21 @@ static NSString *LDAPContactInfoAttribute = nil; forKey: @"Content-Type"]; responseString = [NSMutableString new]; - contacts = [[results allKeys] objectEnumerator]; - while ((contact = [contacts nextObject])) + while ((contact = [users nextObject])) { uid = [contact objectForKey: @"c_uid"]; - folders = [results objectForKey: contact]; - foldersString - = [self _foldersStringForFolders: [folders objectEnumerator]]; - [responseString appendFormat: @"%@:%@:%@:%@%@\n", uid, + if ([LDAPContactInfoAttribute length]) + { + contactInfo = [contact objectForKey: LDAPContactInfoAttribute]; + if (!contactInfo) + contactInfo = @""; + } + else + contactInfo = @""; + [responseString appendFormat: @"%@:%@:%@:%@\n", uid, [contact objectForKey: @"cn"], [contact objectForKey: @"c_email"], - ([LDAPContactInfoAttribute length] > 0 && [contact objectForKey: LDAPContactInfoAttribute] != nil) ? - [contact objectForKey: LDAPContactInfoAttribute] : @"", - foldersString]; + contactInfo]; } [response appendContentString: responseString]; [responseString release]; @@ -344,25 +326,19 @@ static NSString *LDAPContactInfoAttribute = nil; return response; } -- (id ) foldersSearchAction +- (id ) usersSearchAction { - NSString *contact, *folderType; - NSDictionary *folders; + NSString *contact; id result; + LDAPUserManager *um; + NSEnumerator *users; + um = [LDAPUserManager sharedUserManager]; contact = [self queryParameterForKey: @"search"]; if ([contact length]) { - folderType = [self queryParameterForKey: @"type"]; - if ([folderType length]) - { - folders = [[self clientObject] foldersOfType: folderType - matchingUID: contact]; - result = [self _foldersResponseForResults: folders]; - } - else - result = [NSException exceptionWithHTTPStatus: 400 - reason: @"missing 'type' parameter"]; + users = [[um fetchUsersMatching: contact] objectEnumerator]; + result = [self _usersResponseForResults: users]; } else result = [NSException exceptionWithHTTPStatus: 400 @@ -371,4 +347,49 @@ static NSString *LDAPContactInfoAttribute = nil; return result; } +- (WOResponse *) _foldersResponseForResults: (NSArray *) folders +{ + WOResponse *response; + NSEnumerator *foldersEnum; + NSDictionary *currentFolder; + + response = [context response]; + [response setStatus: 200]; + [response setHeader: @"text/plain; charset=utf-8" + forKey: @"Content-Type"]; + foldersEnum = [folders objectEnumerator]; + while ((currentFolder = [foldersEnum nextObject])) + [response appendContentString: + [currentFolder keysWithFormat: @";%{displayName}:%{name}:%{type}"]]; + + return response; +} + +- (id ) foldersSearchAction +{ + NSString *contact, *folderType; + NSArray *folders; + id result; + + contact = [self queryParameterForKey: @"user"]; + if ([contact length]) + { + folderType = [self queryParameterForKey: @"type"]; + if ([folderType length]) + { + folders = [[self clientObject] foldersOfType: folderType + forUID: contact]; + result = [self _foldersResponseForResults: folders]; + } + else + result = [NSException exceptionWithHTTPStatus: 400 + reason: @"missing 'type' parameter"]; + } + else + result = [NSException exceptionWithHTTPStatus: 400 + reason: @"missing 'user' parameter"]; + + return result; +} + @end diff --git a/UI/MainUI/product.plist b/UI/MainUI/product.plist index 068832074..194b03cd6 100644 --- a/UI/MainUI/product.plist +++ b/UI/MainUI/product.plist @@ -136,6 +136,11 @@ pageName = "SOGoUserHomePage"; actionName = "logoff"; }; + usersSearch = { + protectedBy = "View"; + pageName = "SOGoUserHomePage"; + actionName = "usersSearch"; + }; foldersSearch = { protectedBy = "View"; pageName = "SOGoUserHomePage";