Improved preferences module (save/load, checks on enabled modules, etc.)

This commit is contained in:
Ludovic Marcotte 2015-03-26 13:37:44 -04:00 committed by Francis Lachapelle
parent 48b74b0f6b
commit 2bc44dec9b
3 changed files with 212 additions and 127 deletions

View file

@ -35,24 +35,27 @@
@implementation UIxJSONPreferences
- (WOResponse *) _makeResponse: (SOGoUserProfile *) profile
- (WOResponse *) _makeResponse: (NSDictionary *) values
{
WOResponse *response;
response = [context response];
[response setHeader: @"text/plain; charset=utf-8"
forKey: @"content-type"];
[response appendContentString: [profile jsonRepresentation]];
[response appendContentString: [values jsonRepresentation]];
return response;
}
- (WOResponse *) jsonDefaultsAction
{
NSMutableDictionary *values;
SOGoUserDefaults *defaults;
NSArray *categoryLabels;
BOOL dirty;
defaults = [[context activeUser] userDefaults];
dirty = NO;
if (![[defaults source] objectForKey: @"SOGoLongDateFormat"])
[[defaults source] setObject: @"default" forKey: @"SOGoLongDateFormat"];
@ -65,6 +68,7 @@
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
[defaults setCalendarCategories: categoryLabels];
dirty = YES;
}
// Populate default contact categories, based on the user's preferred language
@ -78,6 +82,7 @@
categoryLabels = [NSArray array];
[defaults setContactsCategories: categoryLabels];
dirty = YES;
}
// Populate default mail lablels, based on the user's preferred language
@ -90,12 +95,19 @@
// TODO - translate + refactor to not pass self since it's not a component
//[defaults setMailLabelsColors: [SOGoMailLabel labelsFromDefaults: v component: self]];
[defaults setMailLabelsColors: v];
dirty = YES;
}
if (dirty)
[defaults synchronize];
return [self _makeResponse: [defaults source]];
// We inject our default mail account, something we don't want to do before we
// call -synchronize on our defaults.
values = [[[[defaults source] values] mutableCopy] autorelease];
[[values objectForKey: @"AuxiliaryMailAccounts"] insertObject: [[[context activeUser] mailAccounts] objectAtIndex: 0]
atIndex: 0];
return [self _makeResponse: values];
}
- (WOResponse *) jsonSettingsAction
@ -104,7 +116,7 @@
settings = [[context activeUser] userSettings];
return [self _makeResponse: [settings source]];
return [self _makeResponse: [[settings source] values]];
}
@end

View file

