]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1409 d1b88da0-ebda-0310...
authorwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 16 May 2008 20:41:43 +0000 (20:41 +0000)
committerwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 16 May 2008 20:41:43 +0000 (20:41 +0000)
12 files changed:
ChangeLog
SoObjects/SOGo/SOGoContentObject.m
SoObjects/SOGo/SOGoFolder.h
SoObjects/SOGo/SOGoFolder.m
SoObjects/SOGo/SOGoGCSFolder.h
SoObjects/SOGo/SOGoGCSFolder.m
SoObjects/SOGo/SOGoObject.h
SoObjects/SOGo/SOGoObject.m
UI/Common/UIxFolderActions.m
UI/WebServerResources/ContactsUI.js
UI/WebServerResources/SchedulerUI.js
UI/WebServerResources/generic.js

index 9f2635bd5e47491526ebad90a5fc61d86232339e..526682f53c0c0cd841d69edd96fc0102157e013f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2008-05-16  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
 
+       * SoObjects/SOGo/SOGoGCSFolder.m ([SOGoGCSFolder
+       -subscribe:reallyDoinTheNameOf:delegatedUserfromMailInvitation:isMailInvitationinContext:localContext]):
+       published method.
+       ([-folderReference]): no longer distingish between the user owned
+       and the subscribed folders.
+
+       * SoObjects/SOGo/SOGoFolder.m ([SOGoFolder -compare:otherFolder]):
+       no longer use the "_" in the folder's nameInContainer.
+
+       * UI/Common/UIxFolderActions.m ([UIxFolderActions -subscribeAction])
+       ([UIxFolderActions -unsubscribeAction]): use the client object's
+       method for un-/subscribing.
+
+       * SoObjects/SOGo/SOGoObject.m ([SOGoObject
+       -pathArrayToSOGoObject]): removed useless method.
+
        * SoObjects/Appointments/SOGoAppointmentFolder.m
        ([SOGoAppointmentFolder -davCalendarQuery:queryContext]): added
        partial support for the "text-match" caldav directive.
index af4e3b53159d9275b1b3e3f88d1ba2c1b431e2a8..f9714efef99632505e85684ba0825aae356f0291 100644 (file)
 
 - (NSArray *) aclUsers
 {
-  return [container aclUsersForObjectAtPath: [self pathArrayToSOGoObject]];
+  NSMutableArray *pathArray;
+
+  pathArray = [NSMutableArray arrayWithArray: [container pathArrayToFolder]];
+  [pathArray addObject: nameInContainer];
+
+  return pathArray;
 }
 
 - (NSArray *) aclsForUser: (NSString *) uid
index 03f1c934f8b8a5e816ef703d8bc2061ba389e4d7..a4b3772071e01697c8373a4a5009a7b1715b0723 100644 (file)
 @interface SOGoFolder : SOGoObject
 {
   NSMutableString *displayName;
+  BOOL isSubscription;
 }
 
 - (void) setDisplayName: (NSString *) newDisplayName;
 - (NSString *) displayName;
 
+- (void) setIsSubscription: (BOOL) newIsSubscription;
+- (BOOL) isSubscription;
+
+- (NSString *) realNameInContainer;
+
 - (NSString *) folderType;
 - (NSArray *) fetchContentObjectNames;
 
index f931cc496cbc7cb948a3a7da9cbfcc2d4d604b34..3dbbcd551acd6e9591aaa2bac794a6027a414a56 100644 (file)
 - (id) init
 {
   if ((self = [super init]))
-    displayName = nil;
+    {
+      displayName = nil;
+      isSubscription = NO;
+    }
 
   return self;
 }
   return ((displayName) ? displayName : nameInContainer);
 }
 
