From e995f14954a485dc1b4e6c80053758f46a3479e0 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 14 Dec 2006 21:17:15 +0000 Subject: [PATCH] Monotone-Parent: ac12726c5c25cab930eea76522ab73de7756eedb Monotone-Revision: 2d162935dc98ba2b7bd8d3a9177213df5f71785c Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-12-14T21:17:15 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 7 +- SoObjects/SOGo/SOGoAclsFolder.h | 44 ++++++++ SoObjects/SOGo/SOGoAclsFolder.m | 182 ++++++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 SoObjects/SOGo/SOGoAclsFolder.h create mode 100644 SoObjects/SOGo/SOGoAclsFolder.m diff --git a/ChangeLog b/ChangeLog index e7675024c..df49e730e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-12-14 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoAclsFolder.[hm]: new class module that + handles the storage for the acls. + * SoObjects/Appointments/SOGoCalendarComponent.[hm]: new parent class for SOGoAppointmentObject and SOGoTaskObject. @@ -7,8 +10,8 @@ general editor for folder acls. * SoObjects/SOGo/NSString+Utilities.[hm]: old "NSString+URL" - renamed. - ([NSString -davMethodToObjC]): method that returns the method name + renamed. + ([NSString -davMethodToObjC]): method that returns the method name for a DAV property implementation. * SoObjects/SOGo/NSArray+Utilities.m: new extension module to diff --git a/SoObjects/SOGo/SOGoAclsFolder.h b/SoObjects/SOGo/SOGoAclsFolder.h new file mode 100644 index 000000000..f290ba436 --- /dev/null +++ b/SoObjects/SOGo/SOGoAclsFolder.h @@ -0,0 +1,44 @@ +/* SOGoAclsFolder.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 SOGOACLSFOLDER_H +#define SOGOACLSFOLDER_H + +#import "SOGoFolder.h" + +@interface SOGoAclsFolder : SOGoFolder +{ +// SOGoObject *clientObject; +} + ++ (id) aclsFolder; + +- (NSArray *) aclsForObject: (SOGoObject *) object; +- (NSArray *) aclsForObject: (SOGoObject *) object + forUser: (NSString *) uid; +- (void) setRoleForObject: (SOGoObject *) object + forUsers: (NSArray *) uids + to: (NSString *) role; + +@end + +#endif /* SOGOACLSOBJECT_H */ diff --git a/SoObjects/SOGo/SOGoAclsFolder.m b/SoObjects/SOGo/SOGoAclsFolder.m new file mode 100644 index 000000000..3b0e6a932 --- /dev/null +++ b/SoObjects/SOGo/SOGoAclsFolder.m @@ -0,0 +1,182 @@ +/* SOGoAclsFolder.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 "SOGoAclsFolder.h" + +static NSArray *fields = nil; + +@implementation SOGoAclsFolder + ++ (void) initialize +{ + if (!fields) + { + fields = [NSArray arrayWithObjects: @"uid", @"object", @"role", nil]; + [fields retain]; + } +} + ++ (id) aclsFolder +{ + id aclsFolder; + + aclsFolder = [self new]; + [aclsFolder autorelease]; + + return aclsFolder; +} + +- (NSString *) _ocsPathForObject: (SOGoObject *) object +{ + NSString *pathForObject; + id currentObject; + + pathForObject = nil; + currentObject = object; + while (currentObject && !pathForObject) + if ([currentObject isKindOfClass: [SOGoFolder class]]) + pathForObject = [NSString stringWithFormat: @"%@/acls", + [(SOGoFolder *) currentObject ocsPath]]; + else + currentObject = [currentObject container]; + + return pathForObject; +} + +- (NSArray *) aclsForObject: (SOGoObject *) object +{ + EOQualifier *qualifier; + NSString *objectPath; + + [self setOCSPath: [self _ocsPathForObject: object]]; + + objectPath + = [NSString stringWithFormat: @"/%@", + [[object pathArrayToSoObject] componentsJoinedByString: @"/"]]; + qualifier + = [EOQualifier qualifierWithQualifierFormat: @"object = %@", objectPath]; + + return [[self ocsFolder] fetchFields: fields matchingQualifier: qualifier]; +} + +- (NSArray *) aclsForObject: (SOGoObject *) object + forUser: (NSString *) uid +{ + EOQualifier *qualifier; + NSString *objectPath; + NSArray *records; + + [self setOCSPath: [self _ocsPathForObject: object]]; + + objectPath + = [NSString stringWithFormat: @"/%@", + [[object pathArrayToSoObject] componentsJoinedByString: @"/"]]; + qualifier = [EOQualifier + qualifierWithQualifierFormat: @"(object = %@) AND (uid = %@)", + objectPath, uid]; + + records = [[self ocsFolder] fetchFields: fields matchingQualifier: qualifier]; + + return [records valueForKey: @"role"]; +} + +- (void) removeUsersWithRole: (NSString *) role + forObjectAtPath: (NSString *) objectPath + inFolder: (GCSFolder *) folder +{ + NSString *deleteSQL; + EOAdaptorChannel *channel; + + channel = [folder acquireQuickChannel]; + + deleteSQL = [NSString stringWithFormat: @"DELETE FROM %@" + @" WHERE object = '%@'" + @" AND role = '%@'", + [folder quickTableName], objectPath, role]; + [channel evaluateExpressionX: deleteSQL]; +} + +- (void) setRoleForObjectAtPath: (NSString *) objectPath + forUser: (NSString *) uid + to: (NSString *) role + inFolder: (GCSFolder *) folder +{ + NSString *SQL; + EOAdaptorChannel *channel; + + channel = [folder acquireQuickChannel]; + + SQL = [NSString stringWithFormat: @"DELETE FROM %@" + @" WHERE object = '%@'" + @" AND uid = '%@'", + [folder quickTableName], objectPath, uid]; + [channel evaluateExpressionX: SQL]; + SQL = [NSString stringWithFormat: @"INSERT INTO %@" + @" (object, uid, role)" + @" VALUES ('%@', '%@', '%@')", [folder quickTableName], + objectPath, uid, role]; + [channel evaluateExpressionX: SQL]; +} + +/* FIXME: part of this code should be moved to sope-gdl/GCSFolder.m */ +- (void) setRoleForObject: (SOGoObject *) object + forUsers: (NSArray *) uids + to: (NSString *) role +{ + GCSFolder *aclsFolder; + NSString *objectPath, *currentUID; + NSEnumerator *userUIDs; + + [self setOCSPath: [self _ocsPathForObject: object]]; + aclsFolder = [self ocsFolder]; + + objectPath + = [NSString stringWithFormat: @"/%@", + [[object pathArrayToSoObject] componentsJoinedByString: @"/"]]; + [self removeUsersWithRole: role + forObjectAtPath: objectPath + inFolder: aclsFolder]; + + userUIDs = [uids objectEnumerator]; + currentUID = [userUIDs nextObject]; + while (currentUID) + { + if ([currentUID length] > 0) + [self setRoleForObjectAtPath: objectPath + forUser: currentUID + to: role + inFolder: aclsFolder]; + currentUID = [userUIDs nextObject]; + } +} + +@end