@ -1746,7 +1746,12 @@ static NSArray *reminderValues = nil;
return [[user domainDefaults] mailAuxiliaryUserAccountsEnabled];
}
//
// Used internally
//
- (void) _extractMainIdentity: (NSDictionary *) identity
inDictionary: (NSMutableDictionary *) target
{
/* We perform some validation here as we have no guaranty on the input
validity. */
@ -1755,9 +1760,11 @@ static NSArray *reminderValues = nil;
if ([identity isKindOfClass: [NSDictionary class]])
{
value = [identity objectForKey: @"signature"];
if (!value)
value = @"";
[userDefaults setMailSignature: value];
if (value)
[target setObject: value forKey: @"SOGoMailSignature"];
else
[target removeObjectForKey: @"SOGoMailSignature"];
if (mailCustomFromEnabled)
{
@ -1769,22 +1776,37 @@ static NSArray *reminderValues = nil;
if ([value length] == 0
|| [[user allEmails] containsObject: value])
value = nil;
[userDefaults setMailCustomEmail: value];
if (value)
[target setObject: value forKey: @"SOGoMailCustomEmail"];
else
[target removeObjectForKey: @"SOGoMailCustomEmail"];
value = [[identity objectForKey: @"fullName"]
stringByTrimmingSpaces];
if ([value length] == 0
|| [[user cn] isEqualToString: value])
value = nil;
[userDefaults setMailCustomFullName: value];
if (value)
[target setObject: value forKey: @"SOGoMailCustomFullName"];
else
[target removeObjectForKey: @"SOGoMailCustomFullName"];
}
value = [[identity objectForKey: @"replyTo"]
stringByTrimmingSpaces];
[userDefaults setMailReplyTo: value];
if (value && [value length] > 0)
[target setObject: value forKey: @"SOGoMailReplyTo"];
else
[target removeObjectForKey: @"SOGoMailReplyTo"];
}
}
//
// Used internally
//
- (BOOL) _validateReceiptAction: (NSString *) action
{
return ([action isKindOfClass: [NSString class]]
@ -1793,7 +1815,12 @@ static NSArray *reminderValues = nil;
|| [action isEqualToString: @"ask"]));
}
//
// Used internally
//
- (void) _extractMainReceiptsPreferences: (NSDictionary *) receipts
inDictionary: (NSMutableDictionary *) target
{
/* We perform some validation here as we have no guaranty on the input
validity. */
@ -1802,31 +1829,39 @@ static NSArray *reminderValues = nil;
if ([receipts isKindOfClass: [NSDictionary class]])
{
action = [receipts objectForKey: @"receiptAction"];
[userDefaults
setAllowUserReceipt: [action isEqualToString: @"allow"]];
[target setObject: @"1" forKey: @"SOGoMailReceiptAllow"];
action = [receipts objectForKey: @"receiptNonRecipientAction"];
if ([self _validateReceiptAction: action])
[userDefaults setUserReceiptNonRecipientAction: action];
[target setObject: action forKey: @"SOGoMailReceiptNonRecipientAction"];
action = [receipts objectForKey: @"receiptOutsideDomainAction"];
if ([self _validateReceiptAction: action])
[userDefaults setUserReceiptOutsideDomainAction: action];
[target setObject: action forKey: @"SOGoMailReceiptOutsideDomainAction"];
action = [receipts objectForKey: @"receiptAnyAction"];
if ([self _validateReceiptAction: action])
[userDefaults setUserReceiptAnyAction: action];
[target setObject: action forKey: @"SOGoMailReceiptAnyAction"];
}
}
//
// Used internally
//
- (void) _extractMainCustomFrom: (NSDictionary *) account
{
}
//
// Used internally
//
- (void) _extractMainReplyTo: (NSDictionary *) account
{
}
//
// Used internally
//
- (BOOL) _validateAccountIdentities: (NSArray *) identities
{
static NSString *identityKeys[] = { @"fullName", @"email", nil };
@ -1880,6 +1915,9 @@ static NSArray *reminderValues = nil;
return valid;
}
//
// Used internally
//
- (BOOL) _validateAccount: (NSDictionary *) account
{
static NSString *accountKeys[] = { @"name", @"serverName", @"userName",
@ -1934,7 +1972,11 @@ static NSArray *reminderValues = nil;
return valid;
}
//
// Used internally
//
- (void) _extractMainAccountSettings: (NSDictionary *) account
inDictionary: (NSMutableDictionary *) target
{
NSArray *identities;
@ -1943,12 +1985,15 @@ static NSArray *reminderValues = nil;
identities = [account objectForKey: @"identities"];
if ([identities isKindOfClass: [NSArray class]]
&& [identities count] > 0)
[self _extractMainIdentity: [identities objectAtIndex: 0]];
[self _extractMainReceiptsPreferences: [account objectForKey: @"receipts"]];
[self _extractMainIdentity: [identities objectAtIndex: 0] inDictionary: target];
[self _extractMainReceiptsPreferences: [account objectForKey: @"receipts"] inDictionary: target];
}
}
- (void) _extractAuxiliaryAccounts: (NSArray *) accounts
//
// Used internally
//
- (NSArray *) _extractAuxiliaryAccounts: (NSArray *) accounts
{
int count, max, oldMax;
NSArray *oldAccounts;
@ -1984,7 +2029,7 @@ static NSArray *reminderValues = nil;
}
}
[userDefaults setAuxiliaryMailAccounts: auxAccounts];
return auxAccounts;
}
// - (void) setMailAccounts: (NSString *) newMailAccounts
@ -2027,6 +2072,9 @@ static NSArray *reminderValues = nil;
return (mailCustomFromEnabled ? @"true" : @"false");
}
//
//
//
- (id <WOActionResults>) saveAction
{
id o, v;
@ -2037,8 +2085,8 @@ static NSArray *reminderValues = nil;
if ((v = [o objectForKey: @"defaults"]))
{
NSMutableDictionary *sanitizedLabels;
NSArray *allKeys, *accounts;
NSDictionary *newLabels;
NSArray *allKeys;
NSString *name;
int i;
@ -2068,6 +2116,22 @@ static NSArray *reminderValues = nil;
[v setObject: sanitizedLabels forKey: @"SOGoMailLabelsColors"];
}
// We sanitize our auxilary mail accounts
accounts = [v objectForKey: @"AuxiliaryMailAccounts"];
if (accounts && [accounts isKindOfClass: [NSArray class]])
{
if ([accounts count] > 0)
{
[self _extractMainAccountSettings: [accounts objectAtIndex: 0] inDictionary: v];
if ([self mailAuxiliaryUserAccountsEnabled])
accounts = [self _extractAuxiliaryAccounts: accounts];
else
accounts = [NSArray array];
[v setObject: accounts forKey: @"AuxiliaryMailAccounts"];
}
}
[[[user userDefaults] source] setValues: v];
[[user userDefaults] synchronize];
}

