From b8595d7ae6d1c961f03eaea0e870aa0f117e7b9b Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 1 Jul 2020 16:58:16 -0400 Subject: [PATCH] fix(calendar): return SOGoUser instances when expanding LDAP groups Fixes #5043 --- .../Appointments/SOGoAppointmentFolder.m | 21 +++++++++---------- .../Appointments/SOGoCalendarComponent.m | 6 +++--- SoObjects/SOGo/LDAPSource.m | 8 +++---- SoObjects/SOGo/SOGoGCSFolder.m | 21 +++++++++---------- UI/Contacts/UIxContactView.m | 8 +++---- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index 27a773f3dc..c4b51f1415 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -429,6 +429,7 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier NSString *subscriptionPointer, *domain; NSMutableArray *allUsers; SOGoUserSettings *us; + SOGoUser *sogoUser; NSDictionary *dict; BOOL rc; int i; @@ -452,15 +453,11 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier NSArray *members; members = [(id)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]; - allUsers = [NSMutableArray array]; + allUsers = [NSMutableArray arrayWithArray: members]; - for (i = 0; i < [members count]; i++) - { - [allUsers addObject: [[members objectAtIndex: i] objectForKey: @"c_uid"]]; - } // We remove the active user from the group (if present) in order to // not subscribe him to their own resource! - [allUsers removeObject: [[context activeUser] login]]; + [allUsers removeObject: [context activeUser]]; } else { @@ -470,15 +467,17 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier } else { - if (dict) - allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]]; + sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil]; + if (sogoUser) + allUsers = [NSArray arrayWithObject: sogoUser]; else allUsers = [NSArray array]; } for (i = 0; i < [allUsers count]; i++) { - us = [SOGoUserSettings settingsForUser: [allUsers objectAtIndex: i]]; + sogoUser = [allUsers objectAtIndex: i]; + us = [sogoUser userSettings]; moduleSettings = [us objectForKey: [container nameInContainer]]; if (!(moduleSettings && [moduleSettings isKindOfClass: [NSMutableDictionary class]])) @@ -1520,7 +1519,7 @@ - (NSArray *) fetchFields: (NSArray *) _fields BOOL rememberRecords, canCycle; SOGoUser *ownerUser; - ownerUser = [SOGoUser userWithLogin: owner roles: nil]; + ownerUser = [SOGoUser userWithLogin: self->owner roles: nil]; rememberRecords = [self _checkIfWeCanRememberRecords: _fields]; canCycle = [_component isEqualToString: @"vevent"] || [_component isEqualToString: @"vtodo"]; // if (rememberRecords) @@ -1679,7 +1678,7 @@ - (NSArray *) fetchFields: (NSArray *) _fields } currentLogin = [[context activeUser] login]; - if (![currentLogin isEqualToString: owner]) + if (![currentLogin isEqualToString: self->owner]) { if (!_includeProtectedInformation) diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index 9b34b493eb..62e91439dc 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -557,7 +557,7 @@ - (BOOL) expandGroupsInEvent: (iCalEvent *) theEvent { iCalPerson *person; NSArray *members; - NSDictionary *user; + SOGoUser *user; id source; // We did decompose a group... @@ -574,10 +574,10 @@ - (BOOL) expandGroupsInEvent: (iCalEvent *) theEvent // If the organizer is part of the group, we skip it from // the addition to the attendees' list - if ([[user objectForKey: @"c_emails"] containsObject: organizerEmail]) + if ([user hasEmail: organizerEmail]) continue; - person = [self iCalPersonWithUID: [user objectForKey: @"c_uid"]]; + person = [self iCalPersonWithUID: [user login]]; [person setTag: @"ATTENDEE"]; [person setParticipationStatus: [currentAttendee participationStatus]]; [person setRsvp: [currentAttendee rsvp]]; diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 9e1c38f4c8..b2bb15aa6d 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -2085,8 +2085,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid if (user) { [logins addObject: login]; - [members addObject: [NSDictionary dictionaryWithObject: login - forKey: @"c_uid"]]; + [members addObject: user]; } [pool release]; } @@ -2100,15 +2099,14 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid if (user) { [logins addObject: login]; - [members addObject: [NSDictionary dictionaryWithObject: login - forKey: @"c_uid"]]; + [members addObject: user]; } [pool release]; } // We are done fetching members, let's cache the members of the group - // (ie., their UIDs) in memcached to speed up -hasMemberWithUID. + // (ie., their UIDs) in memcached to speed up -groupWithUIDHasMemberWithUID. [[SOGoCache sharedCache] setValue: [logins componentsJoinedByString: @","] forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]]; } diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index 5676babd11..814cb0e1a9 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -926,6 +926,7 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier NSString *subscriptionPointer, *domain; NSMutableArray *allUsers; SOGoUserSettings *us; + SOGoUser *sogoUser; NSDictionary *dict; BOOL rc; int i; @@ -944,15 +945,11 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier NSArray *members; members = [(id)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]; - allUsers = [NSMutableArray array]; + allUsers = [NSMutableArray arrayWithArray: members]; - for (i = 0; i < [members count]; i++) - { - [allUsers addObject: [[members objectAtIndex: i] objectForKey: @"c_uid"]]; - } // We remove the active user from the group (if present) in order to // not subscribe him to their own resource! - [allUsers removeObject: [[context activeUser] login]]; + [allUsers removeObject: [context activeUser]]; } else { @@ -962,8 +959,9 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier } else { - if (dict) - allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]]; + sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil]; + if (sogoUser) + allUsers = [NSArray arrayWithObject: sogoUser]; else allUsers = [NSArray array]; } @@ -976,7 +974,8 @@ - (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier for (i = 0; i < [allUsers count]; i++) { - us = [SOGoUserSettings settingsForUser: [allUsers objectAtIndex: i]]; + sogoUser = [allUsers objectAtIndex: i]; + us = [sogoUser userSettings]; moduleSettings = [us objectForKey: [container nameInContainer]]; if (!(moduleSettings && [moduleSettings isKindOfClass: [NSMutableDictionary class]])) @@ -1797,8 +1796,8 @@ - (void) removeAclsForUsers: (NSArray *) users source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]]; if ([source conformsToProtocol:@protocol(SOGoMembershipSource)]) { - NSDictionary *user; NSArray *members; + SOGoUser *user; unsigned int j; // Fetch members to remove them from the cache along the group @@ -1806,7 +1805,7 @@ - (void) removeAclsForUsers: (NSArray *) users for (j = 0; j < [members count]; j++) { user = [members objectAtIndex: j]; - [groupsMembers addObject: [user objectForKey: @"c_uid"]]; + [groupsMembers addObject: [user login]]; } if (![uid hasPrefix: @"@"]) diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index efb6cf32af..7f551e5779 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -397,7 +397,7 @@ - (NSArray *) deliveryAddresses NSString *email; SOGoObject *contact; SOGoObject *source; - NSDictionary *user; + SOGoUser *user; id result; unsigned int i, max; @@ -418,14 +418,14 @@ - (NSArray *) deliveryAddresses { user = [allUsers objectAtIndex: i]; allUserEmails = [NSMutableArray array]; - emails = [[user objectForKey: @"c_emails"] objectEnumerator]; + emails = [[user allEmails] objectEnumerator]; while ((email = [emails nextObject])) { [allUserEmails addObject: [NSDictionary dictionaryWithObjectsAndKeys: email, @"value", @"work", @"type", nil]]; } userData = [NSDictionary dictionaryWithObjectsAndKeys: - [user objectForKey: @"c_uid"], @"c_uid", - [user objectForKey: @"c_cn"], @"c_cn", + [user loginInDomain], @"c_uid", + [user cn], @"c_cn", allUserEmails, @"emails", nil]; [allUsersData addObject: userData]; }