Skip to content

Commit

Permalink
perf(calendar(web)): initiate Web calendars reload from the frontend
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cgx committed Oct 6, 2021
1 parent ef64c13 commit f017c42
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
39 changes: 28 additions & 11 deletions UI/MainUI/SOGoRootPage.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSObject+Values.h>

#import <Appointments/SOGoAppointmentFolders.h>

#import <SOGo/NSString+Crypto.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoBuild.h>
Expand All @@ -49,6 +47,7 @@
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoWebAuthenticator.h>

#if defined(MFA_CONFIG)
Expand Down Expand Up @@ -173,6 +172,26 @@ - (WOResponse *) _responseWithLDAPPolicyError: (int) error
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];
}
}
}

//
//
//
Expand All @@ -182,7 +201,6 @@ - (WOResponse *) connectAction
WORequest *request;
WOCookie *authCookie, *xsrfCookie;
SOGoWebAuthenticator *auth;
SOGoAppointmentFolders *calendars;
SOGoUserDefaults *ud;
SOGoUser *loggedInUser;
NSDictionary *params;
Expand Down Expand Up @@ -294,6 +312,8 @@ - (WOResponse *) connectAction
}
#endif

[self _checkAutoReloadWebCalendars: loggedInUser];

json = [NSDictionary dictionaryWithObjectsAndKeys:
[loggedInUser cn], @"cn",
[NSNumber numberWithInt: expire], @"expire",
Expand Down Expand Up @@ -323,10 +343,6 @@ - (WOResponse *) connectAction
[ud setLanguage: language];
[ud synchronize];
}

calendars = [loggedInUser calendarsFolderInContext: context];
if ([calendars respondsToSelector: @selector (reloadWebCalendars:)])
[calendars reloadWebCalendars: NO];
}
else
{
Expand Down Expand Up @@ -382,7 +398,6 @@ - (NSDictionary *) _casRedirectKeys
{
WOResponse *response;
NSString *login, *logoutRequest, *newLocation, *oldLocation, *ticket;
SOGoAppointmentFolders *calendars;
SOGoCASSession *casSession;
SOGoUser *loggedInUser;
SOGoWebAuthenticator *auth;
Expand Down Expand Up @@ -450,9 +465,7 @@ login callback (ticket != nil). */
}

loggedInUser = [SOGoUser userWithLogin: login];
calendars = [loggedInUser calendarsFolderInContext: context];
if ([calendars respondsToSelector: @selector (reloadWebCalendars:)])
[calendars reloadWebCalendars: NO];
[self _checkAutoReloadWebCalendars: loggedInUser];
}
else
{
Expand All @@ -476,6 +489,7 @@ login callback (ticket != nil). */
{
WOResponse *response;
NSString *login, *newLocation, *oldLocation;
SOGoUser *loggedInUser;
WOCookie *saml2LocationCookie;
WORequest *rq;

Expand All @@ -500,6 +514,9 @@ login callback (ticket != nil). */
newLocation = [NSString stringWithFormat: @"%@%@",
oldLocation, [login stringByEscapingURL]];
}

loggedInUser = [SOGoUser userWithLogin: login];
[self _checkAutoReloadWebCalendars: loggedInUser];
}
else
{
Expand Down
8 changes: 8 additions & 0 deletions UI/PreferencesUI/UIxPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,14 @@ - (NSString *) forwardEnabled

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] synchronize];
}
Expand Down
27 changes: 25 additions & 2 deletions UI/WebServerResources/js/Preferences/Preferences.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,30 @@
data = {};
}

// We convert our PreventInvitationsWhitelist hash into a array of user
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) {
data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) {
var match = /^(.+)\s<(\S+)>$/.exec(value),
Expand All @@ -204,10 +226,11 @@
* @desc The factory we'll use to register with Angular
* @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, {
$window: $window,
$document: $document,
$rootScope: $rootScope,
$q: $q,
$timeout: $timeout,
$log: $log,
Expand Down

1 comment on commit f017c42

@wixaw
Copy link

@wixaw wixaw commented on f017c42 Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @cgx
I tested and It's work, thanks !

Please sign in to comment.