From f0b8eb8dfb6d19fdc82fe92a796c9e2b9a9c2aa3 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Mon, 7 Jul 2014 13:38:37 -0400 Subject: [PATCH] server side code to integrate the whitelist --- .../English.lproj/Localizable.strings | 1 + .../Appointments/SOGoAppointmentObject.m | 51 +++++++++++-------- UI/PreferencesUI/UIxPreferences.m | 4 +- UI/WebServerResources/UIxPreferences.js | 43 ++++++++++++++-- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/SoObjects/Appointments/English.lproj/Localizable.strings b/SoObjects/Appointments/English.lproj/Localizable.strings index ba3b942f1..3fbab4be3 100644 --- a/SoObjects/Appointments/English.lproj/Localizable.strings +++ b/SoObjects/Appointments/English.lproj/Localizable.strings @@ -1,3 +1,4 @@ +"This or these persons cannot be invited:" = "This or these persons cannot be invited:"; "Personal Calendar" = "Personal Calendar"; vevent_class0 = "(Public event)"; vevent_class1 = "(Private event)"; diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 16732e7c4..623bd1de6 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -25,6 +25,7 @@ #import #import #import +#import #import #import @@ -52,6 +53,7 @@ #import #import #import +#import #import #import #import @@ -424,51 +426,56 @@ NSDictionary *values; NSMutableDictionary *value; SOGoUser *user, *currentUser, *ownerUser; + SOGoUserSettings *us; NSException *e; int count = 0, i = 0; + NSMutableArray *whiteList; + NSPredicate *predicate; - // Build a list of the attendees uids without the ressources + // Build list of the attendees uids without ressources attendees = [NSMutableArray arrayWithCapacity: [theAttendees count]]; unavailableAttendees = [[NSMutableArray alloc] init]; enumerator = [theAttendees objectEnumerator]; + while ((currentAttendee = [enumerator nextObject])) { currentUID = [currentAttendee uid]; if (currentUID) { user = [SOGoUser userWithLogin: currentUID]; + us = [user userSettings]; if (![user isResource]) { - // Check if the user can be invited to an event. - if ([[user userSettings] objectForKey:@"PreventInvitations"]) + // Check if the user prevented his account from beeing invited to events + if ([[us objectForKey:@"PreventInvitations"] boolValue]) { - values = [NSDictionary dictionaryWithObject:[user cn] forKey:@"Cn"]; - [unavailableAttendees addObject:values]; + // Check if the user have a whiteList + whiteList = [NSMutableArray arrayWithObject:[us objectForKey:@"whiteListInvitations"]]; + predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", @"sogo1"]; + [whiteList filterUsingPredicate:predicate]; + + // If the filter have a hit, do not add the currentUID to the unavailableAttendees array + if ([whiteList count] == 0) + { + values = [NSDictionary dictionaryWithObject:[user cn] forKey:@"Cn"]; + [unavailableAttendees addObject:values]; + } } } } } + count = [unavailableAttendees count]; - if (count > 0) + if ([unavailableAttendees count] > 0) { - if (count > 1) + reason = [NSMutableString stringWithString:[self labelForKey: @"This or these persons cannot be invited:"]]; + // Add all the unavailable users in the warning message + for (i = 0; i < count; i++) { - reason = [NSMutableString stringWithString:[self labelForKey: @"These persons cannot be invited :"]]; - for (i = 0; i < count; i++) - { - value = [unavailableAttendees objectAtIndex:i]; - [reason appendString:[value keysWithFormat: @"\n %{Cn}"]]; - if (!(i == (count - 1))) - { - [reason appendString:@" &"]; - } - } - } - else - { - value = [unavailableAttendees objectAtIndex:0]; - reason = [self labelForKey: @"This person cannot be invited:"]; + value = [unavailableAttendees objectAtIndex:i]; [reason appendString:[value keysWithFormat: @"\n %{Cn}"]]; + if (!(i == (count - 1))) + [reason appendString:@" &"]; } [unavailableAttendees release]; return [NSException exceptionWithHTTPStatus:403 reason: reason]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 96e91f0e6..86416ed11 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -639,10 +639,10 @@ static NSArray *reminderValues = nil; return [userDefaults busyOffHours]; } -- (NSString *) whiteListValue +- (NSArray *) whiteListValue { SOGoUserSettings *us; - id *whiteListValue; + NSArray *whiteListValue; us = [user userSettings]; whiteListValue = [us objectForKey:@"whiteListInvitations"]; diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index 8086879f3..17685a533 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -229,10 +229,42 @@ function initPreferences() { // Calendar whiteList var whiteList = $("appointmentsWhiteListWrapper"); if(whiteList) { + var whiteListValue = $("whiteListValue").getValue().split(","); + if (whiteListValue.length != 0) + { + 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(); + + } + } + var table = whiteList.childNodesWithTag("table")[0]; - var r = $$("#appointmentsWhiteListWrapper tbody tr"); - for (var i= 0; i < r.length; i++) - r[i].identify(); table.multiselect = true; $("appointmentsWhiteListAdd").observe("click", onAppointmentsWhiteListAdd); $("appointmentsWhiteListDelete").observe("click", onAppointmentsWhiteListDelete); @@ -1076,6 +1108,7 @@ function onAppointmentsWhiteListAdd(e) { row.selectElement(); makeEditable(td); + } function onAppointmentsWhiteListDelete(e) { @@ -1096,7 +1129,9 @@ function serializeAppointmentsWhiteList() { for (var i = 0; i < r.length; i++) { var tds = r[i].childElements().first().down("INPUT"); var uid = tds.getAttribute("uid"); - values.push(uid); + var value = tds.getValue(); + var user = uid + "=" + value; + values.push(user); } $("whiteListValue").value = values;