diff --git a/ChangeLog b/ChangeLog index 1be32028e..58209d70d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,30 @@ 2007-11-26 Wolfgang Sourdeau + * UI/PreferencesUI/UIxPreferences.m ([UIxPreferences -userHasCalendarAccess]) + ([UIxPreferences -userHasMailAccess]): same as below, for + displaying preference tabs. + + * UI/Common/UIxPageFrame.m ([UIxPageFrame + -userHasCalendarAccess]): new accessor for the link banner. + ([UIxPageFrame -userHasMailAccess]): same as above. + + * SoObjects/SOGo/SOGoUserFolder.m ([SOGoUserFolder + -toManyRelationshipKeys]): do not report the path to modules to + which the user has no access. No longer cache this information + statically, the array will be generated at each call. + ([SOGoUserFolder -lookupName:_keyinContext:_ctxacquire:_flag]): + ignore the path to modules to which the user has no access. + + * SoObjects/SOGo/SOGoUser.m ([SOGoUser -canAccessModule:module]): + new method that returns whether the user has access to the + specified module. + + * SoObjects/SOGo/LDAPSource.m ([LDAPSource + -initFromUDSource:udSource]): take a new parameter named + 'ModulesContraints' that defines a set of constraints for + accessing specified named modules. This is an optout, meaning the + modules will be present unless a constraint is specified. + * SoObjects/Appointments/SOGoAppointmentFolder.m ([SOGoAppointmentFolder -roleForComponentsWithAccessClass:accessClassforUser:uid]): cache diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index c2edec3de..2124b609f 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -44,6 +44,8 @@ NSArray *mailFields; NSString *bindFields; + NSDictionary *modulesConstraints; + NGLdapConnection *ldapConnection; NSMutableArray *searchAttributes; } diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index b2cd7ad32..f3239afbe 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -170,6 +170,7 @@ static int sizeLimit; [bindFields release]; [ldapConnection release]; [sourceID release]; + [modulesConstraints release]; [super dealloc]; } @@ -189,6 +190,7 @@ static int sizeLimit; UIDField: [udSource objectForKey: @"UIDFieldName"] mailFields: [udSource objectForKey: @"MailFieldNames"] andBindFields: [udSource objectForKey: @"bindFields"]]; + ASSIGN (modulesConstraints, [udSource objectForKey: @"ModulesConstraints"]); return self; } @@ -351,6 +353,20 @@ static int sizeLimit; return [EOQualifier qualifierWithQualifierFormat: qs]; } +- (NSArray *) _contraintsFields +{ + NSMutableArray *fields; + NSEnumerator *values; + NSDictionary *currentConstraint; + + fields = [NSMutableArray array]; + values = [[modulesConstraints allValues] objectEnumerator]; + while ((currentConstraint = [values nextObject])) + [fields addObjectsFromArray: [currentConstraint allKeys]]; + + return fields; +} + - (NSArray *) _searchAttributes { if (!searchAttributes) @@ -361,6 +377,7 @@ static int sizeLimit; if (UIDField) [searchAttributes addObject: UIDField]; [searchAttributes addObjectsFromArray: mailFields]; + [searchAttributes addObjectsFromArray: [self _contraintsFields]]; [searchAttributes addObjectsFromArray: commonSearchFields]; } @@ -408,7 +425,8 @@ static int sizeLimit; emailFields = [mailFields objectEnumerator]; while ((currentFieldName = [emailFields nextObject])) { - value = [[ldapEntry attributeWithName: currentFieldName] stringValueAtIndex: 0]; + value = [[ldapEntry attributeWithName: currentFieldName] + stringValueAtIndex: 0]; if (value) [emails addObject: value]; } @@ -416,6 +434,38 @@ static int sizeLimit; [contactEntry setObject: emails forKey: @"c_emails"]; } +- (void) _fillConstraints: (NGLdapEntry *) ldapEntry + forModule: (NSString *) module + intoContactEntry: (NSMutableDictionary *) contactEntry +{ + NSDictionary *constraints; + NSEnumerator *matches; + NSString *currentMatch, *currentValue, *ldapValue; + BOOL result; + + result = YES; + + constraints = [modulesConstraints objectForKey: module]; + if (constraints) + { + matches = [[constraints allKeys] objectEnumerator]; + currentMatch = [matches nextObject]; + while (result && currentMatch) + { + ldapValue = [[ldapEntry attributeWithName: currentMatch] + stringValueAtIndex: 0]; + currentValue = [constraints objectForKey: currentMatch]; + if ([ldapValue isEqualToString: currentValue]) + currentMatch = [matches nextObject]; + else + result = NO; + } + } + + [contactEntry setObject: [NSNumber numberWithBool: result] + forKey: [NSString stringWithFormat: @"%@Access", module]]; +} + - (NSDictionary *) _convertLDAPEntryToContact: (NGLdapEntry *) ldapEntry { NSMutableDictionary *contactEntry; @@ -446,6 +496,10 @@ static int sizeLimit; value = @""; [contactEntry setObject: value forKey: @"c_cn"]; [self _fillEmailsOfEntry: ldapEntry intoContactEntry: contactEntry]; + [self _fillConstraints: ldapEntry forModule: @"Calendar" + intoContactEntry: (NSMutableDictionary *) contactEntry]; + [self _fillConstraints: ldapEntry forModule: @"Mail" + intoContactEntry: (NSMutableDictionary *) contactEntry]; return contactEntry; } diff --git a/SoObjects/SOGo/LDAPUserManager.m b/SoObjects/SOGo/LDAPUserManager.m index 6dcdd3afa..0e1168852 100644 --- a/SoObjects/SOGo/LDAPUserManager.m +++ b/SoObjects/SOGo/LDAPUserManager.m @@ -303,11 +303,17 @@ static NSString *defaultMailDomain = nil; LDAPSource *currentSource; NSString *cn, *c_uid; NSArray *c_emails; - + BOOL access; + emails = [NSMutableArray array]; cn = nil; c_uid = nil; + [currentUser setObject: [NSNumber numberWithBool: YES] + forKey: @"CalendarAccess"]; + [currentUser setObject: [NSNumber numberWithBool: YES] + forKey: @"MailAccess"]; + ldapSources = [sources objectEnumerator]; currentSource = [ldapSources nextObject]; while (currentSource) @@ -322,6 +328,14 @@ static NSString *defaultMailDomain = nil; c_emails = [userEntry objectForKey: @"c_emails"]; if ([c_emails count]) [emails addObjectsFromArray: c_emails]; + access = [[userEntry objectForKey: @"CalendarAccess"] boolValue]; + if (!access) + [currentUser setObject: [NSNumber numberWithBool: NO] + forKey: @"CalendarAccess"]; + access = [[userEntry objectForKey: @"MailAccess"] boolValue]; + if (!access) + [currentUser setObject: [NSNumber numberWithBool: NO] + forKey: @"MailAccess"]; } currentSource = [ldapSources nextObject]; } diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index d8f80102e..bc0513988 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -124,6 +124,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (BOOL) isSuperUser; +/* module access */ +- (BOOL) canAccessModule: (NSString *) module; + /* folders */ - (SOGoUserFolder *) homeFolderInContext: (id) context; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index ee1233596..bdf37fa0e 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -622,4 +622,15 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return [superUsernames containsObject: login]; } +/* module access */ +- (BOOL) canAccessModule: (NSString *) module +{ + NSString *accessValue; + + accessValue = [self _fetchFieldForUser: + [NSString stringWithFormat: @"%@Access", module]]; + + return [accessValue boolValue]; +} + @end /* SOGoUser */ diff --git a/SoObjects/SOGo/SOGoUserFolder.m b/SoObjects/SOGo/SOGoUserFolder.m index 5003c54d2..035cbcb47 100644 --- a/SoObjects/SOGo/SOGoUserFolder.m +++ b/SoObjects/SOGo/SOGoUserFolder.m @@ -24,6 +24,8 @@ #import #import +#import + #import #import @@ -64,12 +66,18 @@ - (NSArray *) toManyRelationshipKeys { - static NSArray *children = nil; + NSMutableArray *children; + SOGoUser *currentUser; - if (!children) - children = [[NSArray alloc] initWithObjects: - @"Calendar", @"Contacts", @"Mail", - @"Preferences", nil]; + children = [NSMutableArray arrayWithCapacity: 4]; + + currentUser = [context activeUser]; + if ([currentUser canAccessModule: @"Calendar"]) + [children addObject: @"Calendar"]; + [children addObject: @"Contacts"]; + if ([currentUser canAccessModule: @"Mail"]) + [children addObject: @"Mail"]; + [children addObject: @"Preferences"]; return children; } @@ -149,12 +157,15 @@ acquire: (BOOL) _flag { id obj; + SOGoUser *currentUser; /* first check attributes directly bound to the application */ obj = [super lookupName: _key inContext: _ctx acquire: NO]; if (!obj) { - if ([_key isEqualToString: @"Calendar"]) + currentUser = [_ctx activeUser]; + if ([_key isEqualToString: @"Calendar"] + && [currentUser canAccessModule: _key]) obj = [self privateCalendars: @"Calendar" inContext: _ctx]; // if (![_key isEqualToString: @"Calendar"]) // obj = [obj lookupName: [_key pathExtension] @@ -163,7 +174,8 @@ obj = [self privateContacts: _key inContext: _ctx]; // else if ([_key isEqualToString: @"Groups"]) // obj = [self groupsFolder: _key inContext: _ctx]; - else if ([_key isEqualToString: @"Mail"]) + else if ([_key isEqualToString: @"Mail"] + && [currentUser canAccessModule: _key]) obj = [self mailAccountsFolder: _key inContext: _ctx]; else if ([_key isEqualToString: @"Preferences"]) obj = [$(@"SOGoPreferencesFolder") objectWithName: _key diff --git a/UI/Common/UIxPageFrame.m b/UI/Common/UIxPageFrame.m index 47f9433ca..b3565daed 100644 --- a/UI/Common/UIxPageFrame.m +++ b/UI/Common/UIxPageFrame.m @@ -345,6 +345,24 @@ && [user isSuperUser]); } +- (BOOL) userHasCalendarAccess +{ + SOGoUser *user; + + user = [context activeUser]; + + return [user canAccessModule: @"Calendar"]; +} + +- (BOOL) userHasMailAccess +{ + SOGoUser *user; + + user = [context activeUser]; + + return [user canAccessModule: @"Mail"]; +} + /* browser/os identification */ - (BOOL) isCompatibleBrowser diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 192d8267e..c5f5bac42 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -483,7 +483,7 @@ static BOOL shouldDisplayPasswordChange = NO; - (NSString *) itemIdentityText { - return [item keysWithFormat: @"%{fullName} <%{email}>"]; + return [(NSDictionary *) item keysWithFormat: @"%{fullName} <%{email}>"]; } - (NSMutableDictionary *) defaultIdentity @@ -538,6 +538,16 @@ static BOOL shouldDisplayPasswordChange = NO; return [[request method] isEqualToString: @"POST"]; } +- (BOOL) userHasCalendarAccess +{ + return [user canAccessModule: @"Calendar"]; +} + +- (BOOL) userHasMailAccess +{ + return [user canAccessModule: @"Mail"]; +} + - (BOOL) shouldDisplayPasswordChange { return shouldDisplayPasswordChange; diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index bb01400d4..fde540e73 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -15,12 +15,16 @@
  • -
  • -
  • -
  • + +
  • +
    + +
  • +
  • +
  • @@ -45,43 +49,46 @@ /> -
    -
    - -
    -
    -
    -
    -
    - -
    -
    -
    -
    + +
    +
    + +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    -
    -
    - -
    -