diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 55cbb30e1..fdf30249c 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -35,8 +35,6 @@ #import #import -#import - #import #import #import @@ -49,6 +47,7 @@ #import #import #import +#import #import #if defined(MFA_CONFIG) @@ -173,6 +172,26 @@ 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; WOCookie *authCookie, *xsrfCookie; SOGoWebAuthenticator *auth; - SOGoAppointmentFolders *calendars; SOGoUserDefaults *ud; SOGoUser *loggedInUser; NSDictionary *params; @@ -294,6 +312,8 @@ } #endif + [self _checkAutoReloadWebCalendars: loggedInUser]; + json = [NSDictionary dictionaryWithObjectsAndKeys: [loggedInUser cn], @"cn", [NSNumber numberWithInt: expire], @"expire", @@ -323,10 +343,6 @@ [ud setLanguage: language]; [ud synchronize]; } - - calendars = [loggedInUser calendarsFolderInContext: context]; - if ([calendars respondsToSelector: @selector (reloadWebCalendars:)]) - [calendars reloadWebCalendars: NO]; } else { @@ -382,7 +398,6 @@ { WOResponse *response; NSString *login, *logoutRequest, *newLocation, *oldLocation, *ticket; - SOGoAppointmentFolders *calendars; SOGoCASSession *casSession; SOGoUser *loggedInUser; SOGoWebAuthenticator *auth; @@ -450,9 +465,7 @@ } loggedInUser = [SOGoUser userWithLogin: login]; - calendars = [loggedInUser calendarsFolderInContext: context]; - if ([calendars respondsToSelector: @selector (reloadWebCalendars:)]) - [calendars reloadWebCalendars: NO]; + [self _checkAutoReloadWebCalendars: loggedInUser]; } else { @@ -476,6 +489,7 @@ { WOResponse *response; NSString *login, *newLocation, *oldLocation; + SOGoUser *loggedInUser; WOCookie *saml2LocationCookie; WORequest *rq; @@ -500,6 +514,9 @@ newLocation = [NSString stringWithFormat: @"%@%@", oldLocation, [login stringByEscapingURL]]; } + + loggedInUser = [SOGoUser userWithLogin: login]; + [self _checkAutoReloadWebCalendars: loggedInUser]; } else { diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 15434b73c..4cabf9fff 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1567,6 +1567,14 @@ static NSArray *reminderValues = nil; 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]; } diff --git a/UI/WebServerResources/js/Preferences/Preferences.service.js b/UI/WebServerResources/js/Preferences/Preferences.service.js index e0f9f8162..68c4fe2ab 100644 --- a/UI/WebServerResources/js/Preferences/Preferences.service.js +++ b/UI/WebServerResources/js/Preferences/Preferences.service.js @@ -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), @@ -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,