From 030e2297891d4a8ad5f4e63e4442c7eaaf9291ec Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 15 Dec 2008 22:01:52 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 6411d6bcaaaa5245d22397cfde490125a116e0c7 Monotone-Revision: c8d084db03459d614e6031f3b3996696f8a588b4 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2008-12-15T22:01:52 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 ++ SoObjects/SOGo/SOGoObject.m | 83 +++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6866af4ab..cd231c1a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ the usage of the SOGoLDAPContactInfoAttribute, if defined, over "description" when generating the "NOTE" attribute. + * SoObjects/SOGo/SOGoObject.m + Optimized a bit and we also now support setting + roles, or adding/removing roles for multiple users + at once. 2008-12-14 Ludovic Marcotte diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 51fcfae78..5a0ea293b 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -1062,9 +1062,7 @@ SEL SOGoSelectorForPropertySetter (NSString *property) BOOL result; if ([uid length] - && ![uid isEqualToString: [self ownerInContext: nil]] - && [[LDAPUserManager sharedUserManager] - contactInfosForUserWithUIDorEmail: uid]) + && ![uid isEqualToString: [self ownerInContext: nil]]) { [self setRoles: [self aclsForUser: uid] forUser: uid]; @@ -1432,7 +1430,8 @@ SEL SOGoSelectorForPropertySetter (NSString *property) id node, userAttr; id attrs; NSString *nodeName, *result, *response, *user; - NSArray *childNodes; + NSArray *childNodes, *allUsers, *allRoles; + int i; result = nil; @@ -1454,16 +1453,50 @@ SEL SOGoSelectorForPropertySetter (NSString *property) } else if ([nodeName isEqualToString: @"set-roles"]) { + // We support two ways of setting roles. The first one is, for example: + // + // + // + // + // + // while the second one, for mutliple users at the same time, is: + // + // + // + // + // attrs = [node attributes]; userAttr = [attrs namedItem: @"user"]; user = [userAttr nodeValue]; + if ([user length]) + allUsers = [NSArray arrayWithObject: user]; + else { + userAttr = [attrs namedItem: @"users"]; + allUsers = [[userAttr nodeValue] componentsSeparatedByString: @","]; + } + + allRoles = [self _davGetRolesFromRequest: node]; + for (i = 0; i < [allUsers count]; i++) { - [self setRoles: [self _davGetRolesFromRequest: node] - forUser: user]; - result = @""; + [self setRoles: allRoles + forUser: [allUsers objectAtIndex: i]]; } + result = @""; } + // + // Here again, we support two ways of adding users. The first one is, for example: + // + // + // + // + // + // while the second one, for mutliple users at the same time, is: + // + // + // + // + // else if ([nodeName isEqualToString: @"add-user"]) { attrs = [node attributes]; @@ -1472,6 +1505,25 @@ SEL SOGoSelectorForPropertySetter (NSString *property) if ([self addUserInAcls: user]) result = @""; } + else if ([nodeName isEqualToString: @"add-users"]) + { + attrs = [node attributes]; + userAttr = [attrs namedItem: @"users"]; + allUsers = [[userAttr nodeValue] componentsSeparatedByString: @","]; + + for (i = 0; i < [allUsers count]; i++) + { + if ([self addUserInAcls: [allUsers objectAtIndex: i]]) + result = @""; + else { + result = nil; + break; + } + } + } + // + // See the comment for add-user / add-users + // else if ([nodeName isEqualToString: @"remove-user"]) { attrs = [node attributes]; @@ -1480,6 +1532,23 @@ SEL SOGoSelectorForPropertySetter (NSString *property) if ([self removeUserFromAcls: user]) result = @""; } + else if ([nodeName isEqualToString: @"remove-users"]) + { + attrs = [node attributes]; + userAttr = [attrs namedItem: @"users"]; + + allUsers = [[userAttr nodeValue] componentsSeparatedByString: @","]; + + for (i = 0; i < [allUsers count]; i++) + { + if ([self removeUserFromAcls: [allUsers objectAtIndex: i]]) + result = @""; + else { + result = nil; + break; + } + } + } } if (result)