+- (void) setIsSubscription: (BOOL) newIsSubscription
+{
+  isSubscription = newIsSubscription;
+}
+
+- (BOOL) isSubscription
+{
+  return isSubscription;
+}
+
+- (NSString *) realNameInContainer
+{
+  NSString *realNameInContainer, *ownerName;
+
+  if (isSubscription)
+    {
+      ownerName = [self ownerInContext: context];
+      realNameInContainer
+       = [nameInContainer substringFromIndex: [ownerName length] + 1];
+    }
+  else
+    realNameInContainer = nameInContainer;
+
+  return realNameInContainer;
+}
+
 - (NSString *) folderType
 {
   [self subclassResponsibility: _cmd];
 /* sorting */
 - (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder
 {
-  NSArray *thisElements, *otherElements;
-  unsigned thisCount, otherCount;
   NSComparisonResult comparison;
 
-  thisElements = [nameInContainer componentsSeparatedByString: @"_"];
-  otherElements = [[otherFolder nameInContainer]
-                   componentsSeparatedByString: @"_"];
-  thisCount = [thisElements count];
-  otherCount = [otherElements count];
-  if (thisCount == otherCount)
-    {
-      if (thisCount == 1)
-       comparison = NSOrderedSame;
-      else
-       comparison = [[thisElements objectAtIndex: 0]
-                      compare: [otherElements objectAtIndex: 0]];
-    }
+  if (isSubscription == [otherFolder isSubscription])
+    comparison = NSOrderedSame;
   else
     {
-      if (thisCount > otherCount)
+      if (isSubscription)
        comparison = NSOrderedDescending;
       else
        comparison = NSOrderedAscending;
 
 - (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder
 {
-  NSString *otherName;
+  NSString *selfName, *otherName;
   NSComparisonResult comparison;
 
-  otherName = [otherFolder nameInContainer];
-  if ([nameInContainer hasSuffix: @"personal"])
+  selfName = [self realNameInContainer];
+  otherName = [otherFolder realNameInContainer];
+  if ([selfName isEqualToString: @"personal"])
     {
-      if ([otherName hasSuffix: @"personal"])
-       comparison = [nameInContainer compare: otherName];
+      if ([otherName isEqualToString: @"personal"])
+       comparison = NSOrderedSame;
       else
        comparison = NSOrderedAscending;
     }
   else
     {
-      if ([otherName hasSuffix: @"personal"])
+      if ([otherName isEqualToString: @"personal"])
        comparison = NSOrderedDescending;
       else
-       comparison = NSOrderedSame;
+       comparison = [selfName compare: otherName];
     }
 
   return comparison;
index 54214dff2b4626ee9e9ed8b5cb13d5ba8a0a0ead..c64f879ca2e9ec7c4380929579c42ada421facf7 100644 (file)
@@ -30,6 +30,8 @@
 @class NSString;
 
 @class GCSFolder;
+@class WOContext;
+@class WOResponse;
 
 /*
   SOGoGCSFolder
@@ -60,6 +62,7 @@
 - (GCSFolder *) ocsFolder;
 
 - (NSString *) folderReference;
+- (NSArray *) pathArrayToFolder;
 
 /* lower level fetches */
 - (BOOL) nameExistsInFolder: (NSString *) objectName;
 - (NSException *) delete;
 - (void) renameTo: (NSString *) newName;
 
+- (WOResponse *) subscribe: (BOOL) reallyDo
+              inTheNameOf: (NSString *) delegatedUser
+       fromMailInvitation: (BOOL) isMailInvitation
+                inContext: (WOContext *) localContext;
+
 /* acls as a container */
 - (NSArray *) aclUsersForObjectAtPath: (NSArray *) objectPathArray;
 - (NSArray *) aclsForUser: (NSString *) uid
index 6c4e990503ca9c9c9977c3b5878304661d71d295..893f12ef0a4fa369fc3ee07e1ec901ac3981bafc 100644 (file)
@@ -138,10 +138,13 @@ static BOOL sendFolderAdvisories = NO;
 {
   id newFolder;
   NSArray *elements, *pathElements;
-  NSString *path, *objectPath, *login, *ocsName, *folderName;
+  NSString *path, *objectPath, *login, *currentUser, *ocsName, *folderName;
+  WOContext *context;
 
   elements = [reference componentsSeparatedByString: @":"];
   login = [elements objectAtIndex: 0];
+  context = [[WOApplication application] context];
+  currentUser = [[context activeUser] login];
   objectPath = [elements objectAtIndex: 1];
   pathElements = [objectPath componentsSeparatedByString: @"/"];
   if ([pathElements count] > 1)
@@ -155,6 +158,7 @@ static BOOL sendFolderAdvisories = NO;
   newFolder = [self objectWithName: folderName inContainer: aContainer];
   [newFolder setOCSPath: path];
   [newFolder setOwner: login];
+  [newFolder setIsSubscription: ![login isEqualToString: currentUser]];
   if (![newFolder displayName])
     newFolder = nil;
 
@@ -284,27 +288,21 @@ static BOOL sendFolderAdvisories = NO;
 
 - (NSString *) folderReference
 {
-  NSString *login, *reference, *realName;
-  NSArray *nameComponents;
+  return [NSString stringWithFormat: @"%@:%@/%@",
+                  owner,
+                  [container nameInContainer],
+                  [self realNameInContainer]];
+}
 
-  login = [[context activeUser] login];
-  if ([owner isEqualToString: login])
-    reference = nameInContainer;
-  else
-    {
-      nameComponents = [nameInContainer componentsSeparatedByString: @"_"];
-      if ([nameComponents count] > 1)
-       realName = [nameComponents objectAtIndex: 1];
-      else
-       realName = nameInContainer;
+- (NSArray *) pathArrayToFolder
+{
+  NSArray *basePathElements;
+  unsigned int max;
 
-      reference = [NSString stringWithFormat: @"%@:%@/%@",
-                           owner,
-                           [container nameInContainer],
-                           realName];
-    }
+  basePathElements = [[self ocsPath] componentsSeparatedByString: @"/"];
+  max = [basePathElements count];
 
-  return reference;
+  return [basePathElements subarrayWithRange: NSMakeRange (2, max - 2)];
 }
 
 - (NSString *) davDisplayName
@@ -497,7 +495,6 @@ static BOOL sendFolderAdvisories = NO;
     }
 }
 
-#warning this method is dirty code
 - (NSDictionary *) fetchContentStringsAndNamesOfAllObjects
 {
   NSDictionary *files;
@@ -508,27 +505,23 @@ static BOOL sendFolderAdvisories = NO;
       [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
       return nil;
     }
-  if ([files isKindOfClass:[NSException class]])
-    return files;
+
   return files;
 }
 
 #warning this code should be cleaned up
-#warning this code is a dup of UIxFolderActions,\
-         we should remove the methods there
 - (void) _subscribeUser: (SOGoUser *) subscribingUser
               reallyDo: (BOOL) reallyDo
+     fromMailInvitation: (BOOL) isMailInvitation
             inResponse: (WOResponse *) response
 {
   NSMutableArray *folderSubscription;
-  NSString *subscriptionPointer, *baseFolder, *folder;
+  NSString *subscriptionPointer, *mailInvitationURL;
   NSUserDefaults *ud;
-  NSArray *realFolderPath;
   NSMutableDictionary *moduleSettings;
 
   ud = [subscribingUser userSettings];
-  baseFolder = [container nameInContainer];
-  moduleSettings = [ud objectForKey: baseFolder];
+  moduleSettings = [ud objectForKey: [container nameInContainer]];
 
   if ([owner isEqualToString: [subscribingUser login]])
     {
@@ -548,12 +541,6 @@ static BOOL sendFolderAdvisories = NO;
                          forKey: @"SubscribedFolders"];
        }
 
-      realFolderPath = [nameInContainer componentsSeparatedByString: @"_"];
-      if ([realFolderPath count] > 1)
-       folder = [realFolderPath objectAtIndex: 1];
-      else
-       folder = [realFolderPath objectAtIndex: 0];
-
       subscriptionPointer = [self folderReference];
       if (reallyDo)
        [folderSubscription addObjectUniquely: subscriptionPointer];
@@ -562,13 +549,23 @@ static BOOL sendFolderAdvisories = NO;
 
       [ud synchronize];
 
-      [response setStatus: 204];
+      if (isMailInvitation)
+       {
+         mailInvitationURL = [[self soURLToBaseContainerForCurrentUser]
+                               absoluteString];
+         [response setStatus: 302];
+         [response setHeader: mailInvitationURL
+                   forKey: @"location"];
+       }
+      else
+       [response setStatus: 204];
     }
 }
 
-- (WOResponse *) _subscribe: (BOOL) reallyDo
-               inTheNameOf: (NSString *) delegatedUser
-                 inContext: (WOContext *) localContext
+- (WOResponse *) subscribe: (BOOL) reallyDo
+              inTheNameOf: (NSString *) delegatedUser
+       fromMailInvitation: (BOOL) isMailInvitation
+                inContext: (WOContext *) localContext
 {
   WOResponse *response;
   SOGoUser *currentUser, *subscriptionUser;
@@ -591,6 +588,7 @@ static BOOL sendFolderAdvisories = NO;
   if (validRequest)
     [self _subscribeUser: subscriptionUser
          reallyDo: reallyDo
+         fromMailInvitation: isMailInvitation
          inResponse: response];
   else
     {
@@ -616,15 +614,17 @@ static BOOL sendFolderAdvisories = NO;
 
 - (id <WOActionResults>) davSubscribe: (WOContext *) queryContext
 {
-  return [self _subscribe: YES
+  return [self subscribe: YES
               inTheNameOf: [self _parseDAVDelegatedUser: queryContext]
+              fromMailInvitation: NO
               inContext: queryContext];
 }
 
 - (id <WOActionResults>) davUnsubscribe: (WOContext *) queryContext
 {
-  return [self _subscribe: NO
+  return [self subscribe: NO
               inTheNameOf: [self _parseDAVDelegatedUser: queryContext]
+              fromMailInvitation: NO
               inContext: queryContext];
 }
 
@@ -784,7 +784,7 @@ static BOOL sendFolderAdvisories = NO;
 /* acls */
 - (NSArray *) aclUsers
 {
-  return [self aclUsersForObjectAtPath: [self pathArrayToSOGoObject]];
+  return [self aclUsersForObjectAtPath: [self pathArrayToFolder]];
 }
 
 - (NSArray *) aclsForUser: (NSString *) uid
@@ -793,8 +793,7 @@ static BOOL sendFolderAdvisories = NO;
   NSArray *ownAcls, *containerAcls;
 
   acls = [NSMutableArray array];
-  ownAcls = [self aclsForUser: uid
-                 forObjectAtPath: [self pathArrayToSOGoObject]];
+  ownAcls = [self aclsForUser: uid forObjectAtPath: [self pathArrayToFolder]];
   [acls addObjectsFromArray: ownAcls];
   if ([container respondsToSelector: @selector (aclsForUser:)])
     {
@@ -815,13 +814,13 @@ static BOOL sendFolderAdvisories = NO;
 {
   return [self setRoles: roles
                forUser: uid
-               forObjectAtPath: [self pathArrayToSOGoObject]];
+               forObjectAtPath: [self pathArrayToFolder]];
 }
 
 - (void) removeAclsForUsers: (NSArray *) users
 {
   return [self removeAclsForUsers: users
-               forObjectAtPath: [self pathArrayToSOGoObject]];
+               forObjectAtPath: [self pathArrayToFolder]];
 }
 
 - (NSString *) defaultUserID
index eb1736f2ff0677cb6e1b2edbfdbace69221e0942..d800d74c3466dcd7f5d1b6a9f6f2d58be294ff39 100644 (file)
@@ -82,8 +82,6 @@
 - (NSString *) nameInContainer;
 - (id) container;
 
-- (NSArray *) pathArrayToSOGoObject;
-
 - (NSURL *) davURL;
 - (NSURL *) soURL;
 - (NSURL *) soURLToBaseContainerForUser: (NSString *) uid;
index b3398a6761a6fe5fe8ad575343d91747ea0dd714..fccb4e359faeb887bc147f341d5fe984ef0c19c0 100644 (file)
@@ -246,33 +246,6 @@ static NSDictionary *reportMap = nil;
   return container;
 }
 
-- (NSArray *) pathArrayToSOGoObject
-{
-  NSMutableArray *realPathArray;
-  NSString *objectName;
-  NSArray *objectDescription;
-
-  realPathArray
-    = [NSMutableArray arrayWithArray: [self pathArrayToSoObject]];
-  if ([realPathArray count] > 2)
-    {
-      objectName = [realPathArray objectAtIndex: 2];
-      if ([objectName isKindOfClass: [NSString class]])
-       {
-         objectDescription = [objectName componentsSeparatedByString: @"_"];
-         if ([objectDescription count] > 1)
-           {
-             [realPathArray replaceObjectAtIndex: 0
-                            withObject: [objectDescription objectAtIndex: 0]];
-             [realPathArray replaceObjectAtIndex: 2
-                            withObject: [objectDescription objectAtIndex: 1]];
-           }
-       }
-    }
-
-  return realPathArray;
-}
-
 /* ownership */
 
 - (void) setOwner: (NSString *) newOwner
index 9fde4a2febc360861ba0e56e9c23514be0c61b68..fae4f02b4d22a390c5dacc8652eaad1033506a7f 100644 (file)
@@ -45,9 +45,6 @@
 
 @implementation UIxFolderActions
 
-#warning some of this code could probably be moved in one of the \
-         clientObject classes...
-
 - (void) _setupContext
 {
   NSString *mailInvitationParam;
   isMailInvitation = [mailInvitationParam boolValue];
 }
 
-- (WOResponse *) _realSubscribe: (BOOL) reallyDo
-{
-  WOResponse *response;
-  NSMutableArray *folderSubscription;
-  NSString *mailInvitationURL, *subscriptionPointer;
-
-  if ([owner isEqualToString: login])
-    {
-      response = [self responseWithStatus: 403];
-      [response appendContentString:
-                @"You cannot (un)subscribe to a folder that you own!"];
-    }
-  else
-    {
-      folderSubscription
-       = [moduleSettings objectForKey: @"SubscribedFolders"];
-      if (!(folderSubscription
-           && [folderSubscription isKindOfClass: [NSMutableArray class]]))
-       {
-         folderSubscription = [NSMutableArray array];
-         [moduleSettings setObject: folderSubscription
-                         forKey: @"SubscribedFolders"];
-       }
-      subscriptionPointer = [[self clientObject] folderReference];
-      if (reallyDo)
-       [folderSubscription addObjectUniquely: subscriptionPointer];
-      else
-       [folderSubscription removeObject: subscriptionPointer];
-
-      [ud synchronize];
-
-      if (isMailInvitation)
-       {
-         mailInvitationURL
-           = [[clientObject soURLToBaseContainerForCurrentUser]
-               absoluteString];
-         response = [self responseWithStatus: 302];
-         [response setHeader: mailInvitationURL
-                   forKey: @"location"];
-       }
-      else
-       response = [self responseWith204];
-    }
-
-  return response;
-}
-
 - (WOResponse *) subscribeAction
 {
   [self _setupContext];
 
-  return [self _realSubscribe: YES];
+  return [clientObject subscribe: YES
+                      inTheNameOf: nil
+                      fromMailInvitation: isMailInvitation
+                      inContext: context];
 }
 
 - (WOResponse *) unsubscribeAction
 {
   [self _setupContext];
 
-  return [self _realSubscribe: NO];
+  return [clientObject subscribe: NO
+                      inTheNameOf: nil
+                      fromMailInvitation: isMailInvitation
+                      inContext: context];
 }
 
 - (WOResponse *) canAccessContentAction
index a9155fad4f3794d37a330281a191e12df4d356c4..4e3410519830694f8a333d2a62fb858d41777546 100644 (file)
@@ -623,12 +623,13 @@ function onFolderUnsubscribeCB(folderId) {
 function onAddressBookRemove(event) {
   var selector = $("contactFolders");
   var nodes = selector.getSelectedNodes();
-  if (nodes.length > 0) { 
+  if (nodes.length > 0) {
     nodes[0].deselect();
-    var folderId = nodes[0].getAttribute("id");
-    var folderIdElements = folderId.split("_");
-    if (folderIdElements.length > 1)
-      unsubscribeFromFolder(folderId, onFolderUnsubscribeCB, folderId);
+    var owner = nodes[0].getAttribute("owner");
+    if (owner != UserLogin) {
+      var folderId = nodes[0].getAttribute("id");
+      unsubscribeFromFolder(folderId, owner, onFolderUnsubscribeCB, folderId);
+    }
     else {
       var abId = folderIdElements[0].substr(1);
       deletePersonalAddressBook(abId);
index be36e8c5bc821646a76392f6611bab37be2ac693..a9eef319f6762518c53c778967613cc865e7a706 100644 (file)
@@ -1754,10 +1754,11 @@ function onCalendarRemove(event) {
     var nodes = $("calendarList").getSelectedNodes();
     for (var i = 0; i < nodes.length; i++) {
       nodes[i].deselect();
-      var folderId = nodes[i].getAttribute("id");
-      var folderIdElements = folderId.split("_");
-      if (folderIdElements.length > 1) {
-       unsubscribeFromFolder(folderId, onFolderUnsubscribeCB, folderId);
+      var owner = nodes[i].getAttribute("owner");
+      if (owner != UserLogin) {
+       var folderId = nodes[i].getAttribute("id");
+       unsubscribeFromFolder(folderId, owner,
+                             onFolderUnsubscribeCB, folderId);
       }
       else
        deletePersonalCalendar(folderIdElements[0]);
index 7c2e36b5ae120c2ba25049da97c8b1007b61c5e7..a47bbc7c77ade88a6d77fb8eaad6d62e12444d14 100644 (file)
@@ -1061,18 +1061,16 @@ function folderUnsubscriptionCallback(http) {
   }
 }
 
-function unsubscribeFromFolder(folder, refreshCallback, refreshCallbackData) {
+function unsubscribeFromFolder(folder, owner, refreshCallback,
+                              refreshCallbackData) {
   if (document.body.hasClassName("popup")) {
     window.opener.unsubscribeFromFolder(folder, refreshCallback,
                                        refreshCallbackData);
   }
   else {
-    var folderData = folder.split("_");
-    var username = folderData[0];
-    var folderPath = folderData[1];
-    if (username.startsWith('/'))
-      username = username.substring(1);
-    if (username != UserLogin) {
+    if (owner.startsWith('/'))
+      owner = owner.substring(1);
+    if (owner != UserLogin) {
       var url = (ApplicationBaseURL + folder + "/unsubscribe");
       removeFolderRequestCount++;
       var rfCbData = { method: refreshCallback, data: refreshCallbackData };