1 /* UIxCalUserRightsEditor.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSEnumerator.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <SoObjects/SOGo/SOGoPermissions.h>
28 #import "UIxCalUserRightsEditor.h"
30 @implementation UIxCalUserRightsEditor
34 if ((self = [super init]))
37 currentRightType = nil;
38 rights = [NSMutableDictionary new];
39 [rights setObject: @"None" forKey: @"Public"];
40 [rights setObject: @"None" forKey: @"Private"];
41 [rights setObject: @"None" forKey: @"Confidential"];
49 [currentRight release];
50 [currentRightType release];
55 - (void) prepareRightsForm
57 NSEnumerator *roles, *types;
58 NSString *role, *type;
61 roles = [userRights objectEnumerator];
62 role = [roles nextObject];
65 types = [[self rightTypes] objectEnumerator];
66 type = [types nextObject];
69 if ([role hasPrefix: type])
71 length = [type length];
72 [rights setObject: [role substringFromIndex: length]
75 type = [types nextObject];
77 role = [roles nextObject];
81 - (NSArray *) _rightsForType: (NSString *) type
83 NSMutableArray *rightsForType;
84 NSEnumerator *commonRights;
85 NSString *currentCommonRight;
87 rightsForType = [NSMutableArray new];
88 [rightsForType autorelease];
89 commonRights = [[self objectRights] objectEnumerator];
90 currentCommonRight = [commonRights nextObject];
91 while (currentCommonRight)
93 [rightsForType addObject: [NSString stringWithFormat: @"%@%@",
94 type, currentCommonRight]];
95 currentCommonRight = [commonRights nextObject];
101 - (void) updateRights
104 NSString *currentType, *currentValue;
105 NSArray *rightsForType;
108 request = [context request];
109 types = [[self rightTypes] objectEnumerator];
110 currentType = [types nextObject];
113 rightsForType = [self _rightsForType: currentType];
115 = [request formValueForKey:
116 [NSString stringWithFormat: @"%@Right", currentType]];
117 if ([currentValue isEqualToString: @"None"])
118 [self removeAllRightsFromList: rightsForType];
120 [self appendExclusiveRight: [NSString stringWithFormat: @"%@%@",
121 currentType, currentValue]
122 fromList: rightsForType];
123 currentType = [types nextObject];
126 if ([[request formValueForKey: @"ObjectCreator"] length] > 0)
127 [self appendRight: SOGoRole_ObjectCreator];
129 [self removeRight: SOGoRole_ObjectCreator];
131 if ([[request formValueForKey: @"ObjectEraser"] length] > 0)
132 [self appendRight: SOGoRole_ObjectEraser];
134 [self removeRight: SOGoRole_ObjectEraser];
137 - (NSArray *) objectRights
140 [NSArray arrayWithObjects:
141 @"Viewer", @"DAndTViewer", @"Modifier", @"Responder", @"None", nil];
144 - (void) setCurrentRight: (NSString *) newCurrentRight
146 ASSIGN (currentRight, newCurrentRight);
149 - (NSString *) currentRight
154 - (NSArray *) rightTypes
157 [NSArray arrayWithObjects: @"Public", @"Confidential", @"Private", nil];
160 - (void) setCurrentRightType: (NSString *) newCurrentRightType
162 ASSIGN (currentRightType, newCurrentRightType);
165 - (NSString *) currentRightType
167 return currentRightType;
170 - (NSString *) currentRightTypeLabel
172 return [self labelForKey:
173 [NSString stringWithFormat: @"label_%@", currentRightType]];
176 - (NSString *) currentRightTypeName
178 return [NSString stringWithFormat: @"%@Right", currentRightType];
181 - (NSString *) currentRightSelection
183 return [rights objectForKey: currentRightType];
186 - (void) setUserCanCreateObjects: (BOOL) userCanCreateObjects
188 [self appendRight: SOGoRole_ObjectCreator];
191 - (BOOL) userCanCreateObjects
193 return [userRights containsObject: SOGoRole_ObjectCreator];
196 - (void) setUserCanEraseObjects: (BOOL) userCanEraseObjects
198 [self appendRight: SOGoRole_ObjectEraser];
201 - (BOOL) userCanEraseObjects
203 return [userRights containsObject: SOGoRole_ObjectEraser];