fix(calendar): return SOGoUser instances when expanding LDAP groups

Fixes #5043
pull/283/head
Francis Lachapelle 2020-07-01 16:58:16 -04:00
parent 62fc80de20
commit b8595d7ae6
5 changed files with 30 additions and 34 deletions

View File

@ -429,6 +429,7 @@ static Class iCalEventK = nil;
NSString *subscriptionPointer, *domain; NSString *subscriptionPointer, *domain;
NSMutableArray *allUsers; NSMutableArray *allUsers;
SOGoUserSettings *us; SOGoUserSettings *us;
SOGoUser *sogoUser;
NSDictionary *dict; NSDictionary *dict;
BOOL rc; BOOL rc;
int i; int i;
@ -452,15 +453,11 @@ static Class iCalEventK = nil;
NSArray *members; NSArray *members;
members = [(id<SOGoMembershipSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]; members = [(id<SOGoMembershipSource>)(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 // We remove the active user from the group (if present) in order to
// not subscribe him to their own resource! // not subscribe him to their own resource!
[allUsers removeObject: [[context activeUser] login]]; [allUsers removeObject: [context activeUser]];
} }
else else
{ {
@ -470,15 +467,17 @@ static Class iCalEventK = nil;
} }
else else
{ {
if (dict) sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil];
allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]]; if (sogoUser)
allUsers = [NSArray arrayWithObject: sogoUser];
else else
allUsers = [NSArray array]; allUsers = [NSArray array];
} }
for (i = 0; i < [allUsers count]; i++) 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]]; moduleSettings = [us objectForKey: [container nameInContainer]];
if (!(moduleSettings if (!(moduleSettings
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]])) && [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
@ -1520,7 +1519,7 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir
BOOL rememberRecords, canCycle; BOOL rememberRecords, canCycle;
SOGoUser *ownerUser; SOGoUser *ownerUser;
ownerUser = [SOGoUser userWithLogin: owner roles: nil]; ownerUser = [SOGoUser userWithLogin: self->owner roles: nil];
rememberRecords = [self _checkIfWeCanRememberRecords: _fields]; rememberRecords = [self _checkIfWeCanRememberRecords: _fields];
canCycle = [_component isEqualToString: @"vevent"] || [_component isEqualToString: @"vtodo"]; canCycle = [_component isEqualToString: @"vevent"] || [_component isEqualToString: @"vtodo"];
// if (rememberRecords) // if (rememberRecords)
@ -1679,7 +1678,7 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir
} }
currentLogin = [[context activeUser] login]; currentLogin = [[context activeUser] login];
if (![currentLogin isEqualToString: owner]) if (![currentLogin isEqualToString: self->owner])
{ {
if (!_includeProtectedInformation) if (!_includeProtectedInformation)

View File

@ -557,7 +557,7 @@
{ {
iCalPerson *person; iCalPerson *person;
NSArray *members; NSArray *members;
NSDictionary *user; SOGoUser *user;
id <SOGoSource> source; id <SOGoSource> source;
// We did decompose a group... // We did decompose a group...
@ -574,10 +574,10 @@
// If the organizer is part of the group, we skip it from // If the organizer is part of the group, we skip it from
// the addition to the attendees' list // the addition to the attendees' list
if ([[user objectForKey: @"c_emails"] containsObject: organizerEmail]) if ([user hasEmail: organizerEmail])
continue; continue;
person = [self iCalPersonWithUID: [user objectForKey: @"c_uid"]]; person = [self iCalPersonWithUID: [user login]];
[person setTag: @"ATTENDEE"]; [person setTag: @"ATTENDEE"];
[person setParticipationStatus: [currentAttendee participationStatus]]; [person setParticipationStatus: [currentAttendee participationStatus]];
[person setRsvp: [currentAttendee rsvp]]; [person setRsvp: [currentAttendee rsvp]];

View File

@ -2085,8 +2085,7 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
if (user) if (user)
{ {
[logins addObject: login]; [logins addObject: login];
[members addObject: [NSDictionary dictionaryWithObject: login [members addObject: user];
forKey: @"c_uid"]];
} }
[pool release]; [pool release];
} }
@ -2100,15 +2099,14 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
if (user) if (user)
{ {
[logins addObject: login]; [logins addObject: login];
[members addObject: [NSDictionary dictionaryWithObject: login [members addObject: user];
forKey: @"c_uid"]];
} }
[pool release]; [pool release];
} }
// We are done fetching members, let's cache the members of the group // 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: @","] [[SOGoCache sharedCache] setValue: [logins componentsJoinedByString: @","]
forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]]; forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]];
} }

