Fix compilation warnings regarding ACLs

Also change the data structure of the JSON returned by [UIxAclEditor
aclsAction]. The user's displayName has been removed and replace by the
"cn" and "c_email" attributes. This will probably affect the Thunderbird
extensions.
pull/91/head
Francis Lachapelle 2014-10-31 12:59:43 -04:00
parent 22faf5c285
commit bd39312b19
6 changed files with 126 additions and 88 deletions

View File

@ -1,8 +1,6 @@
/* UIxAclEditor.h - this file is part of SOGo
*
* Copyright (C) 2006, 2007 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2006-2014 Inverse inc.
*
* 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
@ -38,9 +36,13 @@
- (NSArray *) aclsForObject;
- (NSArray *) usersForObject;
- (void) setCurrentUser: (NSString *) newCurrentUser;
- (NSString *) currentUser;
- (NSString *) currentUserClass;
- (NSDictionary *) currentUserInfos;
- (NSString *) currentUserDisplayName;
- (BOOL) currentUserIsSubscribed;
- (BOOL) isPublicAccessEnabled;
@end

View File

@ -24,17 +24,19 @@
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSKeyValueCoding.h>
#import <NGObjWeb/SoSecurityManager.h>
#import <NGObjWeb/SoUser.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/SoSecurityManager.h>
#import <NGObjWeb/WOResponse.h>
#import <NGCards/iCalPerson.h>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/SOGoContentObject.h>
#import <SOGo/SOGoGCSFolder.h>
#import <SOGo/SOGoPermissions.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserManager.h>
#import "UIxAclEditor.h"
@ -85,8 +87,9 @@
{
id <WOActionResults> result;
NSEnumerator *aclsEnum;
NSString *currentUID, *ownerLogin;
NSDictionary *object;
NSString *currentUID, *ownerLogin, *info;
NSMutableDictionary *userData;
NSDictionary *currentUserInfos;
if (!prepared)
{
@ -104,18 +107,40 @@
// Set the current user in order to get information associated with it
[self setCurrentUser: currentUID];
// Build the object associated with the key; currentUID
object = [NSDictionary dictionaryWithObjectsAndKeys: currentUser, @"uid",
[self currentUserClass], @"userClass",
[self currentUserDisplayName], @"displayName",
[NSNumber numberWithBool: [self currentUserIsSubscribed]], @"isSubscribed", nil];
[users setObject: object forKey: currentUID];
// Build the object associated to the current UID
currentUserInfos = [self currentUserInfos];
userData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
currentUser, @"uid",
[self currentUserClass], @"userClass",
[NSNumber numberWithBool: [self currentUserIsSubscribed]], @"isSubscribed",
nil];
if ((info = [currentUserInfos objectForKey: @"cn"]) && [info length])
[userData setObject: info forKey: @"cn"];
if ((info = [currentUserInfos objectForKey: @"c_email"]) && [info length])
[userData setObject: info forKey: @"c_email"];
[users setObject: userData forKey: currentUID];
}
}
// Adding the Any authenticated user and the public access
[users setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"<default>", @"uid", [self labelForKey: @"Any Authenticated User"], @"displayName", @"public-user", @"userClass", nil] forKey: @"<default>"];
// Add the 'Any authenticated' user
userData = [NSDictionary dictionaryWithObjectsAndKeys:
@"<default>", @"uid",
[self labelForKey: @"Any Authenticated User"], @"cn",
@"public-user", @"userClass",
nil];
[users setObject: userData forKey: @"<default>"];
if ([self isPublicAccessEnabled])
[users setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"anonymous", @"uid", [self labelForKey: @"Public Access"], @"displayName", @"public-user", @"userClass", nil] forKey: @"anonymous"];
{
// Add the 'public access' user
userData = [NSDictionary dictionaryWithObjectsAndKeys:
@"anonymous", @"uid",
[self labelForKey: @"Public Access"], @"cn",
@"public-user", @"userClass",
nil];
[users setObject: userData forKey: @"anonymous"];
}
prepared = YES;
}
@ -153,6 +178,15 @@
return [um getFullEmailForUID: [self currentUser]];
}
- (NSDictionary *) currentUserInfos
{
SOGoUserManager *um;
um = [SOGoUserManager sharedUserManager];
return [um contactInfosForUserWithUIDorEmail: [self currentUser]];
}
- (BOOL) canSubscribeUsers
{
return [[self clientObject]
@ -203,16 +237,15 @@
while ((currentUID = [[aclsEnum nextObject] objectForKey: @"c_uid"]))
if ([currentUID isEqualToString: ownerLogin]
|| [savedUIDs containsObject: currentUID])
[users removeObject: currentUID];
[clientObject removeAclsForUsers: users];
[users removeObjectForKey: currentUID];
[clientObject removeAclsForUsers: [users allKeys]];
return [self jsCloseWithRefreshMethod: nil];
}
- (BOOL) isPublicAccessEnabled
{
return [[SOGoSystemDefaults sharedSystemDefaults]
enablePublicAccess];
return [[SOGoSystemDefaults sharedSystemDefaults] enablePublicAccess];
}
@end

View File

@ -1,8 +1,6 @@
/* UIxUserRightsEditor.h - this file is part of SOGo
*
* Copyright (C) 2007-2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2007-2014 Inverse inc.
*
* 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
@ -48,8 +46,8 @@
- (void) removeRight: (NSString *) right;
- (void) removeAllRightsFromList: (NSArray *) list;
- (void) prepareRightsForm;
- (void) updateRights;
- (NSDictionary *) userRightsForObject;
- (void) updateRights: (NSDictionary *) newRights;
@end

View File

@ -1,8 +1,6 @@
/* UIxUserRightsEditor.m - this file is part of SOGo
*
* Copyright (C) 2007-2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2007-2014 Inverse inc.
*
* 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
@ -20,10 +18,15 @@
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSDictionary.h>
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/WOApplication.h>
#import <NGObjWeb/WOResponse.h>
#import <NGObjWeb/WORequest.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoGroup.h>
#import <SOGo/SOGoObject.h>
@ -31,6 +34,7 @@
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <UI/SOGoUI/SOGoACLAdvisory.h>
#import "UIxUserRightsEditor.h"
@ -123,8 +127,8 @@
um = [SOGoUserManager sharedUserManager];
if ([newUID isEqualToString: defaultUserID]
|| [newUID isEqualToString: @"anonymous"]
|| [[um getEmailForUID: newUID] length] > 0)
|| [newUID isEqualToString: @"anonymous"]
|| [[um getEmailForUID: newUID] length] > 0)
{
if (![newUID hasPrefix: @"@"])
{
@ -140,6 +144,7 @@
response = YES;
}
}
return response;
}
- (BOOL) _initRightsForUserID:(NSString *) newUID
@ -158,7 +163,7 @@
ASSIGN (defaultUserID, [[self clientObject] defaultUserID]);
um = [SOGoUserManager sharedUserManager];
if ([newUID isEqualToString: defaultUserID] || [newUID isEqualToString: @"anonymous"]
if ([newUID isEqualToString: defaultUserID] || [newUID isEqualToString: @"anonymous"]
|| [[um getEmailForUID: newUID] length] > 0)
{
if (![newUID hasPrefix: @"@"])
@ -181,15 +186,21 @@
- (id <WOActionResults>) defaultAction
{
id <WOActionResults> response;
NSDictionary *jsonResponse;
if (![self _initRights])
response = [self responseWithStatus: 403
andString: @"No such user."];
else {
//[self prepareRightsForm];
response = [self responseWithStatus: 200
andString:[[self userRightsForObject] jsonRepresentation]];
}
{
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"No such user."]
forKey: @"error"];
response = [self responseWithStatus: 403
andString: [jsonResponse jsonRepresentation]];
}
else
{
jsonResponse = [self userRightsForObject];
response = [self responseWithStatus: 200
andString: [jsonResponse jsonRepresentation]];
}
return response;
}
@ -220,39 +231,39 @@
id <WOActionResults> response;
WORequest *request;
SOGoDomainDefaults *dd;
NSDictionary *dirtyUsers, *currentUser, *jsonResponse;;
NSEnumerator *enumerator;
NSString *uid;
NSArray *users;
NSDictionary *currentUser, *jsonResponse;;
NSEnumerator *usersList;
NSString *currentUid;
NSArray *o;
request = [[self context] request];
dirtyUsers = [[request contentAsString] objectFromJSONString];
enumerator = [dirtyUsers keyEnumerator];
while((uid = [enumerator nextObject]))
{
currentUser = [dirtyUsers objectForKey: uid];
if(!([self _initRightsForUserID: [currentUser objectForKey: @"uid"]]))
{
jsonResponse = [NSDictionary dictionaryWithObject: @"No such user." forKey: @"error"];
response = [self responseWithStatus: 403
andString: [jsonResponse jsonRepresentation]];
return response;
}
else
{
o = [NSArray arrayWithArray: userRights];
[self updateRights:[currentUser objectForKey: @"aclOptions"]];
[[self clientObject] setRoles: userRights forUser: uid];
dd = [[context activeUser] domainDefaults];
if (![o isEqualToArray: userRights] && [dd aclSendEMailNotifications])
[self sendACLAdvisoryTemplateForObject: [self clientObject]];
response = [self jsCloseWithRefreshMethod: nil];
}
}
response = [self responseWithStatus: 200];
users = [[request contentAsString] objectFromJSONString];
usersList = [users objectEnumerator];
while ((currentUser = [usersList nextObject]))
{
currentUid = [currentUser objectForKey: @"uid"];
if (!([self _initRightsForUserID: currentUid]))
{
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"No such user."]
forKey: @"error"];
response = [self responseWithStatus: 403
andString: [jsonResponse jsonRepresentation]];
break;
}
else
{
o = [NSArray arrayWithArray: userRights];
[self updateRights: [currentUser objectForKey: @"rights"]];
[[self clientObject] setRoles: userRights forUser: currentUid];
dd = [[context activeUser] domainDefaults];
if (![o isEqualToArray: userRights] && [dd aclSendEMailNotifications])
[self sendACLAdvisoryTemplateForObject: [self clientObject]];
}
}
return response;
}
@ -280,11 +291,12 @@
[userRights removeObjectsInArray: list];
}
- (void) prepareRightsForm
- (NSDictionary *) userRightsForObject
{
return [self subclassResponsibility: _cmd];
}
- (void) updateRights
- (void) updateRights: (NSDictionary *) newRights
{
[self subclassResponsibility: _cmd];
}

View File

@ -27,20 +27,11 @@
@interface UIxContactsUserRightsEditor : UIxUserRightsEditor
- (void) setUserCanCreateObjects: (BOOL) userCanCreateObjects;
- (BOOL) userCanCreateObjects;
- (void) setUserCanEraseObjects: (BOOL) userCanEraseObjects;
- (BOOL) userCanEraseObjects;
- (void) setUserCanEditObjects: (BOOL) userCanEditObjects;
- (BOOL) userCanEditObjects;
- (void) setUserCanViewObjects: (BOOL) userCanViewObjects;
- (BOOL) userCanViewObjects;
- (void) updateRights;
@end
#endif /* UIXCONTACTSUSERRIGHTSEDITOR_H */

