diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 40fa2481c..226ac76f6 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -497,6 +497,11 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses return (NGLdapConnection *)[self connection]; } +- (BOOL) isConnected +{ + return [[self _ldapConnection] isBound]; +} + - (void) releaseConnection: (id) connection { if ([(NGLdapConnection *)connection isBound]) diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m index 22cad405a..67ecba927 100644 --- a/SoObjects/SOGo/SOGoParentFolder.m +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -1,6 +1,6 @@ /* SOGoParentFolder.m - this file is part of SOGo * - * Copyright (C) 2006-2017 Inverse inc. + * Copyright (C) 2006-2022 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 @@ -36,7 +36,9 @@ #import "NSObject+DAV.h" #import "SOGoGCSFolder.h" #import "SOGoPermissions.h" +#import "SOGoSource.h" #import "SOGoUser.h" +#import "SOGoUserManager.h" #import "SOGoWebDAVAclManager.h" #import "SOGoParentFolder.h" @@ -307,15 +309,17 @@ static SoSecurityManager *sm = nil; - (NSException *) appendSubscribedSources { - NSMutableDictionary *folderDisplayNames; - NSMutableArray *subscribedReferences; - SOGoUserSettings *settings; - NSString *activeUser, *currentKey; - SOGoUser *ownerUser; + BOOL dirty, safeCheck, isConnected; + NSEnumerator *sources; NSException *error; + NSMutableArray *subscribedReferences; + NSMutableDictionary *folderDisplayNames; + NSObject *currentSource; + NSString *activeUser, *domain, *currentKey; + SOGoUser *ownerUser; + SOGoUserSettings *settings; id o; int i; - BOOL dirty; if (!subscribedSubFolders) subscribedSubFolders = [NSMutableDictionary new]; @@ -325,8 +329,11 @@ static SoSecurityManager *sm = nil; error = nil; /* we ignore non-DB errors at this time... */ dirty = NO; + safeCheck = NO; + isConnected = YES; activeUser = [[context activeUser] login]; + domain = [[context activeUser] domain]; ownerUser = [SOGoUser userWithLogin: owner]; settings = [ownerUser userSettings]; @@ -348,8 +355,21 @@ static SoSecurityManager *sm = nil; [subscribedReferences removeObject: currentKey]; [folderDisplayNames removeObjectForKey: currentKey]; if ([owner isEqualToString: activeUser]) - // Synchronize settings only if the subscription is owned by the active user - dirty = YES; + { + // Safe check -- don't remove the subscription if any of the users sources has a connection failure. + if (!safeCheck) + { + safeCheck = YES; + sources = [[[SOGoUserManager sharedUserManager] sourcesInDomain: domain] objectEnumerator]; + while (isConnected && (currentSource = [sources nextObject])) + { + isConnected = isConnected && [currentSource isConnected]; + } + } + if (isConnected) + // Synchronize settings only if the subscription is owned by the active user + dirty = YES; + } } } diff --git a/SoObjects/SOGo/SOGoSource.h b/SoObjects/SOGo/SOGoSource.h index c29f186a6..6d861a2b2 100644 --- a/SoObjects/SOGo/SOGoSource.h +++ b/SoObjects/SOGo/SOGoSource.h @@ -43,6 +43,7 @@ - (id) connection; - (void) releaseConnection: (id) connection; +- (BOOL) isConnected; /* requires a "." to obtain the full list of contacts */ - (void) setListRequiresDot: (BOOL) aBool; diff --git a/SoObjects/SOGo/SOGoUserManager.h b/SoObjects/SOGo/SOGoUserManager.h index dbf656dc5..39e121080 100644 --- a/SoObjects/SOGo/SOGoUserManager.h +++ b/SoObjects/SOGo/SOGoUserManager.h @@ -1,6 +1,6 @@ /* SOGoUserManager.h - this file is part of SOGo * - * Copyright (C) 2007-2015 Inverse inc. + * Copyright (C) 2007-2022 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 @@ -54,6 +54,7 @@ - (NSString *) registryClass; +- (NSArray *) sourcesInDomain: (NSString *) domain; - (NSArray *) sourceIDsInDomain: (NSString *) domain; - (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain; - (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 985205a23..bebbc5705 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -1,6 +1,6 @@ /* SOGoUserManager.m - this file is part of SOGo * - * Copyright (C) 2007-2015 Inverse inc. + * Copyright (C) 2007-2021 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 @@ -212,6 +212,28 @@ static Class NSNullK; return @"SOGoUserManagerRegistry"; } +- (NSArray *) sourcesInDomain: (NSString *) domain +{ + NSMutableArray *sources; + NSArray *allSources; + int count, max; + NSString *sourceDomain; + NSObject *currentSource; + + allSources = [_sources allValues]; + max = [allSources count]; + sources = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + currentSource = [allSources objectAtIndex: count]; + sourceDomain = [currentSource domain]; + if (![sourceDomain length] || [sourceDomain isEqualToString: domain]) + [sources addObject: currentSource]; + } + + return sources; +} + - (NSArray *) sourceIDsInDomain: (NSString *) domain { NSMutableArray *sourceIDs; diff --git a/SoObjects/SOGo/SQLSource.m b/SoObjects/SOGo/SQLSource.m index 2f566b012..d17d8f7a0 100644 --- a/SoObjects/SOGo/SQLSource.m +++ b/SoObjects/SOGo/SQLSource.m @@ -445,6 +445,11 @@ return channel; } +- (BOOL) isConnected +{ + return [self connection]; +} + - (void) releaseConnection: (id) connection { GCSChannelManager *cm;