2007-04-25 00:36:20 +02:00
|
|
|
/* UIxCalUserRightsEditor.m - this file is part of SOGo
|
|
|
|
*
|
2015-06-02 17:14:03 +02:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-04-25 00:36:20 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-04-20 23:30:17 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2015-04-24 22:07:48 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-04-25 00:36:20 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
|
|
|
|
|
|
|
#import "UIxCalUserRightsEditor.h"
|
|
|
|
|
|
|
|
@implementation UIxCalUserRightsEditor
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
currentRight = nil;
|
|
|
|
rights = [NSMutableDictionary new];
|
|
|
|
[rights setObject: @"None" forKey: @"Public"];
|
|
|
|
[rights setObject: @"None" forKey: @"Private"];
|
|
|
|
[rights setObject: @"None" forKey: @"Confidential"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[currentRight release];
|
|
|
|
[rights release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) prepareRightsForm
|
|
|
|
{
|
|
|
|
NSEnumerator *roles, *types;
|
|
|
|
NSString *role, *type;
|
|
|
|
unsigned int length;
|
|
|
|
|
|
|
|
roles = [userRights objectEnumerator];
|
|
|
|
role = [roles nextObject];
|
|
|
|
while (role)
|
|
|
|
{
|
|
|
|
types = [[self rightTypes] objectEnumerator];
|
|
|
|
type = [types nextObject];
|
|
|
|
while (type)
|
|
|
|
{
|
|
|
|
if ([role hasPrefix: type])
|
|
|
|
{
|
|
|
|
length = [type length];
|
|
|
|
[rights setObject: [role substringFromIndex: length]
|
|
|
|
forKey: type];
|
|
|
|
}
|
|
|
|
type = [types nextObject];
|
|
|
|
}
|
|
|
|
role = [roles nextObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _rightsForType: (NSString *) type
|
|
|
|
{
|
|
|
|
NSMutableArray *rightsForType;
|
|
|
|
NSEnumerator *commonRights;
|
|
|
|
NSString *currentCommonRight;
|
|
|
|
|
2010-06-03 16:43:38 +02:00
|
|
|
rightsForType = [NSMutableArray arrayWithCapacity: 5];
|
2007-04-25 00:36:20 +02:00
|
|
|
commonRights = [[self objectRights] objectEnumerator];
|
2010-06-03 16:43:38 +02:00
|
|
|
while ((currentCommonRight = [commonRights nextObject]))
|
|
|
|
[rightsForType addObject: [NSString stringWithFormat: @"%@%@",
|
|
|
|
type, currentCommonRight]];
|
2007-04-25 00:36:20 +02:00
|
|
|
|
|
|
|
return rightsForType;
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:14:03 +02:00
|
|
|
/**
|
|
|
|
* @see [UIxUserRightsEditor userRightsAction]
|
|
|
|
*/
|
2015-04-24 22:07:48 +02:00
|
|
|
- (NSDictionary *) userRightsForObject
|
|
|
|
{
|
|
|
|
NSMutableDictionary *d;
|
|
|
|
|
|
|
|
[self prepareRightsForm];
|
|
|
|
|
|
|
|
d = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool:[self userCanCreateObjects]], @"canCreateObjects",
|
|
|
|
[NSNumber numberWithBool:[self userCanEraseObjects]], @"canEraseObjects",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
[d addEntriesFromDictionary: rights];
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:14:03 +02:00
|
|
|
/**
|
|
|
|
* @see [UIxUserRightsEditor saveUserRightsAction]
|
|
|
|
*/
|
2015-04-24 22:07:48 +02:00
|
|
|
- (void) updateRights: (NSDictionary *) newRights
|
2007-04-25 00:36:20 +02:00
|
|
|
{
|
|
|
|
NSEnumerator *types;
|
|
|
|
NSString *currentType, *currentValue;
|
|
|
|
NSArray *rightsForType;
|
|
|
|
|
|
|
|
types = [[self rightTypes] objectEnumerator];
|
|
|
|
currentType = [types nextObject];
|
|
|
|
while (currentType)
|
|
|
|
{
|
|
|
|
rightsForType = [self _rightsForType: currentType];
|
2015-04-24 22:07:48 +02:00
|
|
|
currentValue = [newRights objectForKey: currentType];
|
|
|
|
|
2007-04-25 00:36:20 +02:00
|
|
|
if ([currentValue isEqualToString: @"None"])
|
|
|
|
[self removeAllRightsFromList: rightsForType];
|
|
|
|
else
|
|
|
|
[self appendExclusiveRight: [NSString stringWithFormat: @"%@%@",
|
|
|
|
currentType, currentValue]
|
|
|
|
fromList: rightsForType];
|
|
|
|
currentType = [types nextObject];
|
|
|
|
}
|
|
|
|
|
2015-04-24 22:07:48 +02:00
|
|
|
if ([[newRights objectForKey: @"canCreateObjects"] boolValue])
|
2007-04-25 00:36:20 +02:00
|
|
|
[self appendRight: SOGoRole_ObjectCreator];
|
|
|
|
else
|
|
|
|
[self removeRight: SOGoRole_ObjectCreator];
|
|
|
|
|
2015-04-24 22:07:48 +02:00
|
|
|
if ([[newRights objectForKey: @"canEraseObjects"] boolValue])
|
2007-04-25 00:36:20 +02:00
|
|
|
[self appendRight: SOGoRole_ObjectEraser];
|
|
|
|
else
|
|
|
|
[self removeRight: SOGoRole_ObjectEraser];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) objectRights
|
|
|
|
{
|
2010-06-03 16:43:38 +02:00
|
|
|
return ([uid isEqualToString: @"anonymous"]
|
2013-08-09 17:39:15 +02:00
|
|
|
? [NSArray arrayWithObjects: @"None", @"DAndTViewer", @"Viewer",
|
2010-06-03 16:43:38 +02:00
|
|
|
nil]
|
2013-08-09 17:39:15 +02:00
|
|
|
: [NSArray arrayWithObjects: @"None", @"DAndTViewer", @"Viewer",
|
|
|
|
@"Responder", @"Modifier", nil]);
|
2007-04-25 00:36:20 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 22:12:14 +02:00
|
|
|
- (NSArray *) rightTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"Public", @"Confidential", @"Private", nil];
|
|
|
|
}
|
|
|
|
|
2007-04-25 00:36:20 +02:00
|
|
|
- (void) setCurrentRight: (NSString *) newCurrentRight
|
|
|
|
{
|
|
|
|
ASSIGN (currentRight, newCurrentRight);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentRight
|
|
|
|
{
|
|
|
|
return currentRight;
|
|
|
|
}
|
|
|
|
|
2008-12-23 16:51:12 +01:00
|
|
|
- (NSString *) currentRightLabel
|
|
|
|
{
|
|
|
|
return [self labelForKey:
|
|
|
|
[NSString stringWithFormat: @"label_%@", currentRight]];
|
|
|
|
}
|
|
|
|
|
2015-06-12 22:12:14 +02:00
|
|
|
- (BOOL) userCanCreateObjects
|
|
|
|
{
|
|
|
|
return [userRights containsObject: SOGoRole_ObjectCreator];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) userCanEraseObjects
|
|
|
|
{
|
|
|
|
return [userRights containsObject: SOGoRole_ObjectEraser];
|
|
|
|
}
|
|
|
|
|
2007-04-25 00:36:20 +02:00
|
|
|
@end
|