diff --git a/UI/Common/UIxAclEditor.h b/UI/Common/UIxAclEditor.h index e249ec756..b894cd2a7 100644 --- a/UI/Common/UIxAclEditor.h +++ b/UI/Common/UIxAclEditor.h @@ -1,8 +1,6 @@ /* UIxAclEditor.h - this file is part of SOGo * - * Copyright (C) 2006, 2007 Inverse inc. - * - * Author: Wolfgang Sourdeau + * 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 diff --git a/UI/Common/UIxAclEditor.m b/UI/Common/UIxAclEditor.m index 24da639e7..7903ef9e0 100644 --- a/UI/Common/UIxAclEditor.m +++ b/UI/Common/UIxAclEditor.m @@ -24,17 +24,19 @@ #import #import +#import #import #import -#import +#import #import #import +#import #import #import #import #import -#import #import +#import #import "UIxAclEditor.h" @@ -85,8 +87,9 @@ { id 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: @"", @"uid", [self labelForKey: @"Any Authenticated User"], @"displayName", @"public-user", @"userClass", nil] forKey: @""]; + + // Add the 'Any authenticated' user + userData = [NSDictionary dictionaryWithObjectsAndKeys: + @"", @"uid", + [self labelForKey: @"Any Authenticated User"], @"cn", + @"public-user", @"userClass", + nil]; + [users setObject: userData forKey: @""]; + 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 diff --git a/UI/Common/UIxUserRightsEditor.h b/UI/Common/UIxUserRightsEditor.h index 8cb083c9e..5e0078de1 100644 --- a/UI/Common/UIxUserRightsEditor.h +++ b/UI/Common/UIxUserRightsEditor.h @@ -1,8 +1,6 @@ /* UIxUserRightsEditor.h - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. - * - * Author: Wolfgang Sourdeau + * 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 diff --git a/UI/Common/UIxUserRightsEditor.m b/UI/Common/UIxUserRightsEditor.m index 06f52f4f0..2452c8c69 100644 --- a/UI/Common/UIxUserRightsEditor.m +++ b/UI/Common/UIxUserRightsEditor.m @@ -1,8 +1,6 @@ /* UIxUserRightsEditor.m - this file is part of SOGo * - * Copyright (C) 2007-2010 Inverse inc. - * - * Author: Wolfgang Sourdeau + * 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 + #import #import #import #import + +#import +#import #import #import #import @@ -31,6 +34,7 @@ #import #import #import + #import #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 ) defaultAction { id 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 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]; } diff --git a/UI/Contacts/UIxContactsUserRightsEditor.h b/UI/Contacts/UIxContactsUserRightsEditor.h index 9d32f84b8..cbccb7704 100644 --- a/UI/Contacts/UIxContactsUserRightsEditor.h +++ b/UI/Contacts/UIxContactsUserRightsEditor.h @@ -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 */ diff --git a/UI/Contacts/UIxContactsUserRightsEditor.m b/UI/Contacts/UIxContactsUserRightsEditor.m index 381e4d9f5..09114b373 100644 --- a/UI/Contacts/UIxContactsUserRightsEditor.m +++ b/UI/Contacts/UIxContactsUserRightsEditor.m @@ -1,8 +1,6 @@ /* UIxContactsUserRightsEditor.m - this file is part of SOGo * - * Copyright (C) 2007 Inverse inc. - * - * Author: Wolfgang Sourdeau + * 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 +#import #import #import + #import + #import #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 \ No newline at end of file +@end