Skip to content

Commit

Permalink
fix(core): don't auto-remove a subscription if any source is in error
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed May 11, 2022
1 parent ab5f5ab commit 373ac51
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
5 changes: 5 additions & 0 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ - (NGLdapConnection *) _ldapConnection
return (NGLdapConnection *)[self connection];
}

- (BOOL) isConnected
{
return [[self _ldapConnection] isBound];
}

- (void) releaseConnection: (id) connection
{
if ([(NGLdapConnection *)connection isBound])
Expand Down
36 changes: 28 additions & 8 deletions SoObjects/SOGo/SOGoParentFolder.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -307,15 +309,17 @@ - (BOOL) _appendSubscribedSource: (NSString *) sourceKey

- (NSException *) appendSubscribedSources
{
NSMutableDictionary *folderDisplayNames;
BOOL dirty, safeCheck, isConnected;
NSEnumerator *sources;
NSException *error;
NSMutableArray *subscribedReferences;
SOGoUserSettings *settings;
NSString *activeUser, *currentKey;
NSMutableDictionary *folderDisplayNames;
NSObject <SOGoSource> *currentSource;
NSString *activeUser, *domain, *currentKey;
SOGoUser *ownerUser;
NSException *error;
SOGoUserSettings *settings;
id o;
int i;
BOOL dirty;

if (!subscribedSubFolders)
subscribedSubFolders = [NSMutableDictionary new];
Expand All @@ -325,8 +329,11 @@ - (NSException *) appendSubscribedSources

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];

Expand All @@ -348,8 +355,21 @@ - (NSException *) appendSubscribedSources
[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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions SoObjects/SOGo/SOGoSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion SoObjects/SOGo/SOGoUserManager.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,6 +54,7 @@

- (NSString *) registryClass;

- (NSArray *) sourcesInDomain: (NSString *) domain;
- (NSArray *) sourceIDsInDomain: (NSString *) domain;
- (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain;
- (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain;
Expand Down
24 changes: 23 additions & 1 deletion SoObjects/SOGo/SOGoUserManager.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -212,6 +212,28 @@ - (NSString *) registryClass
return @"SOGoUserManagerRegistry";
}

- (NSArray *) sourcesInDomain: (NSString *) domain
{
NSMutableArray *sources;
NSArray *allSources;
int count, max;
NSString *sourceDomain;
NSObject <SOGoSource> *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;
Expand Down
5 changes: 5 additions & 0 deletions SoObjects/SOGo/SQLSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ - (id) connection
return channel;
}

- (BOOL) isConnected
{
return [self connection];
}

- (void) releaseConnection: (id) connection
{
GCSChannelManager *cm;
Expand Down

0 comments on commit 373ac51

Please sign in to comment.