From 60fad625cab700a613a3e336a7a5103d16a6cd7d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 25 Feb 2008 21:59:25 +0000 Subject: [PATCH] Monotone-Parent: 827d1bc635d1b6af9324b168e8af26b80c4648e0 Monotone-Revision: 40a7f11491111f2eb805d4198decee8951ba0cf6 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-02-25T21:59:25 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 ++++ SoObjects/SOGo/SOGoGCSFolder.m | 74 ++++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a67f429b..7742fdb82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-02-25 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoGCSFolder.m ([SOGoGCSFolder + -davSubscribe:queryContext]): implemented subscribing users other + that the current one, if the user doing the operation is a superuser. + ([SOGoGCSFolder -davUnsubscribe:queryContext]): same as above for + unsubscription. + 2008-02-22 Wolfgang Sourdeau * SoObjects/SOGo/SOGoUserFolder.m ([SOGoUserFolder diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index 3ff9e041d..38a0c90d9 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -41,6 +41,7 @@ #import #import #import +#import #import #import #import @@ -408,25 +409,22 @@ static BOOL sendFolderAdvisories = NO; #warning this code should be cleaned up #warning this code is a dup of UIxFolderActions,\ - we should remove the methods there instead -- (WOResponse *) _subscribe: (BOOL) reallyDo - inContext: (WOContext *) localContext + we should remove the methods there +- (void) _subscribeUser: (SOGoUser *) subscribingUser + reallyDo: (BOOL) reallyDo + inResponse: (WOResponse *) response { - WOResponse *response; NSMutableArray *folderSubscription; NSString *subscriptionPointer, *baseFolder, *folder; - SOGoUser *activeUser; NSUserDefaults *ud; NSArray *realFolderPath; NSMutableDictionary *moduleSettings; - activeUser = [localContext activeUser]; - ud = [activeUser userSettings]; + ud = [subscribingUser userSettings]; baseFolder = [container nameInContainer]; moduleSettings = [ud objectForKey: baseFolder]; - response = [localContext response]; - if ([owner isEqualToString: [activeUser login]]) + if ([owner isEqualToString: [subscribingUser login]]) { [response setStatus: 403]; [response appendContentString: @@ -461,18 +459,68 @@ static BOOL sendFolderAdvisories = NO; [response setStatus: 204]; } +} + +- (WOResponse *) _subscribe: (BOOL) reallyDo + inTheNameOf: (NSString *) delegatedUser + inContext: (WOContext *) localContext +{ + WOResponse *response; + SOGoUser *currentUser, *subscriptionUser; + BOOL validRequest; + + response = [localContext response]; + currentUser = [localContext activeUser]; + + if ([delegatedUser length]) + { + validRequest = ([currentUser isSuperUser]); + subscriptionUser = [SOGoUser userWithLogin: delegatedUser roles: nil]; + } + else + { + validRequest = YES; + subscriptionUser = currentUser; + } + + if (validRequest) + [self _subscribeUser: subscriptionUser + reallyDo: reallyDo + inResponse: response]; + else + { + [response setStatus: 403]; + [response appendContentString: + @"You cannot subscribe another user to any folder" + @" unless you are a super-user."]; + } return response; } -- (id ) davSubscribe: (WOContext *) localContext +- (NSString *) _parseDAVDelegatedUser: (WOContext *) queryContext { - return [self _subscribe: YES inContext: localContext]; + id document; + id attrs; + + document = [[queryContext request] contentAsDOMDocument]; + attrs = [[document documentElement] attributes]; + + return [[attrs namedItem: @"user"] nodeValue]; } -- (id ) davUnsubscribe: (WOContext *) localContext +- (id ) davSubscribe: (WOContext *) queryContext { - return [self _subscribe: NO inContext: localContext]; + return [self _subscribe: YES + inTheNameOf: [self _parseDAVDelegatedUser: queryContext] + inContext: queryContext]; +} + +- (id ) davUnsubscribe: (WOContext *) queryContext +{ + return [self _subscribe: NO + inTheNameOf: [self _parseDAVDelegatedUser: queryContext] + inContext: queryContext]; } - (NSException *) davSetProperties: (NSDictionary *) setProps