2007-11-07 23:27:44 +01:00
|
|
|
/* SOGoFolder.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2007 Inverse inc.
|
2007-11-07 23:27:44 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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 <Foundation/NSArray.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-11-07 23:27:44 +01:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
|
2007-11-09 21:12:07 +01:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
#import "NSObject+DAV.h"
|
2007-11-07 23:27:44 +01:00
|
|
|
#import "NSString+Utilities.h"
|
|
|
|
|
2007-11-29 17:14:11 +01:00
|
|
|
#import "SOGoPermissions.h"
|
2008-05-03 01:08:15 +02:00
|
|
|
#import "SOGoWebDAVAclManager.h"
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
#import "SOGoFolder.h"
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
@interface SOGoObject (SOGoDAVHelpers)
|
|
|
|
|
|
|
|
- (void) _fillArrayWithPrincipalsOwnedBySelf: (NSMutableArray *) hrefs;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
@implementation SOGoFolder
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
+ (SOGoWebDAVAclManager *) webdavAclManager
|
|
|
|
{
|
2008-12-15 23:27:45 +01:00
|
|
|
static SOGoWebDAVAclManager *webdavAclManager = nil;
|
2008-05-03 01:08:15 +02:00
|
|
|
|
|
|
|
if (!webdavAclManager)
|
|
|
|
{
|
|
|
|
webdavAclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"read", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"all", @"DAV:")];
|
|
|
|
[webdavAclManager registerDAVPermission: davElement (@"read-current-user-privilege-set", @"DAV:")
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"read", @"DAV:")];
|
|
|
|
}
|
|
|
|
|
|
|
|
return webdavAclManager;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
2008-05-16 22:33:55 +02:00
|
|
|
{
|
|
|
|
displayName = nil;
|
|
|
|
isSubscription = NO;
|
|
|
|
}
|
2007-11-07 23:27:44 +01:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[displayName release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDisplayName: (NSString *) newDisplayName
|
|
|
|
{
|
|
|
|
ASSIGN (displayName, newDisplayName);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
2009-04-01 15:49:24 +02:00
|
|
|
return ((id)displayName ? (id)displayName : (id)nameInContainer);
|
2007-11-07 23:27:44 +01:00
|
|
|
}
|
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
- (void) setIsSubscription: (BOOL) newIsSubscription
|
|
|
|
{
|
|
|
|
isSubscription = newIsSubscription;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSubscription
|
|
|
|
{
|
|
|
|
return isSubscription;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) realNameInContainer
|
|
|
|
{
|
|
|
|
NSString *realNameInContainer, *ownerName;
|
|
|
|
|
|
|
|
if (isSubscription)
|
|
|
|
{
|
2009-01-21 18:01:06 +01:00
|
|
|
ownerName = [[self ownerInContext: context] asCSSIdentifier];
|
2008-05-16 22:33:55 +02:00
|
|
|
realNameInContainer
|
|
|
|
= [nameInContainer substringFromIndex: [ownerName length] + 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
realNameInContainer = nameInContainer;
|
|
|
|
|
|
|
|
return realNameInContainer;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
- (NSString *) folderType
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-02-12 16:48:53 +01:00
|
|
|
#warning we should remove this method
|
|
|
|
- (NSArray *) toOneRelationshipKeys
|
|
|
|
{
|
|
|
|
return [self fetchContentObjectNames];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchContentObjectNames
|
|
|
|
{
|
|
|
|
return [NSArray array];
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-03-07 23:14:44 +01:00
|
|
|
- (BOOL) isValidContentName: (NSString *) name
|
|
|
|
{
|
|
|
|
return ([name length] > 0);
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) httpURLForAdvisoryToUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return [[self soURL] absoluteString];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) resourceURLForAdvisoryToUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return [[self davURL] absoluteString];
|
|
|
|
}
|
|
|
|
|
2007-11-08 00:35:56 +01:00
|
|
|
/* sorting */
|
|
|
|
- (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder
|
|
|
|
{
|
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
if (isSubscription == [otherFolder isSubscription])
|
|
|
|
comparison = NSOrderedSame;
|
2007-11-08 00:35:56 +01:00
|
|
|
else
|
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
if (isSubscription)
|
2007-11-08 00:35:56 +01:00
|
|
|
comparison = NSOrderedDescending;
|
|
|
|
else
|
|
|
|
comparison = NSOrderedAscending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return comparison;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder
|
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
NSString *selfName, *otherName;
|
2007-11-08 00:35:56 +01:00
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
2008-05-16 22:33:55 +02:00
|
|
|
selfName = [self realNameInContainer];
|
|
|
|
otherName = [otherFolder realNameInContainer];
|
|
|
|
if ([selfName isEqualToString: @"personal"])
|
2007-11-08 00:35:56 +01:00
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
if ([otherName isEqualToString: @"personal"])
|
|
|
|
comparison = NSOrderedSame;
|
2007-11-08 00:35:56 +01:00
|
|
|
else
|
|
|
|
comparison = NSOrderedAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-16 22:33:55 +02:00
|
|
|
if ([otherName isEqualToString: @"personal"])
|
2007-11-08 00:35:56 +01:00
|
|
|
comparison = NSOrderedDescending;
|
|
|
|
else
|
2008-08-25 22:52:48 +02:00
|
|
|
comparison = NSOrderedSame;
|
2007-11-08 00:35:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return comparison;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSComparisonResult) compare: (id) otherFolder
|
|
|
|
{
|
|
|
|
NSComparisonResult comparison;
|
|
|
|
|
|
|
|
comparison = [self _compareByOrigin: otherFolder];
|
|
|
|
if (comparison == NSOrderedSame)
|
|
|
|
{
|
|
|
|
comparison = [self _compareByNameInContainer: otherFolder];
|
|
|
|
if (comparison == NSOrderedSame)
|
|
|
|
comparison
|
|
|
|
= [[self displayName]
|
|
|
|
localizedCaseInsensitiveCompare: [otherFolder displayName]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return comparison;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
/* WebDAV */
|
|
|
|
|
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"httpd/unix-directory";
|
|
|
|
}
|
|
|
|
|
2007-11-09 21:12:07 +01:00
|
|
|
- (NSArray *) davResourceType
|
|
|
|
{
|
|
|
|
NSArray *rType, *groupDavCollection;
|
|
|
|
|
|
|
|
if ([self respondsToSelector: @selector (groupDavResourceType)])
|
|
|
|
{
|
|
|
|
groupDavCollection
|
|
|
|
= [NSArray arrayWithObjects: [self groupDavResourceType],
|
|
|
|
XMLNS_GROUPDAV, nil];
|
|
|
|
rType = [NSArray arrayWithObjects: @"collection", groupDavCollection,
|
|
|
|
nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rType = [NSArray arrayWithObject: @"collection"];
|
|
|
|
|
|
|
|
return rType;
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
/* web dav acl helper */
|
|
|
|
- (void) _fillArrayWithPrincipalsOwnedBySelf: (NSMutableArray *) hrefs
|
|
|
|
{
|
|
|
|
NSEnumerator *children;
|
|
|
|
NSString *currentKey;
|
|
|
|
|
|
|
|
[super _fillArrayWithPrincipalsOwnedBySelf: hrefs];
|
|
|
|
children = [[self toOneRelationshipKeys] objectEnumerator];
|
|
|
|
while ((currentKey = [children nextObject]))
|
|
|
|
[[self lookupName: currentKey inContext: context
|
|
|
|
acquire: NO] _fillArrayWithPrincipalsOwnedBySelf: hrefs];
|
|
|
|
|
|
|
|
children = [[self toManyRelationshipKeys] objectEnumerator];
|
|
|
|
while ((currentKey = [children nextObject]))
|
|
|
|
[[self lookupName: currentKey inContext: context
|
|
|
|
acquire: NO] _fillArrayWithPrincipalsOwnedBySelf: hrefs];
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
/* folder type */
|
|
|
|
|
2007-11-20 20:15:26 +01:00
|
|
|
- (BOOL) isEqual: (id) otherFolder
|
|
|
|
{
|
|
|
|
return ([otherFolder class] == [self class]
|
|
|
|
&& [container isEqual: [otherFolder container]]
|
|
|
|
&& [nameInContainer
|
|
|
|
isEqualToString: [otherFolder nameInContainer]]);
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
- (NSString *) outlookFolderClass
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* acls */
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
- (NSString *) defaultUserID
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-11-29 17:14:11 +01:00
|
|
|
- (NSArray *) subscriptionRoles
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: SoRole_Owner, SOGoRole_ObjectViewer,
|
|
|
|
SOGoRole_ObjectEditor, SOGoRole_ObjectCreator,
|
2008-02-20 18:35:11 +01:00
|
|
|
SOGoRole_ObjectEraser, nil];
|
2007-11-29 17:14:11 +01:00
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
- (NSArray *) aclUsers
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-11-07 23:27:44 +01:00
|
|
|
@end
|