perf(calendar(web)): initiate Web calendars reload from the frontend

The Web calendars subsciptions marked to be reloaded on login are no
longer reloaded from the backend; the sync operation is now activated
from the frontend in XHR calls to avoid blocking the Web interface.

Fixes #4939
master
Francis Lachapelle 2021-10-06 14:16:48 -04:00
parent ef64c13410
commit f017c42608
3 changed files with 61 additions and 13 deletions

View File

@ -35,8 +35,6 @@
#import <NGExtensions/NSObject+Logs.h> #import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSObject+Values.h> #import <NGExtensions/NSObject+Values.h>
#import <Appointments/SOGoAppointmentFolders.h>
#import <SOGo/NSString+Crypto.h> #import <SOGo/NSString+Crypto.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoBuild.h> #import <SOGo/SOGoBuild.h>
@ -49,6 +47,7 @@
#import <SOGo/SOGoSystemDefaults.h> #import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserManager.h> #import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoWebAuthenticator.h> #import <SOGo/SOGoWebAuthenticator.h>
#if defined(MFA_CONFIG) #if defined(MFA_CONFIG)
@ -173,6 +172,26 @@
andJSONRepresentation: jsonError]; andJSONRepresentation: jsonError];
} }
- (void) _checkAutoReloadWebCalendars: (SOGoUser *) loggedInUser
{
NSDictionary *autoReloadedWebCalendars;
NSMutableDictionary *moduleSettings;
SOGoUserSettings *us;
us = [loggedInUser userSettings];
moduleSettings = [us objectForKey: @"Calendar"];
if (moduleSettings)
{
autoReloadedWebCalendars = [moduleSettings objectForKey: @"AutoReloadedWebCalendars"];
if ([[autoReloadedWebCalendars allValues] containsObject: [NSNumber numberWithInt: 1]])
{
[moduleSettings setObject: [NSNumber numberWithBool: YES] forKey: @"ReloadWebCalendars"];
[us synchronize];
}
}
}
// //
// //
// //
@ -182,7 +201,6 @@
WORequest *request; WORequest *request;
WOCookie *authCookie, *xsrfCookie; WOCookie *authCookie, *xsrfCookie;
SOGoWebAuthenticator *auth; SOGoWebAuthenticator *auth;
SOGoAppointmentFolders *calendars;
SOGoUserDefaults *ud; SOGoUserDefaults *ud;
SOGoUser *loggedInUser; SOGoUser *loggedInUser;
NSDictionary *params; NSDictionary *params;
@ -294,6 +312,8 @@
} }
#endif #endif
[self _checkAutoReloadWebCalendars: loggedInUser];
json = [NSDictionary dictionaryWithObjectsAndKeys: json = [NSDictionary dictionaryWithObjectsAndKeys:
[loggedInUser cn], @"cn", [loggedInUser cn], @"cn",
[NSNumber numberWithInt: expire], @"expire", [NSNumber numberWithInt: expire], @"expire",
@ -323,10 +343,6 @@
[ud setLanguage: language]; [ud setLanguage: language];
[ud synchronize]; [ud synchronize];
} }
calendars = [loggedInUser calendarsFolderInContext: context];
if ([calendars respondsToSelector: @selector (reloadWebCalendars:)])
[calendars reloadWebCalendars: NO];
} }
else else
{ {
@ -382,7 +398,6 @@
{ {
WOResponse *response; WOResponse *response;
NSString *login, *logoutRequest, *newLocation, *oldLocation, *ticket; NSString *login, *logoutRequest, *newLocation, *oldLocation, *ticket;
SOGoAppointmentFolders *calendars;
SOGoCASSession *casSession; SOGoCASSession *casSession;
SOGoUser *loggedInUser; SOGoUser *loggedInUser;
SOGoWebAuthenticator *auth; SOGoWebAuthenticator *auth;
@ -450,9 +465,7 @@
} }
loggedInUser = [SOGoUser userWithLogin: login]; loggedInUser = [SOGoUser userWithLogin: login];
calendars = [loggedInUser calendarsFolderInContext: context]; [self _checkAutoReloadWebCalendars: loggedInUser];
if ([calendars respondsToSelector: @selector (reloadWebCalendars:)])
[calendars reloadWebCalendars: NO];
} }
else else
{ {
@ -476,6 +489,7 @@
{ {
WOResponse *response; WOResponse *response;
NSString *login, *newLocation, *oldLocation; NSString *login, *newLocation, *oldLocation;
SOGoUser *loggedInUser;
WOCookie *saml2LocationCookie; WOCookie *saml2LocationCookie;
WORequest *rq; WORequest *rq;
@ -500,6 +514,9 @@
newLocation = [NSString stringWithFormat: @"%@%@", newLocation = [NSString stringWithFormat: @"%@%@",
oldLocation, [login stringByEscapingURL]]; oldLocation, [login stringByEscapingURL]];
} }
loggedInUser = [SOGoUser userWithLogin: login];
[self _checkAutoReloadWebCalendars: loggedInUser];
} }
else else
{ {

View File

@ -1567,6 +1567,14 @@ static NSArray *reminderValues = nil;
if ((v = [o objectForKey: @"settings"])) if ((v = [o objectForKey: @"settings"]))
{ {
// Remove ReloadWebCalendars if necessary
NSMutableDictionary *calendarModule = [o objectForKey: @"Calendar"];
if (calendarModule && [calendarModule objectForKey: @"ReloadWebCalendars"] == nil)
{
calendarModule = [[user userSettings] objectForKey: @"Calendar"];
[calendarModule removeObjectForKey: @"ReloadWebCalendars"];
}
[[[user userSettings] source] setValues: v]; [[[user userSettings] source] setValues: v];
[[user userSettings] synchronize]; [[user userSettings] synchronize];
} }

View File

@ -180,8 +180,30 @@
data = {}; data = {};
} }
// We convert our PreventInvitationsWhitelist hash into a array of user
if (data.Calendar) { if (data.Calendar) {
// When the Calendar settings include "AutoReloadedWebCalendars", reload the Web calendars
// marked to be reloaded on login (AutoReloadedWebCalendars). Once completed, remove the
// parameter and save the settings.
if (data.Calendar.ReloadWebCalendars && data.Calendar.AutoReloadedWebCalendars) {
var reloadPromises = [];
_.map(data.Calendar.AutoReloadedWebCalendars, function (autoReload, id) {
if (autoReload) {
var calendarId = id.split('/')[1],
deferred = Preferences.$q.defer();
Preferences.$$resource.quietFetch('Calendar/' + calendarId, 'reload').finally(deferred.resolve);
reloadPromises.push(deferred.promise);
}
});
Preferences.$q.all(reloadPromises).then(function() {
delete _this.settings.Calendar.ReloadWebCalendars;
Preferences.$$resource.save("Preferences", { settings: _this.$omit(true).settings }).then(function () {
Preferences.$rootScope.$emit('calendars:list');
});
});
}
// We convert our PreventInvitationsWhitelist hash into a array of user
if (data.Calendar.PreventInvitationsWhitelist) { if (data.Calendar.PreventInvitationsWhitelist) {
data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) { data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) {
var match = /^(.+)\s<(\S+)>$/.exec(value), var match = /^(.+)\s<(\S+)>$/.exec(value),
@ -204,10 +226,11 @@
* @desc The factory we'll use to register with Angular * @desc The factory we'll use to register with Angular
* @returns the Preferences constructor * @returns the Preferences constructor
*/ */
Preferences.$factory = ['$window', '$document', '$q', '$timeout', '$log', '$state', '$mdDateLocale', '$mdToast', 'sgSettings', 'Gravatar', 'Resource', 'User', function($window, $document, $q, $timeout, $log, $state, $mdDateLocaleProvider, $mdToast, Settings, Gravatar, Resource, User) { Preferences.$factory = ['$window', '$document', '$rootScope', '$q', '$timeout', '$log', '$state', '$mdDateLocale', '$mdToast', 'sgSettings', 'Gravatar', 'Resource', 'User', function($window, $document, $rootScope, $q, $timeout, $log, $state, $mdDateLocaleProvider, $mdToast, Settings, Gravatar, Resource, User) {
angular.extend(Preferences, { angular.extend(Preferences, {
$window: $window, $window: $window,
$document: $document, $document: $document,
$rootScope: $rootScope,
$q: $q, $q: $q,
$timeout: $timeout, $timeout: $timeout,
$log: $log, $log: $log,