diff --git a/ChangeLog b/ChangeLog index 122f478f2..f2fd671b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-12-05 Wolfgang Sourdeau + + * UI/MainUI/SOGoUserHomePage.m ([SOGoUserHomePage + -foldersSearchAction]): make use of the new search methods in + SOGoUserFolder (see below). + + * UI/Contacts/UIxContactFoldersView.m ([-foldersSearchAction]): + moved method into ../MainUI/SOGoUserHomePage.m. + + * SoObjects/SOGo/SOGoUserFolder.m ([SOGoUserFolder + -foldersOfType:folderTypeforUID:uid]): only return folders owned + by the specified user. + 2007-12-05 Francis Lachapelle * SoObjects/Mailer/SOGoDraftObject.m: The condition for replyToAll diff --git a/SoObjects/SOGo/SOGoUserFolder.m b/SoObjects/SOGo/SOGoUserFolder.m index 688d3f043..68bcfcd4c 100644 --- a/SoObjects/SOGo/SOGoUserFolder.m +++ b/SoObjects/SOGo/SOGoUserFolder.m @@ -131,27 +131,27 @@ return filter; } -#warning UIxContactsFoldersView should use these methods\ - instead from now on... - - (NSArray *) _subFoldersFromFolder: (SOGoParentFolder *) parentFolder { NSMutableArray *folders; NSEnumerator *subfolders; SOGoFolder *currentFolder; - NSString *folderName; + NSString *folderName, *folderOwner; NSMutableDictionary *currentDictionary; SoSecurityManager *securityManager; + folderOwner = [parentFolder ownerInContext: context]; securityManager = [SoSecurityManager sharedSecurityManager]; - + folders = [NSMutableArray array]; subfolders = [[parentFolder subFolders] objectEnumerator]; while ((currentFolder = [subfolders nextObject])) { if (![securityManager validatePermission: SOGoPerm_AccessObject - onObject: currentFolder inContext: context]) + onObject: currentFolder inContext: context] + && [[currentFolder ownerInContext: context] + isEqualToString: folderOwner]) { folderName = [NSString stringWithFormat: @"/%@/%@", [parentFolder nameInContainer], diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index 9605ed56e..c662072a0 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -221,121 +221,6 @@ return folders; } -- (NSArray *) _foldersForUID: (NSString *) uid - ofType: (NSString *) folderType -{ - NSObject *topFolder, *userFolder; - SOGoParentFolder *parentFolder; - NSMutableArray *folders; - - folders = [NSMutableArray new]; - [folders autorelease]; - - topFolder = [[[self clientObject] container] container]; - userFolder = [topFolder lookupName: uid inContext: context acquire: NO]; - - /* FIXME: should be moved in the SOGo* classes. Maybe by having a SOGoFolderManager. */ - if ([folderType length] == 0 || [folderType isEqualToString: @"calendar"]) - { - parentFolder = [userFolder lookupName: @"Calendar" - inContext: context acquire: NO]; - [folders - addObjectsFromArray: [self _subFoldersFromFolder: parentFolder]]; - } - if ([folderType length] == 0 || [folderType isEqualToString: @"contact"]) - { - parentFolder = [userFolder lookupName: @"Contacts" - inContext: context acquire: NO]; - [folders - addObjectsFromArray: [self _subFoldersFromFolder: parentFolder]]; - } - - return folders; -} - -- (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: (NSArray *) results - withType: (NSString *) folderType -{ - WOResponse *response; - NSString *uid, *foldersString; - NSMutableString *responseString; - NSDictionary *contact; - NSEnumerator *contacts; - NSArray *folders; - - response = [context response]; - - if ([results count]) - { - [response setStatus: 200]; - [response setHeader: @"text/plain; charset=utf-8" - forKey: @"Content-Type"]; - - responseString = [NSMutableString new]; - contacts = [results objectEnumerator]; - while ((contact = [contacts nextObject])) - { - uid = [contact objectForKey: @"c_uid"]; - folders = [self _foldersForUID: uid ofType: folderType]; - foldersString - = [self _foldersStringForFolders: [folders objectEnumerator]]; - [responseString appendFormat: @"%@:%@:%@%@\n", uid, - [contact objectForKey: @"cn"], - [contact objectForKey: @"c_email"], - foldersString]; - } - [response appendContentString: responseString]; - [responseString release]; - } - else - [response setStatus: 404]; - - return response; -} - -- (id ) foldersSearchAction -{ - NSString *contact, *folderType; - id result; - LDAPUserManager *um; - - um = [LDAPUserManager sharedUserManager]; - contact = [self queryParameterForKey: @"search"]; - if ([contact length] > 0) - { - folderType = [self queryParameterForKey: @"type"]; - result - = [self _foldersResponseForResults: [um fetchContactsMatching: contact] - withType: folderType]; - } - else - result = [NSException exceptionWithHTTPStatus: 400 - reason: @"missing 'search' parameter"]; - - return result; -} - // - (SOGoContactGCSFolder *) contactFolderForUID: (NSString *) uid // { // SOGoFolder *upperContainer; diff --git a/UI/Contacts/product.plist b/UI/Contacts/product.plist index 1b4d7eb3c..88da1673b 100644 --- a/UI/Contacts/product.plist +++ b/UI/Contacts/product.plist @@ -27,11 +27,6 @@ pageName = "UIxContactFoldersView"; actionName = "contactSearch"; }; - foldersSearch = { - protectedBy = "View"; - pageName = "UIxContactFoldersView"; - actionName = "foldersSearch"; - }; updateAdditionalAddressBooks = { protectedBy = "View"; pageName = "UIxContactFoldersView"; diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 5b6b6364e..bb696b81a 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -24,6 +24,7 @@ #import #import #import + #import #import #import diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index c5f56913e..002e93d41 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import #import @@ -36,6 +37,7 @@ #import #import #import +#import #import #import @@ -230,4 +232,85 @@ static NSString *defaultModule = 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 *response; + NSString *uid, *foldersString; + NSMutableString *responseString; + NSDictionary *contact; + NSEnumerator *contacts; + NSArray *folders; + + response = [context response]; + [response setStatus: 200]; + [response setHeader: @"text/plain; charset=utf-8" + forKey: @"Content-Type"]; + + responseString = [NSMutableString new]; + contacts = [[results allKeys] objectEnumerator]; + while ((contact = [contacts nextObject])) + { + uid = [contact objectForKey: @"c_uid"]; + folders = [results objectForKey: contact]; + foldersString + = [self _foldersStringForFolders: [folders objectEnumerator]]; + [responseString appendFormat: @"%@:%@:%@%@\n", uid, + [contact objectForKey: @"cn"], + [contact objectForKey: @"c_email"], + foldersString]; + } + [response appendContentString: responseString]; + [responseString release]; + + return response; +} + +- (id ) foldersSearchAction +{ + NSString *contact, *folderType; + NSDictionary *folders; + id result; + + 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"]; + } + else + result = [NSException exceptionWithHTTPStatus: 400 + reason: @"missing 'search' parameter"]; + + return result; +} + @end diff --git a/UI/MainUI/product.plist b/UI/MainUI/product.plist index b41123a7c..63e2c5f8e 100644 --- a/UI/MainUI/product.plist +++ b/UI/MainUI/product.plist @@ -113,6 +113,11 @@ pageName = "SOGoUserHomePage"; actionName = "logoff"; }; + foldersSearch = { + protectedBy = "View"; + pageName = "SOGoUserHomePage"; + actionName = "foldersSearch"; + }; }; }; SOGoGroupsFolder = { diff --git a/UI/WebServerResources/UIxContactsUserFolders.js b/UI/WebServerResources/UIxContactsUserFolders.js index 1855cc45e..a984ad055 100644 --- a/UI/WebServerResources/UIxContactsUserFolders.js +++ b/UI/WebServerResources/UIxContactsUserFolders.js @@ -1,8 +1,8 @@ function onSearchFormSubmit() { var searchValue = $("searchValue"); - var url = (ApplicationBaseURL - + "/foldersSearch?ldap-only=YES&search=" + escape(searchValue.value) + var url = (UserFolderURL + + "foldersSearch?search=" + escape(searchValue.value) + "&type=" + window.opener.userFolderType); if (document.userFoldersRequest) { document.userFoldersRequest.aborted = true; @@ -97,6 +97,7 @@ function userFoldersCallback(http) { if (http.status == 200) { var response = http.responseText; div.innerHTML = buildTree(http.responseText); + div.clean = false; var nodes = document.getElementsByClassName("node", $("d")); for (i = 0; i < nodes.length; i++) Event.observe(nodes[i], "click", onFolderTreeItemClick.bindAsEventListener(nodes[i])); @@ -136,9 +137,17 @@ function onConfirmFolderSelection(event) { } } +function onFolderSearchKeyDown(event) { + var div = $("folders"); + if (!div.clean) { + div.innerHTML = ""; + div.clean = true; + } +} + function initUserFoldersWindow() { - configureSearchField(); - Event.observe($("addButton"), "click", onConfirmFolderSelection); + $("searchValue").observe("keydown", onFolderSearchKeyDown); + $("addButton").observe("click", onConfirmFolderSelection); } FastInit.addOnLoad(initUserFoldersWindow); diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index cf006e3e7..6313cd2ea 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -918,7 +918,12 @@ function onSearchKeyDown(event) { if (this.timer) clearTimeout(this.timer); - this.timer = setTimeout("onSearchFormSubmit()", 1000); + if (event.keyCode == 13) { + onSearchFormSubmit(); + event.preventDefault(); + } + else + this.timer = setTimeout("onSearchFormSubmit()", 1000); } function onSearchFormSubmit(event) {