View File

@ -1,8 +1,6 @@
/* UIxContactsUserRightsEditor.m - this file is part of SOGo
*
* Copyright (C) 2007 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2007-2014 Inverse inc.
*
* 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
@ -21,9 +19,12 @@
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSValue.h>
#import <NGObjWeb/WORequest.h>
#import <SoObjects/SOGo/SOGoPermissions.h>
#import "UIxContactsUserRightsEditor.h"
@ -52,15 +53,16 @@
- (NSDictionary *) userRightsForObject
{
return [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:[self userCanCreateObjects]], @"canCreateObjects",
[NSNumber numberWithBool:[self userCanEraseObjects]], @"canEraseObjects",
[NSNumber numberWithBool:[self userCanEditObjects]], @"canEditObjects",
[NSNumber numberWithBool:[self userCanViewObjects]], @"canViewObjects", nil];
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:[self userCanCreateObjects]], @"canCreateObjects",
[NSNumber numberWithBool:[self userCanEraseObjects]], @"canEraseObjects",
[NSNumber numberWithBool:[self userCanEditObjects]], @"canEditObjects",
[NSNumber numberWithBool:[self userCanViewObjects]], @"canViewObjects",
nil];
}
- (void) updateRights: (NSDictionary *) newRights
{
if ([[newRights objectForKey: @"canCreateObjects"] boolValue])
[self appendRight: SOGoRole_ObjectCreator];
else
@ -82,4 +84,4 @@
[self removeRight: SOGoRole_ObjectEraser];
}
@end
@end