2006-12-14 21:20:40 +01:00
|
|
|
/* UIxAclEditor.m - this file is part of SOGo
|
|
|
|
*
|
2010-08-11 19:23:59 +02:00
|
|
|
* Copyright (C) 2006-2010 Inverse inc.
|
2006-12-14 21:20:40 +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>
|
2007-01-31 19:42:59 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <NGObjWeb/SoUser.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-12-07 00:09:58 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2010-01-19 13:28:10 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/SOGoContentObject.h>
|
|
|
|
#import <SOGo/SOGoGCSFolder.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2010-06-07 15:15:20 +02:00
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
2010-01-19 13:28:10 +01:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
#import "UIxAclEditor.h"
|
|
|
|
|
|
|
|
@implementation UIxAclEditor
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2007-05-19 02:43:40 +02:00
|
|
|
aclUsers = nil;
|
2006-12-14 21:20:40 +01:00
|
|
|
prepared = NO;
|
2006-12-20 17:43:55 +01:00
|
|
|
publishInFreeBusy = NO;
|
2006-12-14 21:20:40 +01:00
|
|
|
users = [NSMutableArray new];
|
2007-03-29 20:09:18 +02:00
|
|
|
currentUser = nil;
|
2007-05-22 21:30:36 +02:00
|
|
|
defaultUserID = nil;
|
2007-04-17 15:56:19 +02:00
|
|
|
savedUIDs = nil;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
[savedUIDs release];
|
2006-12-14 21:20:40 +01:00
|
|
|
[users release];
|
2007-03-29 20:09:18 +02:00
|
|
|
[currentUser release];
|
2007-05-22 21:30:36 +02:00
|
|
|
[defaultUserID release];
|
2006-12-14 21:20:40 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (NSArray *) aclsForObject
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-05-19 02:43:40 +02:00
|
|
|
if (!aclUsers)
|
|
|
|
aclUsers = [[self clientObject] aclUsers];
|
2006-12-14 21:20:40 +01:00
|
|
|
|
2007-05-19 02:43:40 +02:00
|
|
|
return aclUsers;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:07:31 +02:00
|
|
|
- (NSString *) defaultUserID
|
|
|
|
{
|
2007-05-22 20:40:45 +02:00
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
|
|
|
|
|
|
|
return defaultUserID;
|
2007-05-18 01:07:31 +02:00
|
|
|
}
|
|
|
|
|
2010-06-07 23:30:36 +02:00
|
|
|
- (NSArray *) usersForObject
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
|
|
|
NSEnumerator *aclsEnum;
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *currentUID, *ownerLogin;
|
2006-12-14 21:20:40 +01:00
|
|
|
|
2010-06-07 23:30:36 +02:00
|
|
|
if (!prepared)
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2010-06-07 23:30:36 +02:00
|
|
|
ownerLogin = [[self clientObject] ownerInContext: context];
|
|
|
|
if (!defaultUserID)
|
|
|
|
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
|
|
|
|
|
|
|
|
aclsEnum = [[self aclsForObject] objectEnumerator];
|
|
|
|
while ((currentUID = [aclsEnum nextObject]))
|
|
|
|
{
|
|
|
|
if (!([currentUID isEqualToString: ownerLogin]
|
|
|
|
|| [currentUID isEqualToString: defaultUserID]
|
|
|
|
|| [currentUID isEqualToString: @"anonymous"]))
|
|
|
|
[users addObjectUniquely: currentUID];
|
|
|
|
}
|
|
|
|
prepared = YES;
|
2006-12-14 21:20:40 +01:00
|
|
|
}
|
2007-05-22 20:40:45 +02:00
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
return users;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:09:18 +02:00
|
|
|
- (void) setCurrentUser: (NSString *) newCurrentUser
|
|
|
|
{
|
|
|
|
ASSIGN (currentUser, newCurrentUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUser
|
|
|
|
{
|
2011-10-21 22:12:38 +02:00
|
|
|
return ([currentUser hasPrefix: @"@"]
|
|
|
|
? [currentUser substringFromIndex: 1]
|
|
|
|
: currentUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUserClass
|
|
|
|
{
|
|
|
|
return ([currentUser hasPrefix: @"@"]
|
|
|
|
? @"normal-group"
|
|
|
|
: @"normal-user");
|
2007-03-29 20:09:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUserDisplayName
|
|
|
|
{
|
2010-06-07 23:30:36 +02:00
|
|
|
SOGoUserManager *um;
|
|
|
|
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
2011-10-21 22:12:38 +02:00
|
|
|
return [um getFullEmailForUID: [self currentUser]];
|
2007-03-29 20:09:18 +02:00
|
|
|
}
|
|
|
|
|
2010-01-20 17:28:56 +01:00
|
|
|
- (BOOL) canSubscribeUsers
|
|
|
|
{
|
|
|
|
return [[self clientObject]
|
2012-04-18 19:39:11 +02:00
|
|
|
respondsToSelector: @selector (subscribeUserOrGroup:reallyDo:)];
|
2010-01-20 17:28:56 +01:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
- (BOOL) currentUserIsSubscribed
|
|
|
|
{
|
|
|
|
SOGoGCSFolder *folder;
|
|
|
|
|
|
|
|
folder = [self clientObject];
|
|
|
|
|
|
|
|
return ([folder respondsToSelector: @selector (userIsSubscriber:)]
|
|
|
|
&& [folder userIsSubscriber: currentUser]);
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (void) setUserUIDS: (NSString *) retainedUsers
|
|
|
|
{
|
|
|
|
if ([retainedUsers length] > 0)
|
2009-10-13 16:04:02 +02:00
|
|
|
{
|
|
|
|
savedUIDs = [retainedUsers componentsSeparatedByString: @","];
|
|
|
|
[savedUIDs retain];
|
|
|
|
}
|
2007-04-17 15:56:19 +02:00
|
|
|
else
|
|
|
|
savedUIDs = [NSArray new];
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
- (NSString *) folderID
|
|
|
|
{
|
|
|
|
return [[self clientObject] nameInContainer];
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext *) context
|
2006-12-20 17:43:55 +01:00
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
return ([[request method] isEqualToString: @"POST"]);
|
2006-12-20 17:43:55 +01:00
|
|
|
}
|
|
|
|
|
2007-04-17 15:56:19 +02:00
|
|
|
- (id <WOActionResults>) saveAclsAction
|
2006-12-14 21:20:40 +01:00
|
|
|
{
|
2007-04-17 15:56:19 +02:00
|
|
|
NSEnumerator *aclsEnum;
|
2006-12-14 21:20:40 +01:00
|
|
|
SOGoObject *clientObject;
|
2007-04-17 15:56:19 +02:00
|
|
|
NSString *currentUID, *ownerLogin;
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
clientObject = [self clientObject];
|
2007-04-17 15:56:19 +02:00
|
|
|
ownerLogin = [clientObject ownerInContext: context];
|
|
|
|
aclsEnum = [[self aclsForObject] objectEnumerator];
|
2010-06-07 23:30:36 +02:00
|
|
|
while ((currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"]))
|
|
|
|
if ([currentUID isEqualToString: ownerLogin]
|
|
|
|
|| [savedUIDs containsObject: currentUID])
|
|
|
|
[users removeObject: currentUID];
|
2007-04-17 15:56:19 +02:00
|
|
|
[clientObject removeAclsForUsers: users];
|
2006-12-14 21:20:40 +01:00
|
|
|
|
|
|
|
return [self jsCloseWithRefreshMethod: nil];
|
|
|
|
}
|
|
|
|
|
2010-06-07 15:15:20 +02:00
|
|
|
- (BOOL) isPublicAccessEnabled
|
|
|
|
{
|
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults]
|
|
|
|
enablePublicAccess];
|
|
|
|
}
|
2007-04-17 15:56:19 +02:00
|
|
|
|
2006-12-14 21:20:40 +01:00
|
|
|
@end
|