improved handling of SOGoSubscriptionFolderFormat

This commit is contained in:
Ludovic Marcotte
2014-07-24 12:48:03 -04:00
parent 5de51e8aa1
commit f6ef94a631
8 changed files with 96 additions and 51 deletions
+59 -31
View File
@@ -216,18 +216,17 @@ static NSArray *childRecordFields = nil;
- (void) setFolderPropertyValue: (id) theValue
inCategory: (NSString *) theKey
settings: (SOGoUserSettings *) theSettings
{
SOGoUserSettings *settings;
NSMutableDictionary *folderSettings, *values;
NSString *module;
settings = [[context activeUser] userSettings];
module = [container nameInContainer];
folderSettings = [settings objectForKey: module];
folderSettings = [theSettings objectForKey: module];
if (!folderSettings)
{
folderSettings = [NSMutableDictionary dictionary];
[settings setObject: folderSettings forKey: module];
[theSettings setObject: folderSettings forKey: module];
}
values = [folderSettings objectForKey: theKey];
if (theValue)
@@ -249,7 +248,19 @@ static NSArray *childRecordFields = nil;
[folderSettings removeObjectForKey: theKey];
}
[settings synchronize];
[theSettings synchronize];
}
- (void) setFolderPropertyValue: (id) theValue
inCategory: (NSString *) theKey
{
SOGoUserSettings *settings;
settings = [[context activeUser] userSettings];
[self setFolderPropertyValue: theValue
inCategory: theKey
settings: settings];
}
- (id) folderPropertyValueInCategory: (NSString *) theKey
@@ -281,34 +292,19 @@ static NSArray *childRecordFields = nil;
SOGoDomainDefaults *dd;
primaryDN = [row objectForKey: @"c_foldername"];
if ([primaryDN length])
{
displayName = [NSMutableString new];
if ([primaryDN isEqualToString: [container defaultFolderName]])
[displayName appendString: [self labelForKey: primaryDN
inContext: context]];
else
[displayName appendString: primaryDN];
if (!activeUserIsOwner)
{
// We MUST NOT use SOGoUser instances here (by calling -primaryIdentity)
// as it'll load user defaults and user settings which is _very costly_
// since it involves JSON parsing and database requests
ownerIdentity = [[SOGoUserManager sharedUserManager]
contactInfosForUserWithUIDorEmail: owner];
folderSubscriptionValues = [[NSMutableDictionary alloc] initWithObjectsAndKeys: displayName, @"FolderName",
[ownerIdentity objectForKey: @"cn"], @"UserName",
[ownerIdentity objectForKey: @"c_email"], @"Email", nil];
DESTROY(displayName);
dd = [[context activeUser] domainDefaults];
subjectFormat = [dd subscriptionFolderFormat];
if ([primaryDN isEqualToString: [container defaultFolderName]])
displayName = [self labelForKey: primaryDN
inContext: context];
else
displayName =primaryDN;
displayName = [folderSubscriptionValues keysWithFormat: subjectFormat];
[displayName retain];
RETAIN(displayName);
}
}
}
/* This method fetches the display name defined by the owner, but is also the
@@ -365,6 +361,7 @@ static NSArray *childRecordFields = nil;
else
{
[self _fetchDisplayNameFromSubscriber];
if (!displayName)
[self _fetchDisplayNameFromOwner];
}
@@ -856,11 +853,15 @@ static NSArray *childRecordFields = nil;
- (BOOL) subscribeUserOrGroup: (NSString *) theIdentifier
reallyDo: (BOOL) reallyDo
response: (WOResponse *) theResponse
{
NSDictionary *ownerIdentity, *folderSubscriptionValues;
NSMutableDictionary *moduleSettings, *folderShowAlarms;
NSString *subjectFormat, *formattedName;
NSMutableArray *folderSubscription;
NSString *subscriptionPointer;
NSMutableArray *allUsers;
SOGoDomainDefaults *dd;
SOGoUserSettings *us;
NSDictionary *dict;
SOGoUser *sogoUser;
@@ -892,6 +893,26 @@ static NSArray *childRecordFields = nil;
}
rc = NO;
// We MUST NOT use SOGoUser instances here (by calling -primaryIdentity)
// as it'll load user defaults and user settings which is _very costly_
// since it involves JSON parsing and database requests
ownerIdentity = [[SOGoUserManager sharedUserManager]
contactInfosForUserWithUIDorEmail: owner];
folderSubscriptionValues = [[NSDictionary alloc] initWithObjectsAndKeys: [self displayName], @"FolderName",
[ownerIdentity objectForKey: @"cn"], @"UserName",
[ownerIdentity objectForKey: @"c_email"], @"Email", nil];
dd = [[context activeUser] domainDefaults];
subjectFormat = [dd subscriptionFolderFormat];
formattedName = [folderSubscriptionValues keysWithFormat: subjectFormat];
// This is consumed by SOGo Integrator during folder subscription since v24.0.6
if (theResponse)
[theResponse appendContentString: formattedName];
for (i = 0; i < [allUsers count]; i++)
{
@@ -929,6 +950,10 @@ static NSArray *childRecordFields = nil;
forKey: @"FolderShowAlarms"];
}
[self setFolderPropertyValue: formattedName
inCategory: @"FolderDisplayNames"
settings: us];
[folderSubscription addObjectUniquely: subscriptionPointer];
// By default, we disable alarms on subscribed calendars
@@ -987,7 +1012,7 @@ static NSArray *childRecordFields = nil;
response = [context response];
[response setHeader: @"text/plain; charset=utf-8"
forKey: @"Content-Type"];
[response setStatus: 204];
[response setStatus: 200];
currentUser = [context activeUser];
delegatedUsers = [self _parseDAVDelegatedUsers];
@@ -1002,7 +1027,8 @@ static NSArray *childRecordFields = nil;
create contention on GDNC. */
for (count = 0; count < max; count++)
[self subscribeUserOrGroup: [delegatedUsers objectAtIndex: count]
reallyDo: reallyDo];
reallyDo: reallyDo
response: response];
}
else
{
@@ -1021,7 +1047,9 @@ static NSArray *childRecordFields = nil;
@"You cannot (un)subscribe to a folder that you own!"];
}
else
[self subscribeUserOrGroup: userLogin reallyDo: reallyDo];
[self subscribeUserOrGroup: userLogin
reallyDo: reallyDo
response: response];
}
return response;