From 8fab0af88d6b693b7c477e22da141d9f5ec9b0cc Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 14 Dec 2006 20:20:40 +0000 Subject: [PATCH] Monotone-Parent: 719e48a98f49b93c9135226ca220043964d2cfdd Monotone-Revision: f261c808456800f2a75a751af5871d3dc8fdd693 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-12-14T20:20:40 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 + UI/Common/UIxAclEditor.h | 42 +++++++ UI/Common/UIxAclEditor.m | 158 ++++++++++++++++++++++++++ UI/Templates/UIxAclEditor.wox | 29 +++++ UI/WebServerResources/UIxAclEditor.js | 75 ++++++++++++ 5 files changed, 307 insertions(+) create mode 100644 UI/Common/UIxAclEditor.h create mode 100644 UI/Common/UIxAclEditor.m create mode 100644 UI/Templates/UIxAclEditor.wox create mode 100644 UI/WebServerResources/UIxAclEditor.js diff --git a/ChangeLog b/ChangeLog index 663eb1de1..6188a323c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-12-14 Wolfgang Sourdeau + * UI/Common/UIxAclEditor.[hm]: new component that provides a + general editor for folder acls. + * SoObjects/SOGo/NSString+Utilities.[hm]: old "NSString+URL" renamed. ([NSString -davMethodToObjC]): method that returns the method name diff --git a/UI/Common/UIxAclEditor.h b/UI/Common/UIxAclEditor.h new file mode 100644 index 000000000..f19b5d8cf --- /dev/null +++ b/UI/Common/UIxAclEditor.h @@ -0,0 +1,42 @@ +/* UIxAclEditor.h - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef UIXACLEDITOR_H +#define UIXACLEDITOR_H + +#import + +@interface UIxAclEditor : UIxComponent +{ + BOOL prepared; + NSArray *acls; + NSMutableArray *users; + NSMutableArray *checkedUsers; + NSString *ownerCN; +} + +- (NSArray *) aclsForFolder; +- (NSString *) ownerCN; + +@end + +#endif /* UIXACLEDITOR_H */ diff --git a/UI/Common/UIxAclEditor.m b/UI/Common/UIxAclEditor.m new file mode 100644 index 000000000..9173a25ab --- /dev/null +++ b/UI/Common/UIxAclEditor.m @@ -0,0 +1,158 @@ +/* UIxAclEditor.m - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import +#import +#import +#import +#import +#import +#import + +#import "UIxAclEditor.h" + +@implementation UIxAclEditor + +- (id) init +{ + if ((self = [super init])) + { + acls = nil; + prepared = NO; + users = [NSMutableArray new]; + checkedUsers = [NSMutableArray new]; + ownerCN = nil; + } + + return self; +} + +- (void) dealloc +{ + [users release]; + [checkedUsers release]; + if (ownerCN) + [ownerCN release]; + [super dealloc]; +} + +- (NSArray *) aclsForFolder +{ + SOGoAclsFolder *folder; + + if (!acls) + { + folder = [SOGoAclsFolder aclsFolder]; + acls = [folder aclsForObject: [self clientObject]]; + } + + return acls; +} + +- (NSString *) ownerCN +{ + if (!ownerCN) + { + ownerCN = [[self clientObject] ownerInContext: context]; + [ownerCN retain]; + } + + return ownerCN; +} + +- (void) _prepareUsers +{ + NSEnumerator *aclsEnum; + AgenorUserManager *um; + NSDictionary *currentAcl; + iCalPerson *currentUser; + NSString *currentUID; + + aclsEnum = [[self aclsForFolder] objectEnumerator]; + um = [AgenorUserManager sharedUserManager]; + currentAcl = [aclsEnum nextObject]; + while (currentAcl) + { + currentUID = [currentAcl objectForKey: @"uid"]; + if (![currentUID isEqualToString: @"freebusy"]) + { + currentUser = [um iCalPersonWithUid: currentUID]; + if (![[currentUser cn] isEqualToString: [self ownerCN]]) + { + if ([[currentAcl objectForKey: @"role"] + isEqualToString: SOGoRole_Delegate]) + [checkedUsers addObject: currentUser]; + [users addObject: currentUser]; + } + } + currentAcl = [aclsEnum nextObject]; + + prepared = YES; + } +} + +- (NSArray *) usersForFolder +{ + if (!prepared) + [self _prepareUsers]; + + return users; +} + +- (NSArray *) checkedUsers +{ + if (!prepared) + [self _prepareUsers]; + + return checkedUsers; +} + +- (NSString *) toolbar +{ + return (([[self ownerCN] isEqualToString: [[context activeUser] login]]) + ? @"SOGoAclOwner.toolbar" : @"SOGoAclAssistant.toolbar"); +} + +- (id) saveAclsAction +{ + NSString *uids; + WORequest *request; + SOGoAclsFolder *folder; + SOGoObject *clientObject; + + folder = [SOGoAclsFolder aclsFolder]; + request = [context request]; + clientObject = [self clientObject]; + uids = [request formValueForKey: @"delegates"]; + [folder setRoleForObject: clientObject + forUsers: [uids componentsSeparatedByString: @","] + to: SOGoRole_Delegate]; + uids = [request formValueForKey: @"assistants"]; + [folder setRoleForObject: clientObject + forUsers: [uids componentsSeparatedByString: @","] + to: SOGoRole_Assistant]; + + return [self jsCloseWithRefreshMethod: nil]; +} + +@end diff --git a/UI/Templates/UIxAclEditor.wox b/UI/Templates/UIxAclEditor.wox new file mode 100644 index 000000000..246e0be84 --- /dev/null +++ b/UI/Templates/UIxAclEditor.wox @@ -0,0 +1,29 @@ + + + +
+
+ + + +
+ + +
+
+
diff --git a/UI/WebServerResources/UIxAclEditor.js b/UI/WebServerResources/UIxAclEditor.js new file mode 100644 index 000000000..0c7c2a098 --- /dev/null +++ b/UI/WebServerResources/UIxAclEditor.js @@ -0,0 +1,75 @@ +/* test */ + +var contactSelectorAction = 'acls-contacts'; + +function addContact(tag, fullContactName, contactId, contactName, + contactEmail) { + if (tag == "assistant") + addUser(contactName, contactId, false); + else if (tag == "delegate") + addUser(contactName, contactId, true); +} + +function addUser(userName, userId, checked) { + var uidList = $("uixselector-userRoles-uidList"); + var uids; + + if (uidList.value.length > 0) { + uids = uidList.value.split(","); + } else { + uids = new Array(); + } + + if (uids.indexOf(userId) < 0) { + uids.push(userId); + var ul = $("uixselector-userRoles-display"); + ul.appendChild(nodeForUser(userName, userId, checked)); + uidList.value = uids.join(","); + } + + log("addUser: " + uidList.value); +} + +function nodeForUser(userName, userId, checked) { + var node = document.createElement("li"); + node.setAttribute("uid", userId); + node.setAttribute("class", ""); + node.addEventListener("mousedown", listRowMouseDownHandler, true); + node.addEventListener("click", onRowClick, true); + + var checkbox = document.createElement("input"); + checkbox.setAttribute("type", "checkbox"); + checkbox.setAttribute("class", "checkBox"); + checkbox.checked = checked; + checkbox.addEventListener("change", updateAclStatus, true); + + node.appendChild(checkbox); + node.appendChild(document.createTextNode(userName)); + + return node; +} + +function updateAclStatus() { +} + +function saveAcls() { + var form = $("aclForm"); + var lis = $("uixselector-userRoles-display").childNodesWithTag("li"); + + var assistants = new Array(); + var delegates = new Array(); + for (var i = 0; i < lis.length; i++) { + var uName = lis[i].getAttribute("uid"); + var cb = lis[i].childNodesWithTag("input")[0]; + if (cb.checked) + delegates.push(uName); + else + assistants.push(uName); + } + $("assistants").value = assistants.join(","); + $("delegates").value = delegates.join(","); + + form.submit(); + + return false; +}