View File

@ -926,6 +926,7 @@ static NSArray *childRecordFields = nil;
NSString *subscriptionPointer, *domain; NSString *subscriptionPointer, *domain;
NSMutableArray *allUsers; NSMutableArray *allUsers;
SOGoUserSettings *us; SOGoUserSettings *us;
SOGoUser *sogoUser;
NSDictionary *dict; NSDictionary *dict;
BOOL rc; BOOL rc;
int i; int i;
@ -944,15 +945,11 @@ static NSArray *childRecordFields = nil;
NSArray *members; NSArray *members;
members = [(id<SOGoMembershipSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]; members = [(id<SOGoMembershipSource>)(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 // We remove the active user from the group (if present) in order to
// not subscribe him to their own resource! // not subscribe him to their own resource!
[allUsers removeObject: [[context activeUser] login]]; [allUsers removeObject: [context activeUser]];
} }
else else
{ {
@ -962,8 +959,9 @@ static NSArray *childRecordFields = nil;
} }
else else
{ {
if (dict) sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil];
allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]]; if (sogoUser)
allUsers = [NSArray arrayWithObject: sogoUser];
else else
allUsers = [NSArray array]; allUsers = [NSArray array];
} }
@ -976,7 +974,8 @@ static NSArray *childRecordFields = nil;
for (i = 0; i < [allUsers count]; i++) 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]]; moduleSettings = [us objectForKey: [container nameInContainer]];
if (!(moduleSettings if (!(moduleSettings
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]])) && [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
@ -1797,8 +1796,8 @@ static NSArray *childRecordFields = nil;
source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]]; source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]];
if ([source conformsToProtocol:@protocol(SOGoMembershipSource)]) if ([source conformsToProtocol:@protocol(SOGoMembershipSource)])
{ {
NSDictionary *user;
NSArray *members; NSArray *members;
SOGoUser *user;
unsigned int j; unsigned int j;
// Fetch members to remove them from the cache along the group // Fetch members to remove them from the cache along the group
@ -1806,7 +1805,7 @@ static NSArray *childRecordFields = nil;
for (j = 0; j < [members count]; j++) for (j = 0; j < [members count]; j++)
{ {
user = [members objectAtIndex: j]; user = [members objectAtIndex: j];
[groupsMembers addObject: [user objectForKey: @"c_uid"]]; [groupsMembers addObject: [user login]];
} }
if (![uid hasPrefix: @"@"]) if (![uid hasPrefix: @"@"])

View File

@ -397,7 +397,7 @@
NSString *email; NSString *email;
SOGoObject <SOGoContactObject> *contact; SOGoObject <SOGoContactObject> *contact;
SOGoObject <SOGoSource> *source; SOGoObject <SOGoSource> *source;
NSDictionary *user; SOGoUser *user;
id <WOActionResults> result; id <WOActionResults> result;
unsigned int i, max; unsigned int i, max;
@ -418,14 +418,14 @@
{ {
user = [allUsers objectAtIndex: i]; user = [allUsers objectAtIndex: i];
allUserEmails = [NSMutableArray array]; allUserEmails = [NSMutableArray array];
emails = [[user objectForKey: @"c_emails"] objectEnumerator]; emails = [[user allEmails] objectEnumerator];
while ((email = [emails nextObject])) { while ((email = [emails nextObject])) {
[allUserEmails addObject: [NSDictionary dictionaryWithObjectsAndKeys: [allUserEmails addObject: [NSDictionary dictionaryWithObjectsAndKeys:
email, @"value", @"work", @"type", nil]]; email, @"value", @"work", @"type", nil]];
} }
userData = [NSDictionary dictionaryWithObjectsAndKeys: userData = [NSDictionary dictionaryWithObjectsAndKeys:
[user objectForKey: @"c_uid"], @"c_uid", [user loginInDomain], @"c_uid",
[user objectForKey: @"c_cn"], @"c_cn", [user cn], @"c_cn",
allUserEmails, @"emails", nil]; allUserEmails, @"emails", nil];
[allUsersData addObject: userData]; [allUsersData addObject: userData];
} }