diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 6a2040720..986978878 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -413,24 +413,22 @@ forEvent: (iCalEvent *) theEvent { iCalPerson *currentAttendee; - NSMutableArray *unavailableAttendees, *whiteList; - NSEnumerator *enumerator; - NSPredicate *predicate; - NSString *currentUID, *ownerUID; - NSMutableString *reason; - NSDictionary *values; - NSMutableDictionary *value, *moduleSettings; SOGoUser *user; SOGoUserSettings *us; + NSMutableArray *unavailableAttendees; + NSEnumerator *enumerator; + NSString *currentUID, *ownerUID, *whiteListString; + NSMutableString *reason; + NSDictionary *values; + NSMutableDictionary *value, *moduleSettings, *whiteList; int i, count; - i = count = 0; - + // Build list of the attendees uids without ressources unavailableAttendees = [[NSMutableArray alloc] init]; enumerator = [theAttendees objectEnumerator]; ownerUID = [[[self context] activeUser] login]; - + while ((currentAttendee = [enumerator nextObject])) { currentUID = [currentAttendee uid]; @@ -443,11 +441,10 @@ if (![user isResource] && [[moduleSettings objectForKey:@"PreventInvitations"] boolValue]) { // Check if the user have a whiteList - whiteList = [NSMutableArray arrayWithObject:[moduleSettings objectForKey:@"PreventInvitationsWhitelist"]]; - predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", ownerUID]; - [whiteList filterUsingPredicate:predicate]; + whiteListString = [moduleSettings objectForKey:@"PreventInvitationsWhitelist"]; + whiteList = [whiteListString objectFromJSONString]; // If the filter have a hit, do not add the currentUID to the unavailableAttendees array - if ([whiteList count] == 0) + if (![whiteList objectForKey:ownerUID]) { values = [NSDictionary dictionaryWithObject:[user cn] forKey:@"Cn"]; [unavailableAttendees addObject:values]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index ffd641912..a58dbd8a9 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -652,13 +652,14 @@ static NSArray *reminderValues = nil; return whiteList; } -- (void) setWhiteList: (NSArray *) whiteList +- (void) setWhiteList: (NSString *) whiteListString { SOGoUserSettings *us; NSMutableDictionary *moduleSettings; + us = [user userSettings]; moduleSettings = [us objectForKey: @"Calendar"]; - [moduleSettings setObject: whiteList forKey: @"PreventInvitationsWhitelist"]; + [moduleSettings setObject: whiteListString forKey: @"PreventInvitationsWhitelist"]; [us synchronize]; } diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index 9f1823563..a6f117b98 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -235,47 +235,54 @@ function initPreferences() { // Calendar whiteList var whiteList = $("appointmentsWhiteListWrapper"); - if(whiteList) { - var whiteListValue = $("whiteList").getValue(); - if (whiteListValue != "") { - whiteListValue = whiteListValue.split(","); - var tablebody = $("appointmentsWhiteListWrapper").childNodesWithTag("table")[0].tBodies[0]; - for (i = 0; i < whiteListValue.length; i++) - { - var elements = whiteListValue[i].split("="); - var row = new Element("tr"); - var td = new Element("td").update(""); - var textField = new Element("input"); - var span = new Element("span"); - - row.addClassName("whiteListRow"); - row.observe("mousedown", onRowClick); - td.addClassName ("whiteListCell"); - td.observe("mousedown", endAllEditables); - td.observe("dblclick", onNameEdit); - textField.addInterface(SOGoAutoCompletionInterface); - textField.SOGoUsersSearch = true; - textField.observe("autocompletion:changed", endEditable); - textField.addClassName("textField"); - textField.value = elements[1]; - textField.setAttribute("uid", elements[0]); - textField.hide(); - span.innerText = elements[1]; - - td.appendChild(textField); - td.appendChild(span); - row.appendChild (td); - tablebody.appendChild(row); - $(tablebody).deselectAll(); - - } + if (whiteList) { + var whiteListString = $("whiteList").getValue(); + // This condition is a backward compatibility where the strings looks like : "sogo1=John DOE " + if (whiteListString.search("=") != -1) { + var split = whiteListString.split("="); + var whiteListObject = {}; + whiteListObject[split[0]] = split[1]; + + } + else if (whiteListString != "") { + var whiteListObject = JSON.parse(whiteListString); + } + var allKeys = Object.keys(whiteListObject); + var allValues = Object.values(whiteListObject); + var tablebody = $("appointmentsWhiteListWrapper").childNodesWithTag("table")[0].tBodies[0]; + for (i = 0; i < allKeys.length; i++) { + var row = new Element("tr"); + var td = new Element("td").update(""); + var textField = new Element("input"); + var span = new Element("span"); + + row.addClassName("whiteListRow"); + row.observe("mousedown", onRowClick); + td.addClassName ("whiteListCell"); + td.observe("mousedown", endAllEditables); + td.observe("dblclick", onNameEdit); + textField.addInterface(SOGoAutoCompletionInterface); + textField.SOGoUsersSearch = true; + textField.observe("autocompletion:changed", endEditable); + textField.addClassName("textField"); + textField.value = allValues[i]; + textField.setAttribute("uid", allKeys[i]); + textField.hide(); + span.innerText = allValues[i]; + + td.appendChild(textField); + td.appendChild(span); + row.appendChild (td); + tablebody.appendChild(row); + $(tablebody).deselectAll(); + } - - var table = whiteList.childNodesWithTag("table")[0]; - table.multiselect = true; - $("appointmentsWhiteListAdd").observe("click", onAppointmentsWhiteListAdd); - $("appointmentsWhiteListDelete").observe("click", onAppointmentsWhiteListDelete); } + + var table = whiteList.childNodesWithTag("table")[0]; + table.multiselect = true; + $("appointmentsWhiteListAdd").observe("click", onAppointmentsWhiteListAdd); + $("appointmentsWhiteListDelete").observe("click", onAppointmentsWhiteListDelete); // Calender categories var wrapper = $("calendarCategoriesListWrapper"); @@ -1131,16 +1138,15 @@ function onAppointmentsWhiteListDelete(e) { function serializeAppointmentsWhiteList() { var r = $$("#appointmentsWhiteListWrapper TBODY TR"); - var values = []; + var users = {}; for (var i = 0; i < r.length; i++) { var tds = r[i].childElements().first().down("INPUT"); var uid = tds.getAttribute("uid"); var value = tds.getValue(); - var user = uid + "=" + value; if (uid != null) - values.push(user); + users[uid] = value; } - $("whiteList").value = values; + $("whiteList").value = Object.toJSON(users); } function onCalendarCategoryAdd(e) {