View file

@ -669,6 +669,7 @@
<!-- MAIL > FILTERS -->
<var:if condition="isSieveScriptsEnabled">
<md-tab id="mailFiltersTab"
aria-controls="mailFiltersTab-content"
label:label="Filters">
@ -707,6 +708,7 @@
</div>
</div>
</md-tab>
</var:if>
<!-- END OF MAIL > FILTERS -->
<!-- MAIL > LABELS -->
@ -748,29 +750,35 @@
track by $index">
<md-item-content>
<md-input-container>
<input type="text" ng-model="preferences.defaults.AuxiliaryMailAccounts[$index].name"/>
<input type="text"
ng-model="preferences.defaults.AuxiliaryMailAccounts[$index].name"
ng-readonly="$index == 0"/>
</md-input-container>
<md-button ng-click="editMailAccount($index)" type="button">
<div class="md-icon-edit md-icon-lg"><!-- edit --></div>
</md-button>
<md-button ng-click="removeMailAccount()" type="button">
<md-button ng-click="removeMailAccount()"
ng-show="$index > 0" type="button">
<div class="md-icon-remove md-icon-lg"><!-- delete --></div>
</md-button>
</md-item-content>
</md-item>
</md-list>
<var:if condition="mailAuxiliaryUserAccountsEnabled">
<div class="bottomToolbar">
<md-button ng-click="addMailAccount()" type="button">
<div class="md-icon-add"><!-- create --></div>
</md-button>
</div>
</var:if>
</md-tab>
<!-- END OF MAIL > ACCOUNTS -->
<!-- MAIL > VACATION -->
<var:if condition="isVacationEnabled">
<md-tab id="mailVacationTab" aria-controls="mailVacationTab-content" label:label="Vacation">
<div role="tabpanel" aria-labelledby="mailVacationView" id="mailVacationView-content">
@ -848,12 +856,13 @@
</div>
</md-tab>
</var:if>
<!-- END OF MAIL > VACATION -->
<!-- MAIL > FORWARD -->
<var:if condition="isForwardEnabled">
<md-tab id="mailForwardTab" aria-controls="mailForwardTab-content" label:label="Forward">
<div role="tabpanel" aria-labelledby="mailForwardView" id="mailForwardView-content">
<var:if condition="isForwardEnabled">
<div id="forwardView" class="tab">
<md-checkbox
ng-model="preferences.defaults.Forward.enabled"
@ -882,9 +891,9 @@
</script>
</div>
</var:if>
</div>
</md-tab>
</var:if>
<!-- END OF MAIL > FORWARD -->