refactor(preferences): conditionally activate the Sieve script

All the user defaults are now editable through the Preferences module,
even if an external Sieve script is enabled. However, the user can
disable the external Sieve script and force the activation of the
"sogo" Sieve script.
This commit is contained in:
Francis Lachapelle
2019-11-15 14:37:35 -05:00
parent 350677bbce
commit 5b3d84ee24
8 changed files with 137 additions and 94 deletions

View File

@@ -25,18 +25,23 @@
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGExtensions/NSObject+Logs.h>
#import <NGImap4/NGSieveClient.h>
#import <SOPE/NGCards/iCalRecurrenceRule.h>
#import <SOGo/NSObject+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoSieveManager.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoUserProfile.h>
#import <SOGo/WOResourceManager+SOGo.h>
#import <SOGoUI/UIxComponent.h>
#import <Mailer/SOGoMailAccount.h>
#import <Mailer/SOGoMailAccounts.h>
#import <Mailer/SOGoMailLabel.h>
#import "UIxJSONPreferences.h"
@@ -71,6 +76,27 @@ static SoProduct *preferencesProduct = nil;
return labelsDictionary;
}
//
// Used internally
//
- (BOOL) _hasActiveExternalSieveScripts
{
NGSieveClient *client;
SOGoMailAccount *account;
SOGoMailAccounts *folder;
SOGoSieveManager *manager;
folder = [[[context activeUser] homeFolderInContext: context] mailAccountsFolder: @"Mail" inContext: context];
account = [folder lookupName: @"0" inContext: context acquire: NO];
manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]];
client = [manager clientForAccount: account];
if (client)
return [manager hasActiveExternalSieveScripts: client];
return NO;
}
- (WOResponse *) jsonDefaultsAction
{
return [self responseWithStatus: 200
@@ -401,6 +427,9 @@ static SoProduct *preferencesProduct = nil;
[values setObject: vacation forKey: @"Vacation"];
}
// Detect if an external Sieve script is active
[values setObject: [NSNumber numberWithBool: [self _hasActiveExternalSieveScripts]] forKey: @"hasActiveExternalSieveScripts"];
return [values jsonRepresentation];
}